More example programs for the GrovePi in Java for Maven
Step 1 – Choose an example program
If you haven’t gotten through our “Setting up your computer and Raspberry Pi” tutorial, please do before proceeding. In this tutorial, we show you how to run any example program written in Java for Maven on your GrovePi!
Open Netbeans IDE from your laptop’s Desktop.
Open the “examples” project. On your laptop, navigate to “Desktop/GrovePi/Software/Java8” and open the “examples” project.
Now, let’s examine the example programs we can run. Inside Netbeans IDE, go to “examples/Source Packages/org.iot.raspberry.examples” and see all the java files containing our example programs.
By clicking on the java files, tabs open up and you start seeing the implementation of each example program side by side. Give them a good read and try to understand what each example program does. Files like “Runner.java” & “Monitor.java” are not example programs, but they’re the underlying software that makes everything to run.
Right-click “examples” project and click on “Properties”.
Click on the “Run” section. Inside “Arguments” text box, type the name of one the following example programs you want to run. Remember, your java file name should always reflect the public class defined within that file. Otherwise, you will get a compiler error. So basically, the parameter we’re sending is just the name of the class which has to be instantiated.
- AutomaticAC
- BlinkingLed
- ButtonLed
- ButtonListener
- LightSensor
- Relay
- RgbLcd
- RotarySensor3Led
- RotarySensorDimLed
- SoundSensor
- TemperatureAndHumidity
- UltrasonicRanger
Step 2 – Running the Examples
Since the project was already compiled/build in the “Running basic example program in Java with Maven” tutorial, we don’t need to do it twice. We just have to run it.
On your laptop, click the green play button on the Netbeans’s toolbar in order to run the program.
After you run the program, this is what the output log prints. The name of the example program/class appears in the underlined paragraph.
Errors – A short list of the most frequent errors encountered
When the Raspberry Pi can’t communicate with the GrovePi, the following exception shows up. This means that the GrovePi is not up to date or that the electrical connections between the Raspberry Pi and the GrovePi are prone to interferences or there are bad electrical contacts. This project doesn’t have any mechanism for retrying a command when one fails. For more support, please refer to our forum.
The following error shows up when the Raspberry Pi is not reachable. Check if the Raspberry Pi has the latest Raspbian For Robots and if it’s on the same network as your laptop.
Final Words
In this tutorial, we’ve briefed on all the example programs we can run and showed you the most frequent errors that can be encountered.
The next step for you is to experiment with the source code and add your own example programs.