Then why not using an other cpu to do the stuff! I know you could use the Pollolu serial servo but it is for one part maybe to rigid. So I decide to use a very small cpu , the Microchip pic12F1840.
This is a 8 pin dip and it will be able to drive 4 servos and it cost around $1.20 CAD per unit.
This was bought first to add analog capabilities for my Rpi but since a lot of people struggle with servos, I decide to start with a PWM module.
So first! look at the video https://dl.dropboxusercontent.com/u/488 ... iServo.MP4
And if you like it, continue the reading. This is only 1 part add-on to get 4 servos, up to 60, connected to the rpi on the GPIO14 port (uart TXM).
I design the system in a way that you could connect up to 15 modules in the same Rpi Txm pin.
But if you use 15 modules you should buffer the pin using 74hc08 for example.
15 modules will put 60 servos or 60 leds with intensity controlled or 20 colors leds.
N.B. You need to put a resistor in serie with led to limit the current.
This is the schematic of the system.
Quite simple is in it!
This is the source code in C https://dl.dropboxusercontent.com/u/48891705/RpiServo.c
This is the Hex file to program the cpu https://dl.dropboxusercontent.com/u/488 ... iServo.hex
Ok now to make it work on the Rpi, you need to disable the console and the system debug on the uart .
1 - in /boot/cmdline.txt removes "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
2- in /etc/inittab comment out the last line
"#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100"
3- Install python serial module
sudo apt-get install python-serial
And this is my python routine to check it. (the same as the video)
Code: Select all
#!/usr/bin/env python from time import sleep import RPi.GPIO as GPIO import sys, termios, atexit from select import select import serial out = serial.Serial('/dev/ttyAMA0', 9600) def SetPwm(Module , Channel , Value): out.write( chr(0x80 + (Module << 3) + (Channel)) + chr(Value >> 7) + chr(Value & 0x7f)) #set duration 20ms (default anyway) SetPwm(0,7,2000) #unlock Module Id SetPwm(0,5,0) #set Module Id to 2 SetPwm(0,5,2) #do a little dance for l1 in range(50, 250,50): for s1 in range(1,5): SetPwm(2,s1,l1) sleep(0.5) #go to the middle SetPwm(2,1,150) SetPwm(2,2,150) SetPwm(2,3,150) SetPwm(2,4,150) sleep(1) # do it faster for l1 in range(50, 250,50): for s1 in range(1,5): SetPwm(2,s1,l1) sleep(0.2) sleep(2); #set all servos to middle position SetPwm(0,0,150) sleep(1) #turn them off SetPwm(0,0,0)
I know this is not for everyone but this is the spirit. Start little and build upon it.
P.S. I know my breadboard and scope are old , >35 years, but they still work. Why change them.