RobotGrrl Hack #5: Winter Wonderbot

Friday, January 2, 2015

Fabule is proud to present a series of Clyde hacks by Erin RobotGrrl! She has taken some time from her flock of RoboBrrds to teach Clyde a few new tricks.

Happy winter everyone and everybot! It’s a great season to enjoy many activities. For a robot, this is not just limited to being a robot snowplow.

In this hack, we will be making Clyde into a winter themed connected cheerlights device!

Clyde will be connected to your computer, which will be running a little Processing sketch to connect to the Cheerlights feed. This will be able to tell Clyde what colour to set its eye too.

It will look good on any table, maybe you could mount it inside of a tree as an ornament. Or place it inside of a window to show to the world that you are crazy about robots and winter at the same time.

A Hack in Seven Parts

There are numerous sections to this hack, so get some popcorn and the soldering iron heated up as this will be a fun adventure!

Part 1: Generating Snowflakes

The first step is we need to generate seven snowflakes for Clyde. Six for each of its legs, and one for its antennas.

We will eventually be 3d printing these out, however you can also just use a regular ink printer and cut out the snowflake shapes to use.

Step 1: Using the Snowflake Generator, start creating your design. Export it as .svg when done.

Step 2: Go to Tinkercad and create a new design. Now, import the snowflake .svg at a scale of 15% and height of 1mm.

Step 3: In the design, add two cylinders to the middle of the snowflake. The outer cylinder should be wider than the inner cylinder. This will be used as a LED holder.

Step 4: Make the inner cylinder into a hole type.

Step 5: Adjust the view to look at the bottom of the snowflake. The wider cylinder should be able to be seen. The inner, or hole, cylinder should not. Make sure this is positioned 1mm above the plane.

Step 6: Make the inner cylinder 10mm tall

Step 7: Make the outer cylinder 8mm tall.

Step 8: Now that we are done, export the design as a .stl file by going to Design > Download for 3D printing (and press the .STL button).

Step 9: Go back to the ‘main screen’ of Tinkercad, and duplicate your snowflake design. Open the newly created design, delete the snowflake in it, then upload the next one and download it for 3d printing. You won’t have to create the LED holder again, as we duplicated the design and it is already there!

Step 10: Using your favourite slicer, import the design and generate the gcode. Here our settings are for using the Taulman t-glase orion blue filament, so we are telling the printer to go slowly. :)

Step 11: 3D print it! Make sure that the first layer adheres well to the build platform (... as usual)

Step 12: Admire your 3D printed snowflakes. They look so cool!

Part 2: Wiring & Adding LEDs

Now it is time to start preparing some of the electronics for Clyde. We will be adding 8 white 5mm LEDs. With a 74HC595 chip, we will be able to control them individually.

Step 1: Gather the parts that you will need.

  • 8x White LED (5mm, diffused)
  • 8x 220 ohm resistors
  • 1x 74HC595 chip
  • 1x Tiny breadboard
  • 1x 0.1uF cap (not pictured, but you will need one)
  • 1x CR2032 coin cell battery (used for testing the LEDs)

and some ‘breadboard wire’ (22 awg, single core), and some wire for the LEDs (16 strands, ~50cm, 30 awg, single core).

Step 2: Chop off the ends of the LEDs, up to the ‘nubs’, about 5mm from the bottom of the LED.

Step 3: Strip the ends of the wires, and solder them to the LED.

Step 4: Repeat for all 8 LEDs.

Step 5: Remove the plastic ends from Clyde’s legs, and insert the LEDs into them. Make sure that both wires go through the entire leg.

Step 6: Using the coin cell battery, test each LED. Make some indication as to which wire is positive or negative.

Step 7: Place the tiny breadboard onto Clyde’s brain. With the wires marked in the previous step, take each of the negative ones and place them into the breadboard.

The wires should be in the same column. When there are too many wires, switch to the next column and place a jumper between the two columns. In the first column, insert a breadboard wire (which we will then connect to Gnd).

Next up, we will be adding the shift out chip and wiring it all together!

Part 3: Wiring the Shift-Out 74HC595 Chip

Now it is time to add in the chip, and connect all of the LEDs to Clyde!

Let’s look at the schematic for this chip:

Step 1: Place the chip into the breadboard with the circle notch facing the end of the breadboard, also facing the back of Clyde.

Step 2: Add the wires for Vcc and Gnd, as seen in the diagram above as the red and black wires. Remember to add the Gnd on the left side of the chip as well (just in case you didn’t see it).

Step 3: Add a 0.1uF capacitor between the Gnd and adjacent pin, as seen in the diagram above.

Step 4: Add the SH_CP, ST_CP, and DS wires, and connect them to the corresponding pins (12, 10, and 13 respectively) in Clyde’s brain.

Step 5: Add the resistors to each of the output pins on the shift out chip, as seen by the blue wires in the diagram.

Step 6: Now, last but not least, add the positive wire of the LEDs to each of the resistors.

Here is what it looks like when we are done- maybe yours will be neater!

