Thomson Reuters hosted a CoderDojo in November of 2016. One of the classes offered was "An Introduction to the Internet of Things (IoT) featuring the LightBlue Bean+". I had the honor of co-organizing and teaching this class. The primary focus of the class was programming the LBB+ itself, using the Grove items included in the LBB+ Starter Kit as an introduction to external hardware. This is a great exercise in and of itself, but does not provide much direct experience with the IoT. I had an old Parallax BoE-Shield Robot at home and thought it would be interesting to control it using Bluetooth Low Energy (BLE) via the LBB+.
The system contains three primary components:
- A BoE-Shield Robot and the Arduino/Genuino Uno controlling it
- A LightBlue Bean+ (a LightBlue Bean will work but the range of the connection is much smaller)
It will be easiest to work with this project if you get a copy of the code repository. For the purposes of this document, it is assumed that you created the clone in your home directory:
cd ~
git clone https://github.com/orderthruchaos/web_rc_boe_bot.git
cd ~/web_rc_boe_bot
The BoE-Shield RobotLet's start with the BoE-Shield Robot and its associated Uno. To start with, load the sketch rc_boe_bot_robot.ino onto the Uno. Once this is complete, ensure that the Uno is disconnected from both the power socket and the USB socket. This will save you from annoying piezo buzzer-related headaches while wiring the breadboard.
First, as a point of reference, the back of the robot is considered the end with the single spherical wheel and the Uno connectors:
Place a row of 5 long male headers into the socket for digital pins 3-7. Then, from the back of the robot, place a piezo or mini-speaker in the far left of the breadboard, with the positive lead (if any) connected closer to the rear of the robot. Use a piece of wire to connect digital pin 9 to that lead. The negative lead can be wired directly to ground:
Next, facing the front of the robot, add a row of 2 long male headers to the far-left of the next-to-closest row of the breadboard. Wire the pin on the right to 3.3V and the pin on the left to ground. This is the power source for the LBB+ acting as a receiver.
The BoE-Shield Robot is now ready for the receiver.
The LightBlue Bean+Before working with the LBB+, make sure that its firmware is up to date, and that it is in 3.3V mode:
Turn on the LBB+ and use the Node Bean SDK to find its address:
bean scan
This should create output like the following:
Scanning for LightBlue devices for 30 seconds...
New Device discovered or updated!
DEVICE_TYPE_LIGHT_BLUE:
Name: bnd+00
Address: 87d4d33ff9f14bea8b224197899aa043
Advertised Services:
a495ff10c5b14b44b5121370f02d74de
Command completed.
Quitting gracefully...
Done.
Make note of the listed name (you most likely know this) and address (much more important). I have found that, on my Raspberry Pi 3, the name may appear blank and the addresses are always shorter:
New Device discovered or updated!
DEVICE_TYPE_LIGHT_BLUE:
Name: bnd+00
Address: 987bf3582ee5
Advertised Services:
a495ff10c5b14b44b5121370f02d74de
If you know both addresses, make note of both! Next, load the sketch rc_boe_bot_srl_receiver.ino onto the LBB+.
Finally, ensure that the LBB+ is turned off. The LBB+ will be powered via the BoE-Shield Robot for the remainder of the document.
Mount the LBB+ on the BoE-Shield Robot by carefully aligning the GND and 3.3V sockets with the two power headers on the breadboard, and the digital pin 1-5 sockets with the digital pin headers:
The BoE-Shield Robot is now ready for operation.
Change directories to rc_boe_bot_server:
cd ~/web_rc_boe_bot/rc_boe_bot_server
Open the file src/known_devices.js
for editing and look for the boe_bot_rcv_device
entry. Replace the value for the "name"
key with the name found via bean scan
above. Next replace the "address"
entry with either an array of address strings or a single address string. The address was also found via bean scan
. This example is taken from the code:
module.exports.boe_bot_rcv_device = {
"name": "bnd+01",
"address": [ "987bf3582ee5", "87d4d33ff9f14bea8b224197899aa043" ]
// // Strings also work:
// "address": "987bf3582ee5"
// "address": "87d4d33ff9f14bea8b224197899aa043"
}
Now it is time to start up the server.
This library requires the Bean Node SDK. Please follow the link for installation instructions as they are out of scope for this document. Once Node.js and npm are available, install the package dependencies (this may take some time):
npm install
Next, build the source:
./bin/build
At this point, add a power supply to the BoE-Shield Robot and ensure that the breadboard and servos are powered:
Finally, start the server:
./bin/run_server
Once you see the message "Complete!", you are ready to go! To send messages to the server, simply enter URLs like the following into your web browser:
- http://127.0.0.1:3000/?f=2500 (go forward for 2,500 milliseconds)
- http://127.0.0.1:3000/?l=2500 (go left for 2,500 milliseconds)
- http://127.0.0.1:3000/?r=2500 (go right for 2,500 milliseconds)
- http://127.0.0.1:3000/?b=2500 (go backward for 2,500 milliseconds)
- http://127.0.0.1:3000/?h=1 (honk the horn)
Note that this is still somewhat of a work in progress, so entering multiple URLs in rapid succession may not have the desired effect.
TO-DOI plan on adding a user-friendly interface to this project (rather than bare URLs), but that is not quite ready yet.
ConclusionThis project has shown how it is possible to give new life to (relatively) old hardware by adding some modern components and performing a bit of programming. I hope you all enjoy it!
Comments