Std Servo and Accelerometer Communication

Part of my steps to get the different parts to talk to each other is a basic action/reaction workflow.  With all this tinkering, nothing ever works out of the box!  I soldered header pins onto a 2-axis accelerometer (Sparkfun) and hooked up to my breadboard.  I had two Hitec HS-81 servos for the neck of my robot (for video and sensors), so I wanted to try those first with the Arbotix microcontroller.  Again, nothing works as it should right off the bat.  I created a sketch using the ‘servo.h’ library and the servo did nothing but chatter during sketch upload.  I then found a PWM routine to use with servos online written by Tom Igoe (by the way, I have his book ‘Physical Computing’ – co-authored with Dan O’Sullivan) which used pulse code delay for moving the servo – worked like a charm!  I have already ordered a new 3-axis accelerometer because I don’t know if I got a flaky one, or I hosed it during my soldering.  The X-axis outputs random, crazy numbers even when standing still.  The Y-axis would vary by one digit once every 12-17 outputs even when standing still.  I divided the analogRead value by 10 and that reduced it somewhat, but still happened occasionally.  So for my test, I ignored the X-axis values and simply checked the Y-axis.  When I get my new IMU, it will have pins attached – so I rule out my iffy soldering skills.  Note to self: practice soldering tiny PCBs!  You can see the video below of one axis servo test.

IMU and Servo on Arbotix