Now it is time to test it out. Check out the Arduino ShiftOut page, and try some of the demo code from there like this one. Remember to set the pin numbers accordingly, and upload it to Clyde!

If wired properly, you should see the LEDs turn on. If not, just go back and check your wiring.

Finally, let us admire the new lights on Clyde!

Part 4: Add the LEDs to the Snowflakes

Now it is time to add the LEDs to the snowflakes. The way it will light up will make it look so interesting!

Step 1: Insert the LED into the holder on the snowflake. If it does not fit, use an xacto knife to widen the hole a bit. Add hot glue to secure it in place and cover the exposed leads of the LED.

Step 2: Place the LED into the leg, and add hot glue to secure it in place.

Step 3: That’s it for this task, so admire the illumination of the snowflake!

Step 4: Optionally, you can do something similar with the antennas. We mounted them onto Clyde’s body with some decorated paper.

Part 5: Processing Sketch

This Processing sketch will run on your computer, and essentially act as a way to attach Clyde to the internet. The sketch will download the latest item from the Cheerlights feed, extract the colour from it, and send the info to Clyde. Clyde will be running a sketch to listen for this data, then set its eye to that colour.

If you have not heard of Processing before, it is a programming environment that allows you to quickly prototype graphical ideas. It can go way beyond this though, you can create really complex interactive visualisations, even computer vision!

As for Cheerlights, it is a global internet connected feed that can be controlled by anyone through Twitter. Simply tweet something like “@cheerlights purple”, and any device that is connected to the Cheerlights feed will display the new colour! It’s available at any time of the year, but is especially active during the holidays.

OK, now let’s get started.

Step 1: Download the Processing sketch from the ClydeInvasion repository. It’s in the ClydeWinter/processing folder. Open the main file (ClydeCheerlights.pde) in Processing.

Step 2: In the Arduino tab (Arduino.pde), change the clyde_serial variable to whatever the name is for the port that you connect Clyde to.

Step 3: Run the sketch. You should see a small window appear, and its colour will be the current Cheerlights colour.

Step 4: Test it out! The sketch refreshes every 5 seconds. You can adjust the refresh rate in the FREQ variable.

Now that this is working, stop the sketch for now, and next we will upload the Arduino code to Clyde.

Part 6: Arduino Code

This is the last step to tie everything together, and have it working! Are you excited? Let’s begin...

Step 1: Download the Arduino code from the repository, it is located in the ClydeWinter/arduino directory.

Step 2: Open the main file (ClydeWinter.ino) in Arduino

Step 3: Upload the code to your Clyde

Step 4: Run the Processing sketch from the previous step

You should see “received heartbeat” appear in the console (the part at the bottom) of the Processing screen. If you are seeing this, that means it is connected! Clyde should be displaying the same (or, visually similar) colour as on the window.

So, how does this sketch work? Here is a little overview...

We initialise Clyde the same way, using the ClydeDev library.

We create three ‘patterns’ for the snowflake lights. One all on, the other two alternating on/off. Adding in the pins for the shift out chip, we can then hold the latch pin low and begin transmitting the data to the shift out chip. Set the latch pin to high, to signify that this is the end. The LEDs will then be updated!

Inside of the loop, we update Clyde and check for Serial data. Processing and Clyde are connected using the Serial port. This is how they speak to each other. When Clyde notices incoming data, it will parse it as an integer value. By default, this returns 0. If we do not see a 0, then it must be a new colour coming in from the Processing sketch. So we will set it to that colour- subtracting 1 since we are adding 1 on the Processing side (in order to avoid conflicting 0’s).

Next up, every 2 seconds we are having Clyde send a heartbeat. This is just a “~” character, which the Processing sketch is listening for.

We set the RGB of Clyde’s eye to the current colour, and also set the task lamp brightness.

Next, we have to update the snowflake LEDs! This update occurs every 250ms. The timing is not exact, as there may be some other tasks that may take longer and throw off the timing a bit. But, it still creates a nice visual effect.

Inside, we toggle a switch (in this case, denoted by the variable ‘bloop’), and depending on true or false, set the data to one of the patterns. We then send this data to the shift out chip, using the same process as described previously.

It would not be the holidays without annoying sounds! Clyde wants to participate in this as well! Every 3 seconds or so (the frequency is in the variable ‘sing_every’), Clyde will play a melody. The melody starts at a random frequency, and plays it on / off for a few times, then does a increasing sound at the end (we like to think of it as a ‘woot!’ sound).

Finally, all of this in loop() gets repeated for infinity. Or maybe, until the snow melts and you want to make a different Clyde hack. ;)

Part 7: Conclusion

Hope you enjoyed this mega Clyde hack. If you have learned something new, then this is great! Any questions, please post them in the Fabule forums.

If you are new to Processing, be sure to take some time and play around with it if you find it interesting.

Clyde will be blinking its snowflakes until the end of winter. :)

Special thanks to Fabule for sponsoring these hacks and letting me go crazy with Clyde!

Happy hacking and happy winter,
Erin RobotGRRL

There are no comments on this post. Add a comment

Add new comment