Pi Sailboat

My daughters and I have built a number of boat projects with an assortment of Arduino, ESP-8266, Bluetooth and RFI components. I believe that this version using a Raspberry Pi and NodeRed offers one of the simplest solutions. This sailboat used a basic catamaran design with a Raspberry Pi mounting inside a waterproof container. Using NodeRed dashboards you can control the sailboat’s rudder from a smart phone. The complete NodeRed logic consisted of only 6 nodes.

Building the Sailboat

There are a lot of different building materials that you could choose from. K’Nex construction pieces are lighter than either Lego or Meccano and they allow you to create reasonably large structures with a minimal number of pieces. If you do not have access to K’Nex pieces then popsicle sticks and some card board would offer a good low cost solution.

To build the sailboat we used:
• K’Nex building pieces
• 4 plastic bottles
• 1 small plastic container with a lid
• String
• Duct tape
• Garbage bag
• Low torque servo
• Raspberry Pi Zero W or Pi 3
• Small USB phone charger

The base of the sailboat was a rectangular structure with 16 down facing K’Nex pieces that allowed plastic bottles to be duct taped in place.

boat_bottom

A few K’Nex pieces were used to create a compartment for the servo, and wire was used to secure the servo in place. A rudder was built by screwing a small piece of wood into the servo arm.

servobox

A garbage bag was cut to the required size and taped to the mast. The boom had a swivel connection to the mast and guide ropes were connected to both the boom and mast.

sailboat_details

Servo and Rudder Setup

Only very low torque servos can connected directly to Rasberry Pi GPIO pins.

Pi_servo_wiring

An example of a low torque servo would be the TowerPro SG90 ($4) that has a torque of 25.00 oz-in (1.80 kg-cm). If you have larger torque servos you will need to either use a custom Raspberry Pi servo hat (there are some good ones on the market), or you will need to use a separate power and ground circuit for the servo.

The wiringPi tool gpio can be used to control the servo. This package is pre-install in the Raspbian image, or it can be manually installed by:

sudo apt-get install -y wiringpi

Servos typically want a pulse frequency of 50 Hz, and the Raspberry Pi PWM (Pulse Width Modulation) pins have a frequency of 19200 Hz, so some range definitions and scaling is 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 is to put these commands in the Pi user login file of: $HOME/.bash_login.

After the pwm setup commands are run you need to do some manual testing to define your different rudder (servo) positions (Figure 6), such as “Hard Left”, “Hard Right”, “Easy Left”, “Easy Right” and “Straight”. The pwr timing numbers will vary based on your requirements and servo arm positioning, for our sailboat we used:

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

servo_settings

NodeRed Logic and Dashboards

NodeRed is pre-installed on the Raspbian image, but it will need to be set to autostart on a Pi reboot:  sudo systemctl enable nodered.service

NodeRed has a web configuration interface that is accessed by: http://localhost:1880 or http://pi_ip_address:1880.

On the options button (far right), by selecting: View -> Dashboard , you can define and change the web dashboard layouts.

dashboard

To create logic, nodes are selected from the left node panel and dragged and dropped on to the center flow panel. Logic flow are then created by clicking and joining together different inputs and outputs on the nodes. If a dashboard node is dropped on the flow panel it will be added to the default web dashboard. The gpio -g pwm commands can be called using the exec node. The button dashboard node will pass the defined payload value, for example a “Hard Left” 260 is passed when the button is pushed. The button’s payload value will be appended to the exec command to make a complete gpio -g pwm servo position command.

nodered

Once you’ve completed your logic setup press the Deploy button on the top right to make your configuration live and ready to test.

The final step is to enable a smart phone or tablet to connect to the Raspberry Pi, this can be done by either making the Raspberry Pi a WiFi access point or by tethering the Pi to a cell phone. There are some great guides on how to setup a Raspberry Pi as an access point. For this project the simple tethering method was used. Once the Pi is tethered to a phone, the PI’s IP address can be obtained from the hotspot users list.

pi_address

The NodeRed dashboard is accessed on your phone by: http://pi_ip_address:1880/ui .

nodered_ui

Assuming that everything is connected correctly you should be able to control the sailboard with your phone.

Summary

Once you’ve mastered the basic NodeRed and sailboat construction other projects such as motor boats, iceboats, airboats are possible.

airboat

 

 

 

Arduino talking TCP to Node-Red and Python

There are some great Arduino modules with integrated ESP-8266 wireless chips, some of the most popular of these modules are:

  • Adafruit HUZZAH
  • NodeMCU
  • WeMos

Along with these modules comes some excellent libraries.

For Arduino to PC or Raspberry Pi communications that are a few options to choose from. A TCP client/server is simple and straightforward and it is excellent for sending single point information. For sending multiple data points take a look at MQTT (Message Queuing Telemetry Transport), it’s a common standard for IoT applications and it’s built into Node-Red.

Arduino TCP Client

The Arduino module can be a simple TCP client that can talk to either a Python or a Node-Red TCP server. Below is an example that sends a random integer to a TCP server every 5 seconds.

/*
Test TCP client to send a random number
 */
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {
    Serial.begin(9600);

    // We start by connecting to a WiFi network
    const char * ssid = "your_ssid";       // your WLAN ssid
    const char * password = "your_password"; // your WLAN password
    WiFiMulti.addAP(ssid, password);

    Serial.println();
    Serial.print("Wait for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    delay(500);
}

void loop() {
    const uint16_t port = 8888;          // port to use
    const char * host = "192.168.0.123"; // address of server
    String msg;

    // Use WiFiClient class to create TCP connections
    WiFiClient client;

    if (!client.connect(host, port)) {
        Serial.println("connection failed");
        Serial.println("wait 5 sec...");
        delay(5000);
        return;
    }
   
    // Send a random number to the TCP server
    msg = String(random(0,100));
    client.print(msg);
    Serial.print("Sent : ");
    Serial.println(msg);
    client.stop();    
    delay(5000);
}

Node-Red TCP Server

Node-Red is an excellent visual programming environment that is part of the Raspberry Pi base install. Node-Red is a simple tool to create your own Internet of Things applications. The base Node-Red installation includes a TCP server and client.

To install the web dashboards enter:

sudo apt-get install npm
cd ~/.node-red
npm i node-red-dashboard

To start Node-Red either use the on-screen menus or from the command line enter:

node-red-start &

Once Node-Red is running the programming is done via the web interface at: //localhost:1880 or //your_Pi_ip_address:1880 .

To configure the TCP server, go to the Input nodes section and drag and drop the TCP in node. After the node is inserted double-click on it and edit the port and message settings.

nodered_tcp

To create a gauge Web dashboard, go to the dashboard nodes section and drag and drop the gauge node. After the node is inserted double-click on it and edit the dashboard group, labels and ranges.

nodered_tcp_gauge

For debugging and testing an output debug node is useful.

To access the Web dashboard enter: //localhost:1880/ui or //your_Pi_ip_address:1880/ui

TCP Python Server

The python TCP server will see the incoming Arduino message as a Unicode (UTF-8) text, so convert message to an integer use: thevalue = int(data.decode(“utf-8”)). Below is the full code.

import socket
import sys

HOST = '' # Symbolic name, meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ('Socket created')

#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
sys.exit()

print ('Socket bind complete')

#Start listening on socket
s.listen(10)
print ('Socket now listening')

#now keep talking with the client
while True:
#wait to accept a connection - blocking call
conn, addr = s.accept()
data = conn.recv(1024)
print ('Connected with ' + addr[0] + ':' + str(addr[1]) + " " )
thevalue = int(data.decode("utf-8"))
print ("Value: ", thevalue)

s.close(

Summary

In our final application we mounted the Arduino module outside and we powered it with a small solar charger. We also include a humidity value with the temperature, and we used a QR code that linked to our web page.

littleBits Paddleboat

We made a few versions of the littleBits paddleboat, using bluetooth, IR (infrared with TV remotes) and wireless Ethernet (ESP8266) for control.

For sure the easiest approach is to use a litteBits wireless transmitter and receiver. This method is a hardware only solution and no software/coding is required.

For the wireless littleBits approach the following items are required:

  • 1x littleBits mounting plate (comes with base set)
  • 1x littleBits fork module ($12)
  • 2x littleBits dimmer($8) or slide switches ($10)
  • 2x littleBits power module with battery ($6)
  • 2x littleBits DC motors (o5) ($19)
  • 1x ittleBits wireless transmitter (w12) Bit ($40)
  • 1x wireless receiver (w11) Bit ($40)
  • 2x wire Bits
  • duct tape
  • thin card board
  • tupper ware

Paddleboat Circuit

The paddleboat circuit had the two DC motor bits connected to the wireless receiver bit. A power bit was connected to the input of the receiver bit.

motor1

PaddleBoat Construction

We tried a few designs for the paddle boat, so experiment to find out what works best for you. The most important thing about the design is the paddles, they need to be waterproof and long enough to touch the water. The first step is to cut four rectangles out of thin card board (cereal or cracker box). For our design we used 2″x4.745″ (5cm x12cm). We cut even slits half way in each paddle blade, so that the two pieces would fit together. Next we put the paddles into the littleBits motor attachment and covered them in duct tape (you need to make sure the card board is completely covered).

construction_steps

A 6″ (15 cm) wide dish would fit the littleBits mounting plate, and we used duct tape on the bottom and side to secure things in place. We found that our boat floated a little higher than we wanted so you might need to add some weight.

tupperware

Remote Control

We connected the power module to a fork module and then the fork module powered our dimmer modules. We mounted all the components on a littleBits mounting plate, and we taped the battery to the back.

frontremote

backremote

Final Testing

Despite the fact that the motors do not turn very fast we were quite surprised how well the boat worked. The motors have a “left” and “right” toggle switch. This toggle switch is used to set the forward direction.

 

 

PSP Controlled Arduino Airboat

We thought that it would be fun to try and use an old PlayStation Portable (PSP) on some Arduino and Pi Projects. If you don’t a have PSP you can usually find a used one at a good price.

Some smart people were able to modify or “mod” the PSP firmware so that it is possible to run open source applications on the PSP. We tried using Python, Lua, sdlBasic and SSH to talk between our PSP  and our Arduinos and Pi’s, but none of these methods were simple or 100% reliable. In the end we found that basic built-in PSP Web browser worked the best and it didn’t require a ‘moded’ PSP.

airboat

PSP Setup and Limitations

We were using an older PSP-1000 so if you have a newer PSP GO or PSP Vita you may not have the same limitation that we found. However we think if you stick to our ‘worst case’ setup you should be good to go.

Our recommended setup was:

  • Simple Web Pages
  • No Browser Cache
  • Simple Wireless Network

For the PSP-1000 the web pages had to be very simple, no CSS (Cascading Style Sheets) and no advanced HTML tagging. We had hoped to show Node-Red Web pages from the PI but this was not possible.

In our testing we found that it was important to turn off the browser cache, otherwise we found that our commands would only work once. To turn off the PSP browser cache, go into the PSP browser and select “Tools”, then “Settings”, and “Cache Settings”.

cache

Our older PSP-1000 had some problems with the newer WPA2 wireless encryption, so to simplify things we created a small standalone open network. For Arduino projects this isn’t a problem because the Arduino can be made into a standalone access point. On Pi projects where you are using an existing wireless network you might need to do some tweeking to add a guest account.

To add a new connection on the PSP go to the “Network Settings” and select “Infrastructure Mode”. Then select “[New Connection]” and “Scan”. The scan will only show networks that the PSP is able to connect to.

networksettings

A Simple Web Form

An HTML form supports two types of action, a POST and a GET. The GET method is the simpler (but less secure) approach and it passes parameters on the URL command line.

Below is a simple Web form:

<html>
<body>
<h1>Click a button to control the car</h1>
<form action='GO' method='GET' >
<INPUT TYPE='submit' VALUE="GO" >
</form>
<form action='STOP' method='GET' >
<INPUT TYPE="submit" VALUE="STOP" >
</form>
<form action='LEFT' method='GET' >
<INPUT TYPE='submit' VALUE="LEFT" >
</form>
<form action='RIGHT' method='GET' >
<INPUT TYPE="submit" VALUE="RIGHT" >
</form>

</body>
</html>

menu

An Arduino Web Server

To create Arduino WiFi projects the ESP8266 based modules are low cost way to go. There are some good ESP8266 libraries and the examples are fairly easy to follow. The ESP8266 module can be wired into an Arduino Uno/Nano/Mega module or you can by buy boards with the ESP8266 chip integrated in. For our testing we used an older WeMo board, but other options like the NodeMCU, Adafruit HUZZAH or even the Arduino Yún could be used.

The ESP8266WebServer library has a simple standalone access point example. We modified this example (WifiAccessPoint) to include HTML form tags for all our required action.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

int pinleft = 12;
int pinright = 13;
int pinfront = 14;

/* Set these to your desired credentials. */
const char *ssid = "MY8266";
const char *password = "";

char *webpage = "<html><head><title>My8266 Control</title> \
</head><body> \
<h1>Click a button to control the car</h1>

<hr>

\
<form action='/go' method='GET' > \
<input type='submit' style='font-size:150px;color:lime' value='GO'></form>

\
<form action='/stop' method='GET'> \
<input type='submit' style='font-size:150px;color:red' value='STOP'></form>

 \
<form action='/left' method='GET'> \
<input type='submit' style='font-size:150px' value='LEFT'></form>

 \
<form action='/right' method='GET'> \
<input type='submit' style='font-size:150px' value='RIGHT'></form>

 \
</body></html>";

ESP8266WebServer server(80);

/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
Serial.println("Base page");
server.send(200, "text/html", webpage);
}

void go() {
Serial.println("Go forward");
server.send(200, "text/html", webpage);
digitalWrite(pinleft,LOW);
digitalWrite(pinright,LOW);
digitalWrite(pinfront,LOW);

}
void stop() {
Serial.println("Stop");
server.send(200, "text/html", webpage);
digitalWrite(pinleft,HIGH);
digitalWrite(pinright,HIGH);
digitalWrite(pinfront,HIGH);
}
void left() {
Serial.println("Go left");
server.send(200, "text/html", webpage);
digitalWrite(pinleft,HIGH);
digitalWrite(pinright,LOW);
digitalWrite(pinfront,HIGH);

}
void right() {
Serial.println("Go right");
server.send(200, "text/html", webpage);
digitalWrite(pinleft,LOW);
digitalWrite(pinright,HIGH);
digitalWrite(pinfront,HIGH);
}

void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
pinMode(pinleft,OUTPUT);
pinMode(pinright,OUTPUT);
pinMode(pinfront,OUTPUT);

digitalWrite(pinleft,HIGH);
digitalWrite(pinright,HIGH);
digitalWrite(pinfront,HIGH);

Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);

IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.on("/go",go);
server.on("/stop",stop);
server.on("/left",left);
server.on("/right",right);
server.begin();
Serial.println("HTTP server started");
}

void loop() {
server.handleClient();
}

Arduino Sailboat

To build the sailboat we used

  • Arduino Uno [1]
  • Prototype shield with bread board ($5)
  • Wireless RF module and remote ($6)
  • Small servo ($6)
  • 6x AA batteries with case and plug
  • K’Nex building pieces
  • 4 plastic bottles
  • 1 small plastic container with a lid
  • String, Duct tape, and a garbage bag (white if you have it)

The boat construction used the 4 bottles for flotation and a K’Nex frame.

structure

Mounting the rudder will probably require some trial and error, our design used some Lego pieces, duct tape and wire to hold it in place.

servo1

For the electronics we had some good success with a wireless RF (Radio Frequency) module. The wireless RF modules are relatively low cost ($6), and they do not require any fancy programming. remote1

wiring

The final Arduino code is :

//
// sailboat1.ino - use a wireless RF motor to move a servo on a sailboat
// RF buttons:
// A = straight (90deg), B = turn left (10deg), C = turn right (10deg)
// Limit rudder turning from 60-120 degrees
//
#include <Servo.h> 
 
Servo myservo; 
int pos;

