I2C communication using Python

3 thoughts on “I2C communication using Python

  1. Dear Sir,

    We are using GL868-DUAL module built in processor using python. We are able to Impliment I2C bus sucessfully, but it is responding garbage value. 

    Kindly refer attached example code and let us know, what is the issue.

    #start of I2C example for a particular I2C device
    import IIC
    import SER

    I2C_SDA = 3 # GPIO used for SDA pin
    I2C_SCL = 4 # GPIO used for SCL pin
    I2C_ADDR = 0x48 # myIIC1 address

    SER.set_speed(‘115200′,’8N1’)

    Thanks,

    Diwakar

    a = SER.send(‘————————————————————————rn’)
    a = SER.send(‘ Example of I2C control: ADC PCF8591 rn’)
    a = SER.send(‘————————————————————————rn’)

    myIIC1 = IIC.new(I2C_SDA, I2C_SCL, I2C_ADDR)

    status = myIIC1.init()
    a = SER.send( ‘ STATUS: %srn’ % status)

    ret = myIIC1.readwrite(‘x00’, 2)
    ret1 = ret[0] # Assign 1st byte to ret1
    ret2 = ret[1]
    a = SER.send( ‘ ret: %srn’ % ret)

    a = SER.send( ‘ ret1 %srn’ % ret1)

    a = SER.send( ‘ ret2 %srn’ % ret2)

      1. I don’t know much about the PCF8591 AD/DA but you shouldn’t first set the control byte?

        Try with the address shifted right, ie 0x24.