Monday, 17 August 2015

Enabling I2C

I've received the parts.

  • PCA9685 - the Adafruit module wasn't pre-assembled so I had to do some basic soldering to put the connectors on. Nothing complex, but I had to remaster some old skills.
  • Breakout cable - there were absolutely no indications on the cable as to its proper orientation on the Pi side. I initially connected it the wrong way and I think I may have shorted some GPIO pins while trying to figure out why there were no signals on random pins when playing with some GPIO tools. Beware - use a voltmeter and make sure the pins are coming up at their expected positions on the other side of the cable before attaching any components to it on a breadboard.
Here's what my setup looks like.



Connecting the PCA9685 module is quite simple and straightforward.

Pi connected to  PCA9685
GND GND
3.3V VCC
SDA SDA
SCL SCL

Since I'm not driving any motors yet, I don't need to connect anything else.
Make sure that you connect the PCA9685 VCC pin to the 3.3Volt pin of the Pi, and not the 5V pin.
5V power would need to be connected to the V+ pin to drive motors, LEDs, etc., and would need to come from a separate power supply in order not to drain too much power from the Pi and interfere with its stability.

The PCA9685 board also has jumpers that you can solder to change the address of the module on the I2C bus. By default the address is 0x40.

Once that's all connected, power up the Pi and install the correct tools and libraries. I'll develop in C++, but it doesn't hurt to have the Python stuff as well. By the way, SMBus is a derivative of the I2C bus and that's why some tools are common.
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
sudo apt-get install libi2c-dev
Open /etc/modules
sudo nano /etc/modules
 Add those lines and reboot.
i2c-dev
i2c-bcm2708   
Since I have the Raspberry Pi 2, the I2C bus is on port 1 (instead of 0). To get the list of attached devices, run this command. It will search the /dev/i2c-1 device for all addresses and list them on the console.
sudo i2cdetect -y 1


I'll interface with the device in C++ in the next post...

No comments: