i2c on raspberry

Ok this is it..

This is obviously the first and maybe more for me to remember how I got things to work, more than for you to understand. But if you find it interesting  and useful Im glad i could help out.

Now to my small project, I’m trying to figure out the I2c protocol, and for that I first needed to enable i2c on raspberry pi. This was done using

 

Then choose interfacing options and choose i2c. Not much to it, i kind of remembered that i needed to do a reboot afterwards and if i2c-dev wasn’t enabled in /etc/modules
then add that too.

There are heaps of sites that shows you how to do it, so I want go into it any further.
The next part was to load an i2c program to arduino.
Usually I ony use bare-metal programming , but since i couldn’t be bothered to get a proper i2c library for the AVR and for Servo I just to the used sketch-language or whatever its called.
I used arduino since it has better PWM support, and in this way i could use the i2c between raspberry pi and arduino to steer the servo.

I set the slave address to 0x06 for the arduino

Ok i might have forgotten to add the breadboard layout, so here it is:

Breadboard

The i2c clock/Data is provided in parallell to both the lcd display (which is also using i2c but a different slave address 0x3f).
The master is the raspberry pi.

Anyhow since I didn’t find a useful fritzing model for i2c-lcd screens i just took one with out it, but the green cables are the clock, the yellow are data,black ground and red vcc.

Now the LCD screen that I got had a slave address of 0x3f , the best way to figure out what addresses that different peripherals are using, is to use the command:

Here we can see that 0x06(Arduino) and 0x03f(lcd) is found from the raspberry pi.

Servo

Since this is more or less quick and dirty, get everything up and running with as little effort as possible, the servo was connected to PWM on pin 9 on the Arduino. I use a cheap Micro Servo 9G which is quite crappy, but I bought it really cheap from http://dx.com , there are only three lines for the servo, one which is to PWM,VCC and ground, I used Servo library provided by Arduino, and for debugging purpose i used a serial line, though i haven’t really used it yet, maybe further down the road if I extend this project, this might become useful.

My intention is to send the position of the arm from the raspberry pi over the i2c to the Arduino which will set the right position. The Led will then show what position in degrees the servo has.

 

Raspberry Pi

Since it don’t care to much about speed in this project and the support for i2c and other things are quite good in python, this was my choice.

I used a LCD driver that i got from the link, unfortunately who ever wrote it manage to put in a static address for the LCD i2c slave address. So i had to fix that, other than that i didn’t bother to much, I just wanted it to work as quick as possible. Here is the python program that works fairly good.