I2c

What function do I use to read/write to the integrated i2c port?

Also, Can I hookup more sensors using a hub on that I2C port?

Thanks!
Peter

Yes you can use a hub to extend the number of I2C sockets.

I2C is a bus, so you can have a whole stack of devices, all sharing the same wires.

Your main limitations are unique device addresses and power consumption.

The integrated I2C port is on the Raspi bus, meaning the GoPiGo is just like any other I2C device. You can either send I2C commands from the Raspi, or tell the GoPiGo to send them instead.

The GoPiGo I2C address is: 0x08

If you want the GoPiGo to issue an I2C command, you would need to first send an I2C command to it, and then it would send another command.

If you issue commands from the Raspi directly, you can avoid the second command / latency.

See line 34:
def write_i2c_block(address,block):

So, I am looking to read data from a Digital Light Sensor: Seeed Studio’s Grove Light Sensor.

What value should I use for “pin” since this is directly on the GoPiGo board?

Here’s my code:

import smbus
import time

address = 0x29

#Code used from GrovePi.py for testing.
pMode_cmd = [5]
aRead_cmd = [3]
bus = smbus.SMBus(1)
unused = 0;

def write_i2c_block(address, block):
        try:
                return bus.write_i2c_block_data(address, 1, block)
        except IOError:
                print "IOError"
                return -1

def analogRead(pin):
        bus.write_i2c_block_data(address, 1, aRead_cmd + [pin, unused, unused])
        time.sleep(.1)
        bus.read_byte(address)
        number = bus.read_i2c_block_data(address, 1)
        return number[1] * 256 + number[2]

write_i2c_block(address, pMode_cmd + [1, unused, unused])
print analogRead(0)

Hey,
The code that you were writing above was a good try but I don’t think that would work.

To port the code for the sensor, you basically have to port this example: https://github.com/Seeed-Studio/Grove_Digital_Light_Sensor/blob/master/examples/Digital_Light_Sensor/Digital_Light_Sensor.ino .
The example uses 2 functions: TSL2561.init() and TSL2561.readVisibleLux() , so you would have to port both of them from Arduino to Python. Here is the source library: https://github.com/Seeed-Studio/Grove_Digital_Light_Sensor/blob/master/Digital_Light_TSL2561.cpp and https://github.com/Seeed-Studio/Grove_Digital_Light_Sensor/blob/master/Digital_Light_TSL2561.h .

You can look at the libraries for other sensors here: https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_barometer/basic/grove_barometer_lib.py and https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_accelerometer_16g/adxl345.py. Just take care reading and writing data on I2C, especially with the number of bytes you are trying to read and write.

Do keep us updated about the progress.

-Karan