- If you on Windows install Bonjour service from Apple. On Mac skip this step.
- If you don't have them installed yet, install JDK 8 and Maven
- If you are using Windows Install Putty. On Mac please use any other SSH client.
- Flash this image to 8GB micro SD card and insert it into Raspberry Pi Zero W (to make it shorter RPi)
- Connect RPi to your computer, open Putty and create a new session
- Host name: rpi-1.local
- Password: sytac-1
- Port: 22
- Click "Open" to connect to the RPi
- To build the java project and upload it to RPi execute the command
mvn clean package
- To run the program on RPi in open Putty terminal execute the script
/home/pi/run_app.sh
- To close the program execute the command
ps -ef | grep java
to find the program process ID and than executekill <process id>
- When you finished programming and want the program to be ran on Linux startup add the program to
crontab
- Execute
crontab -e
- Add this to the end of the config:
@reboot /home/pi/run_app.sh >> /home/pi/slab.log &
- Execute
sudo reboot now
to reboot your RPi
- Execute
The project is making use of Pi4J library to access GPIO pins on the RPi, and Ubidots cloud IoT frontend to remotely operate the GPIO pins. If you build the project and run the application on RPi, the application will:
- Try to obtain access token from Ubidots using an API key.
- Then, from Ubidots, it will try to get the value of the variable
wheel-engaged
for the deviceweel
- Then it will try to get the value of the variable
wheel-direction
for the deviceweel
- Then the values of the
wheel-engaged
andwheel-direction
variables is supplied to the method Motor.go(), which toggles GPIO pins on the RPi.
Please put your API key and the GPIO pins numbers you want to use into the application.properties
file.
- Create an account on
ubidots.com
. They offer 1 month trial without asking for your credit card, that's why Google IoT was not chosen for this workshop. - Create a device with the name
wheel
- Inside of the device
wheel
create 2 variables:wheel-direction
andwheel-engaged
- Create a dashboard
- On the dashboard create 2 controls with the type
Switch
and assign previously created variables on them. You should see 2 buttons. If you click on the button it should change the last value of the assigned for it variable.
Take your API key from Ubidots and put it into the application.properties
file instead of the existing one.
Build the project and run the application on RPi, the output of the program should give you something like this:
Motor engaged: true; Direction: 1
Motor engaged: true; Direction: 1
Motor engaged: true; Direction: 1
This means the program is successfully fetching values of the wheel-direction
and wheel-engaged
variables from Ubidots.
Now if you will be pushing buttons you created on Ubidots you should see the output of the program reflects it.
- Never short out the +/- from the power supply
- Look at the pinout of the
Raspberry Pi Zero W
on the Pi4J project website to find the pins on the board - Look at the pinout of the L298N Dual H Bridge
- Connect ground pins of RPi and L298N together
- Connect RPi GPIO pins you've used to IN1 and IN2 (or IN3, IN4) on the L298N board
- Connect OUT1 and OUT2 (or OUT3 and OUT4) to the motor
- Connect negative contact of the power supply to the ground pin of the L298N board
- Connect positive contact of the power supply to the +12V pin of the L298N board
- To see the GPIO pins status execute
gpio readall
in the RPi console - To look up the GPIO pinout of RPi Zero W you can check Pi4G library website http://pi4j.com/pins/model-zerow-rev1.html
- To scan available WiFi networks execute
sudo iwlist wlan0 scan
- To set up WiFi setting via interactive interface
sudo raspi-config
- To set WiFi settings via config file edit /etc/wpa_supplicant/wpa_supplicant.conf
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf