SimpleBot NodeBots Examples

From Open Hardware Miniconf
Revision as of 02:51, 9 January 2015 by Jonathan Oxer (talk | contribs) (Run the examples)
Jump to: navigation, search

Build Firmata

SimpleBot uses a combination of the Raspberry Pi (running Linux) and an Arduino-compatible board called the PiLeven (running Firmata) to control the robot and read from sensors. The SD card image provided in the kit includes the full Arduino IDE and supporting tools to allow you to develop Arduino code directly on the bot and upload it to the PiLeven.

The NodeBots examples rely on the PiLeven running a sketch that implements the "Firmata" protocol, which slaves it to the Raspberry Pi and communicates via serial. This effectively turns the PiLeven into an I/O board for the Pi, providing a standard protocol for the Pi to access the PiLeven's header pins and devices that are plugged into it.

Before running the NodeBots examples, the PiLeven needs to be flashed with firmware called `SBSFirmata`, which is a version of Firmata that specifically supports the features of the SimpleBot Shield provided in the kit.

Build and install Firmata on the PiLeven by running the following commands on the Raspberry Pi:

cd ~/simplebot
cd firmware/ino/SBSFirmata
ino clean && ino build
ino upload -p /dev/ttyS99

Run the examples

Three simple examples are provided, all written using Node.js to communicate with the PiLeven using Firmata. The examples must be executed from the `~/simplebot` directory so that Node.js can find the necessary libraries.

NeoPixel

The SimpleBot Shield includes 4 addressable RGB LEDs using the WS2812B chipset, frequently called "NeoPixels". This example cycles through the LEDs on the shield and blinks different colours:

cd ~/simplebot
node examples/SimpleBotShield/np.js /dev/ttyS99

Ping

The ultrasonic distance sensor on the front of the SimpleBot can be used to detect obstacles. This example repeatedly reads the sensor and reports the result in both cm and inches.

cd ~/simplebot
node examples/SimpleBotShield/ping.js /dev/ttyS99


Driving

Control the continuous-turn servos using arrow keys on your keyboard to drive the bot around. Once moving, the bot will keep going until you press the space bar to stop it.

cd ~/simplebot
node examples/SimpleBotShield/simplebot.js /dev/ttyS99

If you notice that your bot doesn't sit still, but instead creeps slowly on one or both sides, that's a result of the position potentiometers in the servos not being properly tuned. It's possible to disassemble the servo and tune the pots, but you can also compensate in software. Open the `simplebot.js` source file and look for variables that set the left and right wheel zero positions. The default value is 90, but you may need to change it to a value between 87 and 93. In very unusual worst case scenarios it may need to be adjusted as far as 80 or 100.