Reader small image

You're reading from  Raspberry Pi Essentials

Product typeBook
Published inApr 2015
Publisher
ISBN-139781784396398
Edition1st Edition
Right arrow
Author (1)
Jack Creasey
Jack Creasey
author image
Jack Creasey

Jack Creasey has been in the technology industry for more than 30 years, the last 15 years as a Senior Program Manager in hardware and software design. His expertise includes designing, developing, and teaching IT courseware. He is an avid inventor and holds 13 patents in hardware and software design. After retiring early from the computing industry, Jack avidly participates in social network groups that share his passion for next generation technology solutions.
Read more about Jack Creasey

Right arrow

Project 1 – Python control of a PWM board driving RC servo motors


You should now have a reasonable understanding of what is required to program an I2C PWM board, so let's look at some Python code to drive the Adafruit 16 channel PWM board.

Note

The python-smbus library is compatible only with Python 2 at the time of writing. To run PCA9685, you have to use IDLE and not IDLE3. To run from the command line, use Python and not Python 3. As with the RPi-GPIO library, the SMBus library needs to have root privileges.

First, create a new /home/pi/servo project directory for the files and download pca9685.py from the Chapter 6 folder at http://1drv.ms/1ysAxkl into the directory.

Then, open the pca9685.py file in the idle development environment, remembering to use the sudo idle command to start it.

Code block 1 – imports, constants, and variables

In this code block, we import the minimum amount for our functionality. Note here that the bus number i2c-1 or i2c-0 may vary depending on the Raspberry Pi version...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Raspberry Pi Essentials
Published in: Apr 2015Publisher: ISBN-13: 9781784396398

Author (1)

author image
Jack Creasey

Jack Creasey has been in the technology industry for more than 30 years, the last 15 years as a Senior Program Manager in hardware and software design. His expertise includes designing, developing, and teaching IT courseware. He is an avid inventor and holds 13 patents in hardware and software design. After retiring early from the computing industry, Jack avidly participates in social network groups that share his passion for next generation technology solutions.
Read more about Jack Creasey