Create amazing Pi apps without writing code
Web Dashboard Vehicle Control
The goal of the Web dashboard vehicle project is to create a small rover that can be controlled from a smartphone (Figure 10). For the Web dashboard vehicle project we used:
- 1 Car chassis for Arduino [4] ($15)
- 1 Pimoroni Explorer HAT Pro [5] ($23)
- 1 Portable micro-USB charger
- 1 USB WiFi adapter
- 4 Short alligator clips and connectors
- Duct tape
The Arduino car chassis may require a small amount of assembly. Rather than soldering connections we like to use short alligator clips. It is not recommended to wire DC motors directly to a Rasp Pi so the Pimoroni Explorer HAT Pro is used to connect the two DC motors.
The Rasp Pi and the portable micro-USB charger are secured to the top of the car chassis with duct tape. The left motor is wired to the motor 1 connectors on the Explorer Hat, and the right motor is wired to the motor 2 connectors. Note that it might take a little trial and error with the Explorer HAT "+" and "-" motor connections to get both wheels spinning in the same direction.
The Explorer HAT Node-RED library is installed by entering:
\curl -sS get.pimoroni.com/explorerhat | bash cd ~/.node-red npm install node-red-contrib-explorerhat
To control the Rasp Pi and the Node-RED logic from a smartphone, we installed a web dashboard library:
cd $HOME/.node-red npm install node-red-dashboard
The web dashboard presentation is configured from the dashboard tab in the right sidebar (Figure 11). For this example, we created two groups: a control group to drive the vehicle and a light group to turn on the Explorer Pro lights. Use the +group button to add a group, and the edit button to change an existing group.
To control a motor, an Explorer HAT Rasp Pi node and a dashboard button node are dropped in the flow window and connected together. All the configuration is done in the button node (Figure 12). The button configuration options include the Group in which the button appears (Controls [Home]), the Size of the button (3x1 = 50% of smartphone width by short height), the Payload (100, where -100 = reverse, 0=stop, 100 = forward), and the Topic (motor.one or motor.two for motor control).
The Explorer HAT has four colored LEDs. To toggle them, the Topic is light.<color>, where 1 is on and 0 is off (Figure 13).
For this project, Node-RED needs to autostart on boot; to do so, enter:
sudo systemctl enable nodered.service
The Node-RED dashboard user interface is accessed by entering <IPaddress>:1880/UI (e.g., 192.168.1.102:1880/ui). To find your Rasp Pi's IP address, open a terminal and enter:
$ ifconfig
The IP address will be in the wlan0 section. Figure 14 shows the final vehicle logic and the smartphone dashboard.
Multiple Actions with One Button
Many times you want to perform multiple actions with a single button click, such as having both motors start or stop or having one button turn all the LEDs on or off.
To create a circuit to start both motors, start by creating one button node to do one of the actions. For example, define the Topic for motor.one with a Payload of 100 (full speed forward). Next, add and wire a switch node between the button and Explorer HAT nodes (Figure 15). In the switch node configuration, change the Topic to motor.two (Figure 16).
To turn on all the Explorer Hat LEDs with the same technique, you would create a button node defined with a Topic of light.red and a payload of 1; then, you would add three switch nodes (with connections to your new button and the Explorer HAT node) and change the Topics to light.blue, light.green, and light.yellow.
« Previous 1 2 3 Next »
Buy this article as PDF
Pages: 6
(incl. VAT)