Skip to main content
3 of 3
replaced http://stackoverflow.com/ with https://stackoverflow.com/

How to use pigpio to control a servo motor with a keyboard?

My aim is to be able to control a servo motor with my keyboard in a real time fashion using the python module of pigpio. That is, when I press say the 'w' key it rotates clockwise and when I press the 's' key anticlockwise. I'm using an RPi 2, a tower Pro Micro servo SG90 and have connected it to the PWM enabled pin 13 (BCM denotation). My servo has not been modified for continuous rotation. My requests are:

  • A python code using pigpio to achieve this (or guidelines to do the same)
  • Is it possible for me to change the speed with which the servo rotates? As far as I understand it can be done using a for loop. If possible please allow that in the code

To use the keyboard I've tried reading this but am not able to decipher it. I've also tried going through the pigpio documentation and have managed to move the servo to a specific orientation.