Python

Code examples to power your SMARS creations


How to get the Python Library

Our SMARS Python library is available from github: https://www.github.com/kevinmcaleer/smars

Log into your Raspberry pi and type the command below to get the library:

git clone https://www.github.com/kevinmcaleer/smars


How to use the Python Library

The code you have downloaded contains several files:

   
SMARS_Library.py The SMARS Python library
ScratchListener.py The Scratch listener, used to send messages to and from Scratch
limb_setup.py Used to set the servos to the correct position when attaching the servo horn
pinouts.md Shows the pinout connections for the Raspberry Pi to PCA9685 Servo Driver
test.py A simple test program, use this to test you have built the quad robot correctly

The library uses the Adafruit PCA9685 servo driver board module, id you haven’t already install this, install it by typing the following from the raspberry pi command line:

sudo apt-get install git build-essential python-dev

cd ~

git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git

cd Adafruit_Python_PCA9685 sudo python setup.py install

if you have python3 installed:

sudo python3 setup.py install

You will need to install the following python libraries for this to work:

sudo apt-get install python-smbus sudo apt-get install i2c-tools

You will also need to enable the I2C interface using the raspberry pi configuration tool (raspi-config)

If you have Raspbian, not Occidentalis check /etc/modprobe.d/raspi-blacklist.conf and comment blacklist i2c-bcm2708 by running sudo nano /etc/modprobe.d/raspi-blacklist.conf and adding a # (if its not there).

If you’re running Wheezy or something-other-than-Occidentalis, you will need to add the following lines to /etc/modules

i2c-dev

i2c-bcm2708