Raspberry PI - Servo Steuerung

SERVOBLASTER (sehr einfach und funktioniert gut):

https://github.com/richardghirst/PiBits/tree/master/ServoBlaster

C-Code und Makefile downloaden, Kompilieren mit Make
Dämon starten mit "sudo ./servod", läuft im Hintergrund

allerdings sind dann fast alle GPIO auf OUT gestellt! Abhilfe: geänderter Servod-Aufruf : servodaemon.sh.txt

dann Befehle schreiben:
echo 0=150 > /dev/servoblaster     ## liefert 1500 us Signal

echo 0=+10> /dev/servoblaster     ## vergrößert das Signal um 10 einheiten, also 100 us


Steuerung mit Wiring-pi - lehrreich, für die Praxis aber dann nicht verwendbar

http://stackoverflow.com/questions/20081286/controlling-a-servo-with-raspberry-pi-using-the-hardware-pwm-with-wiringpi

liefert folgenden Beitrag
(GPIO 1 ist hier der Pin 12):

I'm a complete newby to Pi and to Servo's. But I got it to work with wiringPi.

It says here that we're looking to create pulse of 1ms to 2ms in length, every 20ms or so.
Assuming this 19.2Mhz base clock is indeed correct, setting pwm clock to 400 and pwm range to 1000, should give a pulse at 48Hz or every 20.8 ms.
Then setting pwm value to 48 should give you a 1ms long pulse and a pwm value of 96 should give you a 2ms long pulse.
But you need to set the chip in pwm-ms mode.
(Lots of shoulds here, since I do not have an osciolloscope either)

So to set it up:

  • gpio mode 1 pwm
  • gpio pwm-ms
  • gpio pwmc 400
  • gpio pwmr 1000

And then you can turn the servo from left to right via

  • gpio pwm 1 48
  • gpio pwm 1 96

(Actually, the servo I got worked from 28 up to 118; could be the servo) (The setup sequence seems important; could be a bug)

Weitere Links:

http://www.meineseiten.info/2013/03/raspberry-pi-servoansteuerung/

http://www.rn-wissen.de/index.php/Servos

 


Python-Steuerung: (falls man mehr mit Python programmieren will)

Anleitung: http://pythonhosted.org/RPIO/index.html

RPIO installieren:

$ sudo apt-get install python-setuptools
$ sudo easy_install -U RPIO

RPIO mit Python steuern (ohne py-Skript zuerst "sudo python" eingeben um Python zu starten):

from RPIO import PWM

servo = PWM.Servo()


# Set servo on GPIO7 to 1200µs (1.2ms),  GPIO7 liegt an Pin 26
servo.set_servo(7, 1200)

# Set servo on GPIO7 to 2000µs (2.0ms)
servo.set_servo(7, 2000)

# Clear servo on GPIO7
servo.stop_servo(7)