Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Essentials

You're reading from   Raspberry Pi Essentials Get up and running with the Raspberry Pi to develop captivating projects

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781784396398
Length 212 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Jack Creasey Jack Creasey
Author Profile Icon Jack Creasey
Jack Creasey
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Getting Started with Raspberry Pi 2. Configuring the Raspberry Pi Desktop and Software FREE CHAPTER 3. Raspberry Pi and Cameras 4. Raspberry Pi Audio Input and Output 5. Port Input and Output on the Raspberry Pi 6. Driving I2C Peripherals on the Raspberry Pi 7. Going Mobile with Raspberry Pi 8. Creating a Raspberry Pi Line-following Robot Index

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image