Topic: Servo control with Chumby PWM

I was able to modify some PWM examples to generate servo compatible signals. Servos need power, ground and a PWM signal that tells them what position to go to. I used a  little (Sparkfun) hobby servo tied to Infocast 3.5" PWM ports. I had previously installed a serial port via stereo jack that brought out the two PWM/serial pins and ground.  The servo also needs 5V or more on it's power pin so I tapped the usb port with an old usb cable that I hacked the end off of.  Yeah it would have been better to put in a new connector but I didn't feel like taking the poor think apart again.

This code sample "homes" the servo and then runs through full range and back.

#!/bin/bash
#                                                                         
# Simple Servo controller using the PWM ports on an Infocast 3.5" (Chumby)
# The serial in/out pins can be reconfigured as PWM ports                   
# Servos are pulsed at regular intervals, up to 50 times per second (20msec)
# The length of the pulse determines the position and can be from         
# 1msec to 2msec where 1msec is the home positon and 2msec is farthers out
# Some servos vary slightly from these numbers                                 
# The Chumby processors signal at 3.3v which may not work for all(most?) servos
#                                                            
                                                             
# moves a servo to whatever value is stored in the variable i  
move_servo()                                                   
{                                                              
 # Set an "active" and an "inactive" period of 3750 cycles each
 # 1msec = 375 (0x177) cycles 2msec=750 (0x2ee) cycles              
 regutil -w HW_PWM_ACTIVE0=0x0$(printf "%x" $i)0000                 
                                                                    
 # Set the crystal to divide by 64, and have a period of 7500 cycles
 # frequency should be about 50hz (500hz was 750) or 20msec period       
 regutil -w HW_PWM_PERIOD0=0x005b1d4c                                    
                                                                         
 # Turn on PWM0 Do we really need this every cycle or only the first one?
 regutil -w HW_PWM_CTRL_SET=0x00000001                                         
                                                                               
}                                                                              
                                                                               
# Set bank 1, pins 26 and 27 to be PWM output                                  
regutil -w HW_PINCTRL_MUXSEL3_CLR=0x00f00000                             
                                                                         
# swing full range and back                                              
# the regutil calls are slow enough with small increments that no sleep is neede
for i in {375..750..8}                                                          
do                                                                              
  move_servo                                                                     
done                                                                            
for i in {750..375..-8}                                                         
do                                                                              
  move_servo                                                                     
done                                                                            
                                                                                
exit 0                                    

It would be simple to modify this to read values off of command line parameters so you could move the servo via a web server cgi call.

Re: Servo control with Chumby PWM

Mmm where are the PWM/serial ports? smile  Please share smile

Re: Servo control with Chumby PWM

The 3.3v console port pins are available on the motherboards. (Some soldering required).  The same pins can be converted from the console port to PWM pins.

Here's a description of adding an external (3.3v) serial port that is compatible with cell phone or other FTDI cables. http://joe.blog.freemansoft.com/2011/01 … or-on.html

Re: Servo control with Chumby PWM

Oh thanks... I won't be touching those... I use the console for debug/recovery and too much of a hassle to use it for any other purpose.  I'll use the GPIO to drive servos I think.

Re: Servo control with Chumby PWM

Very nice!  Will this work on a Chumby One?  And how do you connect the servos to the Chumby?