Introduction: Nyan Bot - Arduino & Leddar
NYAN BOT PROJECT
Looking for a cool hands-on project to introduce kids to robotics, sensors and basic electronics? Using the Arduino platform and a LeddarOne sensor, this family affair was an excellent opportunity to work together to build something fun for everyone ─ including the cat!
PROJECT INFORMATION AND INSTRUCTIONS
For those of you who would like to build your own Nyan Bot, everything you need to know about putting it together is detailed below.
Before you begin, keep in mind that Nyan Bot is a moderately complex project that requires some soldering, so a few simple hand tools (needle-nose pliers, diagonal cutters, wire stripper, screwdrivers) and a soldering iron will be needed.
Also note that Nyan Bot has three distinct modes of operation:
First, its default mode of operation consists of moving straight ahead while scanning the environment. This is done by turning the turret left and right 12 degrees. It also animates the OLED with two Nyan Cat “rainbow” bitmaps and plays a “happy tune”.
Then, once it detects an obstacle located at 30 cm or less in front of it, it stops, updates the OLED with a “!!!” bitmap and plays an “unhappy sound”. Once playback is complete, it updates the OLED with a “???” bitmap and scans the turret over the complete 180 degree range. If it finds a clear path (at least 45 cm), it pivots on itself to that heading and resumes moving ahead.
Finally, if it doesn’t find a clear path, it goes into “sleep mode” by updating the OLED with a “zzz” bitmap and playing a “purring sound”. Once playback is complete, it randomly selects a heading and pivots on itself to that heading. It then attempts to scan for a clear path. If it finds one, it resumes moving ahead; otherwise, it goes into “sleep mode” again.
Download PDF for more info -->
Assemble and test BOE Shield-Bot chassis by following the Parallax instructions at http://learn.parallax.com/ShieldRobot. Complete the activities up to the end of Chapter 3; this will ensure that your chassis is fully functional and also give you a good introduction to the Arduino development environment if this is your first time using it.
Assemble the Ping))) mounting bracket kit and attach it to the chassis by following the Parallax instructions: http://www.parallax.com/sites/default/files/downloads/570-28015-PING-Mounting-Bracket-Documentation-v2.2.pdf. We will not be using the Ping))) sensor so you can ignore that part of the instructions.
1) The Shield-Bot chassis comes with a 5-AA cell holder. If you plan to use NiMH cells (this is recommended, as the completed Nyan Bot will need around 500 mA, and fresh batteries will only last a few hours), you need to add a 6th AA cell since the Arduino needs a minimum of 7V to run reliably. Parallax sells an accessory called the Boe-Boost that allows for a 6th battery to be installed. However, it’s fairly expensive and it makes swapping batteries (something you’ll do a lot) harder. We chose to add a single AA cell holder in series with the standard 5-cell pack, attaching it to the back of the chassis with double-sided tape. This also helps balance the weight on the chassis. Note: if you’re going to use double-sided tape, do yourself a favor and use the real stuff: 3M VHB. 4950 is a great general-purpose, conformable tape. You can get it from Digi-Key or McMaster-Carr, among other places.
Change the left wheel servo connection from port 13 to port 10. It’s never a good idea to use port 13 on the Arduino Uno because that pin is used by the boot loader, and it toggles a few times at boot time. The Nyan Bot sketch assumes that the left servo is on port 10, the right servo on port 12 and the turret servo on port 11.
Install the Leddar Configurator software on your computer, attach the LeddarOne to the computer with the LeddarTech USB to RS-485 cable, and connect to the LeddarOne. Program the sensor for 8 accumulations, 8 oversamples, 15 points, 55% intensity, 115200 baud and a Modbus address of 1. Click the apply button to save the changes in the sensor’s permanent memory.
Mount the Leddar One to the Ping))) bracket. Use this template to fabricate a holder from sheet stock (acrylic or aluminum), attach three M3 19mm standoffs (4-40 ¾ inch standoffs would also work), and attach the resulting assembly to the bracket using the provided 4-40 machine screws and plastic spacers, using the 2 vertically aligned holes in the top center portion of the bracket. You can then mount the Leddar One to the standoffs with machine screws.
You’re now ready to start assembling the expansion shield integrating the Leddar, LCD and audio interface circuits. We chose to use a piece of perfboard and some male header strips, but if you prefer, there are numerous Arduino prototyping shields available. If you opt to go that route, select one that has a large, uncommitted area and not a breadboard pattern. In our case, since we don’t need to connect to the offset P8 to P13 header and since we’re not going to stack another shield perfboard and headers, the scrap box was the quickest way to get there.
Start by positioning the OLED display and sound module, as well as the RS-485 transceiver. We chose to use female headers for the OLED display and the sound module, but they could also be soldered directly to the board. Also, position a 6-pin header to connect to the LeddarOne so that it’s near the front, right-hand side of the robot once the shield is installed. Mark Pin 1 on this header to remember where it is when connecting the sensor later.
Install the resistors and capacitor and wire the circuit as per this schematic. Wire routing is not critical – just make sure you follow the schematic exactly, and verify your work for short or open circuits. You will notice that we used voltage dividers on the signals going from the Arduino to the sound module. Although not explicit in the datasheet, the WTV020SD-20S is not 5V tolerant. The Arduino is able to read the 3.3V busy signal just fine, so no level translation is required for that signal. You will also observe that we put a 100 ohm termination resistor across the RS-485 line; do not forget this resistor!
Wire and attach the speaker. There are no specs for the audio output, but an 8 ohm, 0.25W speaker works fine. The exact speaker is not critical; we used a scrapbox part from an old cordless phone, about 1 ½ inches in diameter. We again used VHB tape to attach the speaker to the shield.
Prepare the SD card with the AD4 files: 0000.ad4 (the “happy tune”, played in a loop while the Nyan-Bot is rolling), 0001.ad4 (the “unhappy sound”, played when the Nyan-Bot reaches an obstacle) and 0002.ad4 (the “purring sound”, played when the Nyan-Bot is “sleeping”). I We started with ringtone files of the Nyan Cat tune, NONONONO cat cry and a purring cat; we trimmed them to the desired length with Audacity and also increased the volume on the purring sound. We then converted the files to 32 kbit ad4 format with USBRecorder, renamed the files (the filename is critical) and copied them to the Micro SD card, which we then inserted in the sound module.
At this point, we recommend adding some filtering capacitors on the breadboard portion of the Parallax BoE shield. We wired two 220uF capacitors to the 5V rail and one to the Vin rail, as follows: Make sure that the capacitors clear the expansion shield and the rotating turret assembly. These capacitors will help filter the voltage drop when the servos start or stop. Insufficient filtering or marginal batteries can cause erratic behavior of the Arduino, including spurious resets.
You’re now ready to attach the expansion shield to the Nyan Cat. Pay close attention to the correct alignment of the pins. Make sure to put the power switch on the BoE shield to the “2” position; otherwise, the servos will not be powered. The remainder of the circuitry (OLED display, sound module, LeddarOne) is fed directly from the Arduino, so if you need to troubleshoot your work, it can be useful to put the switch in the “0” position to prevent the robot from moving.
Wire the LeddarOne to the expansion shield. You need to connect Pins 1 to 5. Pin 6 is not connected (although wiring it won’t cause any harm). We used individual, female-to-female jumper wires 20 cm long, bundled them with spiral wrap and taped the ends together with electrical tape to create a harness and attached it to the LeddarOne and expansion shield. Pay close attention to connect Pin 1 to Pin 1! We added a stack of stand-offs next to the header on the expansion shield to tie-wrap the harness, and also tie-wrapped the other end to one of the standoffs holding the LeddarOne. This is important, as the turret will rotate and the reliability of this connection is critical.
Download and install the following Arduino libraries: Adafruit SSD1306 library, Adafruit GFX library, ElapsedMillis library, WTV020-SD-16P library and Leddar One Library.
At this point, you’re ready to load this sketch into the Arduino. You will want to hold the Nyan Cat so that its wheels and turret can rotate freely!
If you’ve followed all the steps correctly, your Nyan Bot should now be fully functional, but it will look a little bare. Now is the time to get creative! We used scrap InteFoam board to make two “pop tarts”, and attached white cardboard with double-sided tape (the plain paper tape, not VHB!), which we then colored with felt-tip pens. We also made “ears” with scrap acrylic stock, which we also covered with cardboard. Use your imagination; remember, however, that lighter is better, and make sure to use non-conductive materials. Also make sure that anything you attach to the LeddarOne does not touch the electronic components or obstruct the receiving optics or LEDs.
Obviously, feel free to change the sketch or create new bitmaps. We used Pixelformer to create the 128x32 bitmaps, and Radzio LCD Assistant to turn them into C. If you use LCD assistant, select a horizontal orientation, little endian encoding and 8 pixels per byte.