Connecting a sensor to WiPy 1 via I2C



  • Hi

    I'm trying to connect a lux sensor (TSL2561 https://learn.adafruit.com/tsl2561/wiring) to a wipy 1 with expansion board via I2C. I have connected the Vin and GND pins of the sensor to the 3V3 and GND pins respectively, and connected the SCL and SDA pins of the sensor to some of the pairs marked I2C0_... in the pinout (http://docs.micropython.org/en/v1.8.5/wipy/wipy/quickref.html).

    lux_sda = Pin('GP12', mode=Pin.ALT,   alt=5)
    lux_scl = Pin('GP13',  mode=Pin.ALT,  alt=5)
    

    I initialize the I2C bus like this:

    print('configuring I2C')
    #i2c = I2C(0, I2C.MASTER, baudrate=100000)
    i2c = I2C(0)
    print(i2c.scan()) # returns list of slave addresses
    

    However, i2c.scan() always returns an empty list []

    What am I missing?

    Thanks for your help



  • @jnc said in Connecting a sensor to WiPy 1 via I2C:
    I assume you have to specify the scl and ads pin in the constructor, like:

    i2c = I2C(0, scl=lux_scl, sda=lux_sda)

    And you may have to switch GP12 and GP13, as far as I understand the PinOut https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png

    lux_scl = Pin('GP12', mode=Pin.ALT, alt=5)
    lux_sda = Pin('GP13', mode=Pin.ALT, alt=5)



  • Not sure if you have figured out, but yesterday I started playing with my TSL2561 and I was able to get the lux.

    Here is the code I used:
    *import time
    from machine import I2C

    i2c = I2C(0, I2C.MASTER, baudrate=100000)
    #----- NOTE:
    #If you now do i2c.scan() you should get the address, typically 57 or 0x39 in hex (if you did not connected the address pins on the TSL2561)

    addr = 0x39

    #Power ON
    i2c.writeto_mem(addr, 0x80, 0x03)

    #Set Gain 1x and integration time to 402ms
    i2c.writeto_mem(addr, 0x81, 0x02)

    data = i2c.readfrom_mem(addr, 0x8C, 2)
    total_light = ((data[1]<<8) + data[0])

    data1 = i2c.readfrom_mem(addr, 0x8E, 2)
    ir_light = ((data[1]<<8) + data[0])

    print("Total: "+total_light)*



  • The sensor chip is designed for 3.3V, the module has an LDO and two FETs for level conversion. It should be OK to power the sensor module with 3.3V on 3vo and Vin pins together (the MIC5225 regulator used draws negligible reverse current). All of the I/O are open drain. Powering the device with 3.3V only on the Vin pin may be insufficient (the LDO has a dropout voltage around 0.3V).



  • Hi @abilio

    Thanks a lot for your help; regarding the voltage, I'm not really familiar with those electronic schemas; where do you see that it is foreseen for a 5V logic?

    On Adafruit's page (https://www.adafruit.com/products/439), I read: "New! As of June 3, 2014 we are shipping a version with a 3.3V regulator and level shifting circuitry so it can be used with any 3-5V power/logic microcontroller." So I thought it should work with the wipy

    Best



  • Hi @jnc,

    Checked your post. Normally the I2C class should set up the pins if you pass it to them, like this:

    I2C.init(mode, *, baudrate=100000, pins=(SDA, SCL))
    

    But my main concern here is that after checking adafruit's schematic for that board, it seems that the board was designed to be used with 5V. Sadly I believe powering it up from 3.3V won't do the trick, unless you either find a way to convert the signals back to 3.3V or you bypass the level converters FETs in it (the sensor chip works at 3.3V logic).


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.