Who wants a one-eyed robotic skull?
We could have pan/tilt eyeballs, like from Monster Guts that move around with commands from an Arduino or Raspberry Pi. Let’s be practical, though. My latest Off-The-Shelf Hacker project, Hedley, already has a JeVois camera in the right eye socket. And, while the store-bought eye kit is awesome and all, it will set you back a good $180. Maybe we can add a single pan/tilt eye in a future article.
For now, I simply want a good-looking fixed eyeball that will programmatically glow different colors and attract attention, on the cheap.
So, the search was on to find an appropriate item to use as an eyeball.
My epiphany, other than using the JeVois smart machine camera in the right side socket came in the form of a small plastic Christmas tree ornament. My daughter was decorating a little tree and I scarfed several in various colors. It has a small decorative cap with a slot on top that’s easily removed, revealing a round, notched, circular protrusion that works great for holding a piece of 1/4″ brass tubing.
It fit perfectly in the skull.
The hole in the top was enlarged slightly with a drill bit and small rat-tail file. Plastic parts are easily worked by hand since you need almost no power to turn them. I simply twirled the drill bit between my fingers to make the right sized hole. No need for a drill press.
I also hand-drilled a hole in the front (bottom) of the ornament to form the iris. Again, a little touch-up, this time with a spiral cutting Dremel bit, made the hole pretty round in almost no time. Be careful with this particular Dremel bit because the flutes are very sharp.
A Programmable Spooky Glow
A while back we posted a discussion on selecting and using two different kinds of LEDs, common cathode and common anode. I used the common anode type, in this case, because the Pi can handle switching the power on its output pins. The common anode was attached to ground and each color went to its appropriate GPIO pin.
This time, instead of mounting the 100 Ohm resistors near the LED, I put them down on the Raspberry Pi 40-pin connector. There wasn’t enough room inside the 1/4″ tubing for all three resistors, so I just ran wires from the leads, down to the Pi. I used some 24-gauge stranded wire salvaged from an old serial mouse to connect the LEDs to the Pi. The wire is super flexible and pretty easy to use.
We only need 100 Ohm resistors because the general purpose input/output (GPIO) pins on the Raspberry Pi operate at 3.3 volts. You’ll find lots of 5-volt Arduino projects that use three-color LEDs. They require 270 Ohm resistors, due to the higher voltage. Always make calculations using 3.3 volts with the Pi GPIO pins.
After soldering the thin wires to the LED’s leads, I used little pieces of Scotch tape around each one to prevent shorting. It wasn’t pretty and was hidden inside the mounting tube. A dab of hot glue centers and secures the LED to the end of the tube.
The brass mounting tube is a press-fit into the eyeball. Then the eyeball is a press-fit into a matching hole in the skull’s left eye socket. For this one, I did use the Dremel to drill a pilot hole, since the plastic was pretty thick. After that, I again used the spiral bit to hand work the hole to the proper size.
Currently, the eyeball stays in the socket using just a press-fit. I’ll likely build a little bracket inside the skull that grips the mounting tube and holds it securely.
Keep It Simple, Use Python
The code to run the eyeball was very straightforward and similar to what I used in the previously mentioned basic LED visual interface article.
#!/usr/bin/env python2.7 import RPi.GPIO as GPIO # always needed with RPi.GPIO from time import sleep # pull in the sleep function from time module maxint = 30 GPIO.setmode(GPIO.BCM) # choose BCM or BOARD numbering schemes. I use BCM GPIO.setup(22, GPIO.OUT)# set GPIO 22 as output for red led GPIO.setup(17, GPIO.OUT)# set GPIO 17 as output for blue led GPIO.setup(27, GPIO.OUT)# set GPIO 27 as output for green led red = GPIO.PWM(22, 100) # create object red for PWM on port 25 at 100 Hertz green = GPIO.PWM(17, 100) # create object blue for PWM on port 24 at 100 Hertz blue = GPIO.PWM(27, 100) # create object green for PWM on port 24 at 100 Hertz # red.start(1) # start red led on 0 percent duty cycle (off) blue.start(0) # start blue on (100%) # green.start(0) # start green on (0%) # now the fun starts, we'll vary the duty cycle to # dim/brighten the leds, so one is bright while the other is dim pause_time = 0.05 # you can change this to slow down/speed up try: while True: for i in range(1,maxint): # 101 because it stops when it finishes 100 #red.ChangeDutyCycle(maxint - i) blue.ChangeDutyCycle(maxint - i) # green.ChangeDutyCycle(maxint - i) sleep(pause_time) for i in range(maxint,1,-1): # 101 because it stops when it finishes 100 #red.ChangeDutyCycle(maxint- i) blue.ChangeDutyCycle(maxint - i) # green.ChangeDutyCycle(maxint - i) sleep(pause_time) except KeyboardInterrupt: red.stop() # stop the red PWM output blue.stop() # stop the blue PWM output green.stop() # stop the green PWM output GPIO.cleanup() # clean up GPIO on CTRL+C exit
The code initialized the libraries and variables. Then sets which Raspberry Pi pins connect to which LED colors. After that, the program just loops a variable up, then down to change the duty cycle on the blue LED. Duty cycle is the width of the ON pulse from the pulse width modulation (PWM) Raspberry Pi GPIO pin. More width makes the LED brighter.
Starting with a small number the LED appears dim and gradually builds in intensity. Then the program goes the other way, to make the LED get increasingly dim. This gives a cool pulsing effect.
It’s also possible to add other colors or geometric functions to tailor the eyeball glow profile as you see fit.
I’m thinking it’s even possible to pulse the eyeball colors according to what the JeVois camera sees. For example, maybe when the skull recognizes that a human is standing in front of it, the eye glows blue. When a dog shows up it glows red.
We’ll have to explore the LED visual interface in the skull idea a little further.
Adding features and capabilities to the skull takes time and I usually can manage only one or two each week. Ah, the life of a tech “how-to” article writer.
Anyway, I’ll leave you with a couple of links to check out.
The first one is a little catalog of robotic head projects. Some you can buy. Some are very sophisticated. Some… well. Maybe they’ll spark a few ideas for your projects.
The other link is to the Monster Guts site. They have quite a selection of props and robotic parts, including pneumatics. We haven’t even discussed any of those at Off-The-Shelf Hacker yet. Be sure to watch their videos for new project inspiration.
So much off-the-shelf tech, so little time. Here’s to Old One Eye.