pololu / drv8835-motor-driver-rpi

Python library for the Pololu DRV8835 dual motor driver kit for Raspberry Pi B+
http://www.pololu.com/product/2753
Other
24 stars 12 forks source link

h1. Python library for the Pololu DRV8835 Dual Motor Driver Kit for Raspberry Pi

Version: 2.0.0 Release Date: 2016-05-04 "www.pololu.com":http://www.pololu.com/

h2. Summary

This library runs on the "Raspberry Pi":http://www.pololu.com/product/2757 (Model B+, A+, Pi 2, or Pi 3) and provides functions for controlling both channels of the "Pololu DRV8835 Dual Motor Driver Kit for Raspberry Pi":http://www.pololu.com/product/2753. This library supports both Python 2 and Python 3.

Programs that use this library will need to be run as the root user so they can access the GPIO pins.

h2. Getting Started

h3. Installation

This library depends on "WiringPi":http://wiringpi.com/ and "WiringPi-Python":https://github.com/WiringPi/WiringPi-Python. The instructions below explain how to install these prerequisites.

These instructions assume you are using Raspbian, Debian, or some other distribution that provides the @apt-get@ command for managing packages. If you do not have @apt-get@, you will need to use a different method to install the required packages.

These instructions also assume you will use Python 2. If you want to use Python 3, you will need to replace @python@ with @python3@ in the names of the @apt-get@ packages below, and use the @python3@ command instead of @python@ for running Python scripts, and use the @pip3@ command instead of @pip@ to install pip packages.

First, to download and install WiringPi-Python, run:

sudo apt-get install python-dev python-pip
sudo pip install wiringpi

Finally, to download and install the pololu_drv8835_rpi library, run:

git clone https://github.com/pololu/drv8835-motor-driver-rpi.git
cd drv8835-motor-driver-rpi
sudo python setup.py install

h3. Running the example program

This library comes with an example program that drives each motor in both directions. To run the example, navigate to the drv8835-motor-driver-rpi directory and run:

sudo python example.py

h2. Library reference

This library uses ultrasonic 20 kHz PWM to drive the motors.

Motor speeds in this library are represented as numbers between -480 and 480 (inclusive). A speed of 0 corresponds to braking. Positive speeds correspond to current flowing from M1A/M2A to M1B/M2B, while negative speeds correspond to current flowing in the other direction.

The library can be imported into a Python program with the following line:

from pololu_drv8835_rpi import motors, MAX_SPEED

After importing the library, you can use the commands below to set motor speeds:

For convenience, a constant called @MAX_SPEED@ (which is equal to 480) is available on all the objects provided by this library. You can access it directly by just writing @MAX_SPEED@ if you imported it as shown above, or it can be accessed in the following ways:

If you are controlling multiple motor drivers, you might prefer to import the library using @import pololu_drv8835_rpi@, which requires the commands listed above to be prefixed with @pololu_drv8835_rpi.@.

h2. Version history