Monday, December 10, 2012

Raspberry Pi, Chronos Watch, Servos and a Laser

What a great combination! Raspberry Pi, Chronos watch, Servos and a Laser.

This is a real mash-up from two projects. One that displays accelerometer data from a Chronos watch, over its wireless link. The other project being the Adafruit tutorial on using their I2C servo controller.

I combined them to make a two-axis servo mounted laser that mirrors the movement of my arm wearing the watch.

Watch the video to see what it does.

WARNING: Don't shine lasers in your or anyone else's eyes. 

To get this working for yourself, then first follow this tutorial to get your Chronos watch talking to your Raspberry Pi. Nice code thanks to Sean Brewer.

Then build this Adafruit tutorial, but you will need two servos rather than one. Thanks to Kevin Townsend.

Once both are working independently, then build the servo assembly. I just super-glued one servo to the arm of another and glued the optional laser module to an arm for the top laser.

Laser modules vary in voltage requirements. This one is driven from 5V from the Raspberry Pi with a 100 Ω series resistor. Laser modules vary so check the data sheet.

Set your Chronos to ACC mode and dont forget to press [Down] so that it starts transmitting the data.

Here is the Python script that controls everything!


from Adafruit_PWM_Servo_Driver import PWM
import time
import serial
import array

pwm = PWM(0x40, debug=True)

servoMin = 150  # Min pulse length out of 4096
servoMax = 600  # Max pulse length out of 4096
servoMid = (servoMax - servoMin) / 2 + servoMin

def startAccessPoint():
    return array.array('B', [0xFF, 0x07, 0x03]).tostring()

def accDataRequest():
    return array.array('B', [0xFF, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00]).tostring()

def twos_comp(val, bits = 8):
  if ((val & (1 << (bits-1))) != 0):
    val = val -(1 << bits)
  return val

ser = serial.Serial('/dev/ttyACM0',115200,timeout=1)

pwm.setPWMFreq(60)                        # Set frequency to 60 Hz

while (True):
  accel = ser.read(7)
  x = twos_comp(ord(accel[0])) # -50 to +50
  y = twos_comp(ord(accel[1]))
  z = twos_comp(ord(accel[2]))
  if x != 0 and y != 0 and z != 0 :
    pwm.setPWM(0, 0, servoMid-x*3)
    pwm.setPWM(1, 0, servoMid-y*3)

About the Author
These are my books. Click on the image below to find out more about them.

1 comment:

Bernadette Fox said...


I wanted to pass along a couple YouTube channels that I think would be great for you to share on your blog.

1. Cool Contraption Guy: http://www.youtube.com/CoolContraptionGuy
This channel was only started late last year, but there are already a good amount of videos and most of them are about basic DIY electronic gadgets. Making something to learn about it is how I like to learn so this channel is great in that regard!
2. The Geek Group: http://www.youtube.com/thegeekgroup
This channel has been around quite a few years and it's still going strong with new videos. It's not a DIY channel like the first I mentioned but still has some great content with lots of gadgets being dissected and explained.
3. IVES Comprehensive Electronics: http://www.youtube.com/Venturecaplaw
This channel seems to have segments from the 80's, but I've enjoyed what I watched so far. I guess it's because I grew up with Hewitt conceptual physics reruns. :)