void setup() {
 pinMode(5, INPUT); // A button - D0 pin on RF module
 pinMode(6, INPUT); // B button - D1 pin on RF module 
 pinMode(7, INPUT); // C button - D2 pin on RF module 
 pinMode(8, INPUT); // D button - D3 pin on RF module 


void loop(){

if (digitalRead(5) == HIGH) { 
 Serial.println("Button A");
 pos = pos + 10;
 if (pos > 120) { pos = 120;} 
 myservo.write(pos); 
 delay(250);
 } 
 if (digitalRead(6) == HIGH) { 
 Serial.println("Button B"); 
 pos = 90;
 myservo.write(pos); 
 delay(250);
 } 
 if (digitalRead(7) == HIGH) { 
 Serial.println("Button C");
 pos = pos - 10;
 if (pos < 60) { pos = 60;} 
 myservo.write(pos); 
 delay(250); 
 } 
 if (digitalRead(8) == HIGH) { 
 Serial.println("Button D"); 
 delay(250);
 }

}

littleBits Remote MP3 Player

For the remote MP3 Player project we used:

  • 1 –  power module with battery
  • 1 – littleBits wireless receiver
  • 1 – littleBits MP3 Player ($50)
  • 1 –  littleBits synth speaker ($20)

We created wireless remote to have a dimmer bit to control the volume and a littleBits button ($8) to change the song.

On the MP3 Player module the mode switch needs to be set to next to enable the remote button switch to change the songs. Finally we connected a speaker wire between the MP3 player and the speaker module and we duct taped the batteries to the bottom of the mounting plates.

littleBits Rover

Create a remote control littleBits rover using the littleBits wireless transmitter (w12) Bit ($40) and the wireless receiver (w11) Bit ($40). These wireless bits can also be  found in some of the littleBits kits, (for example the Gizmo and Gadgets kit).

The wireless modules can pass up to 3 signals. Depending on what you are trying to remotely control you could mix and match between dimmers, buttons and toggle switches. If you add some littleBits proto modules you could come up with some interesting designs.

Step 1 : Build the Remote

To create the wireless remote for the a Rover we needed to control the left and right motors , for this we used the following components:

  •  1- littleBits mounting plate (comes with base set)
  • 1 – littleBits fork module ($12)
  • 2 – littleBits dimmer($8) or slide switches ($10)
  • 1 – littleBits wireless transmitter
  • 1-  littleBits power module with battery ($6)

We connected the power module to a fork module and then the fork module powered our dimmer modules. We mounted all the components on a littleBits mounting plate, and we taped the battery to the back.

frontremote

backremote

The littleBits motor circuit is quite simple, the only important thing is to ensure that you have the wheels turning in the same direction.

motor1.png