Saturday, November 24, 2012

RasPi Robot Remote - i2c Software Setup

Assuming you've already got your Raspberry Pi wired to your Adafruit 16 Channel Servo Controller here's how you get them to talk to each other.

First I followed Adafruit's instructions I found here:
http://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi

There's another good site for configuring Pi for I2C communications here:

My RasPi is running Raspbian OS so here's my summary of the steps I took:
Connect the RasPi to the Servo Controller, then at a RasPi command line:
sudo apt-get install python-smbus
sudo apt-get install libi2c-dev
sudo modprobe i2c-dev
lsmod
sudo modprobe i2c-bcm2708
sudo i2cdetect –y 1 (this will show a device at address 40 if the servo controller is connected)

edit “/etc/modules” file and add the line i2c-bcm2708 and the line i2c-dev
sudo adduser pi i2c    

NOTE: after this you should not need to run i2c commands with sudo

After a sudo reboot running sudo i2cdetect –y 1 should still show device at addr 40 if all is OK

Install git if not already installed: sudo apt-get install git

make sure you are in the /home/pi folder then:
cd Adafruit-Raspberry-Pi-Python-Code

edit /home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py and change SMBus(0) in line 11 to SMBus(1) because the 2nd gen RasPi is on bus address 1.

To test your RasPi+ServoController+Servo do the following at a command line:
cd ../home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver
sudo python Servo_Example.py

Your servo should start moving back and forth.  Press CTRL+C to stop the program.

NEXT UP... Setting up the web server

No comments:

Post a Comment