Dashboard for RaspPi-controlled toy sailboat with Node-RED
Sail Away
With Node-RED, you can create a web dashboard that instructs a Raspberry Pi to set the rudder position on a toy sailboat.
My daughters and I have built a number of toy boat projects with an assortment of Arduino, ESP8266 (WiFi), Bluetooth, and radio frequency interference (RFI) components, but the version we created for this article using a Raspberry Pi and Node-RED [1] offers one of the simplest solutions. The sailboat uses a basic catamaran design with a Raspberry Pi mounting inside a waterproof container. With Node-RED dashboards, you can control the sailboat's rudder from a smartphone. The complete Node-RED logic comprises only six nodes.
Building the Sailboat
Of the many different building materials from which you could choose, K'Nex construction pieces [2] are lighter than either Lego or Meccano, and they allow you to create reasonably large structures with a minimum number of pieces. If you do not have access to K'Nex pieces, popsicle sticks and cardboard would offer a good low-cost solution.
To build the sailboat we used:
- K'Nex building pieces
- Four plastic bottles
- Small plastic container with a lid
- String
- Duct tape
- Garbage bag
- Low-torque servo
- Raspberry Pi Zero W or 3
- Small USB phone charger
The base of the sailboat was a rectangular structure with 16 water-facing K'Nex pieces that allowed plastic bottles to be duct-taped in place (Figure 1). A few K'Nex pieces created a compartment for the servo, and wire secured the servo in place. A rudder was built by screwing a small piece of wood into the servo arm (Figure 2). A garbage bag was cut to the required size and taped to the mast to form a sail. The boom had a swivel connection to the mast and guide ropes connected to both the boom and mast (Figure 3).
Servo and Rudder
Only very low torque servos can be connected directly to Raspberry Pi GPIO pins (Figure 4). An example of a low-torque servo would be the TowerPro SG90 [3] ($4), which has a torque of 25 oz/in (1.80 kg/cm). If you have servos with greater torque, you will need to use either a custom Raspberry Pi servo hat (there are some good ones on the market) or a separate power and ground circuit for the servo.
The WiringPi gpio
tool can be used to control the servo. This package is pre-installed on the Raspbian image, or it can be installed manually by entering:
sudo apt-get install -y wiringpi
Servos typically want a pulse frequency of 50Hz; however, the Raspberry Pi pulse width modulation (PWM) pins have a frequency of 19,200Hz, so some range definitions and scaling are required:
gpio -g mode 18 pwm #define pin 18 as the PWM pin gpio pwm-ms # use "mark space" mode gpio pwmc 192 # set freq as 19200 gpio pwmr 2000 # use a range of 2000
The gpio pwm
commands are not persistent after a reboot. A simple solution for this problem is to put the above commands in the Pi user login file $HOME/.bash_login
.
After running the PWM setup commands, you need to do some manual testing to define your various rudder (servo) positions (Figure 5), such as Hard Left, Hard Right, Easy Left, Easy Right, and Straight. The pwm
timing numbers will vary according to your requirements and the positioning of the servo arm. We used the commands
gpio -g pwm 18 200 #straight gpio -g pwm 18 260 #hard left gpio -g pwm 18 140 #hard right gpio -g pwm 18 230 #easy left gpio -g pwm 18 170 #easy right
for our sailboat.
Node-RED Logic and Dashboards
Node-RED is pre-installed on the Raspbian image, but it will need to be set to autostart on a Pi reboot with:
sudo systemctl enable nodered.service
The Node-RED web interface for configuration is accessed at http://localhost:1880 or http://<pi_ip_address>:1880. Selecting View | Dashboard brings up the options button on the far right (Figure 6), where you can define and change the web dashboard layout. To create logic, nodes are selected from the left node panel and dragged and dropped onto the center flow panel. Logic flow is then created by clicking and joining together the inputs and outputs on the nodes [4]. When a dashboard node is dropped onto the flow panel, it is added to the default web dashboard.
To call the gpio -g pwm
command, use the exec node (Figure 7). The button dashboard node will pass the defined payload value (e.g., a 260 is passed when the Hard Left button is pushed). The button's payload value is appended to the exec command to make a complete servo position command.
Once you have completed your logic setup, press the Deploy button on the top right to make your configuration live and ready to test.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.