The Python Console

Before writing a Python program to allow us to set the servo to an angle between 0 and 180, we can try some experiments in the Python Console.

To launch the Python Console type:
Download: file
# python
Python 2.7.3 (default, Apr  3 2013, 21:37:23) 
[GCC 4.7.3 20130205 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
First, we need to import the library, so enter the command:
Download: file
>>> import Adafruit_BBIO.PWM as PWM
Now enter the commands below into the Python Console one at a time, and you should see the servo change position.
Download: file
>>> PWM.start("P8_13", 95.0, 60)
>>> PWM.set_duty_cycle("P8_13", 97.0)
>>> PWM.stop("P8_13")
>>> PWM.cleanup()
NOTE: If your servo doesn't move you might need to change the polarity of the PWM signal and try again. Add a 4th parameter to the PWM.start function with a value of 1 (one), this will invert the PWM signal so it's low when normally high and vice versa.

Here's the same code but with the inverse parameter set:
Download: file
>>> PWM.start("P8_13", 95.0, 60, 1)
>>> PWM.set_duty_cycle("P8_13", 97.0)
>>> PWM.stop("P8_13")
>>> PWM.cleanup()
This guide was first published on Jul 15, 2013. It was last updated on Jul 15, 2013. This page (The Python Console) was last updated on Jul 16, 2019.