Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Connecting a sensor to WiPy 1 via I2C

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy 1i2c
    6 Posts 5 Posters 3.7k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      jnc
      last edited by

      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

      A robert-hhR 2 Replies Last reply Reply Quote 0
      • A Offline
        abilio @jnc
        last edited by abilio

        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).

        1 Reply Last reply Reply Quote 0
        • J Offline
          jnc
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • L Offline
            LoneTech
            last edited by

            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).

            1 Reply Last reply Reply Quote 0
            • D Offline
              diego
              last edited by diego

              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)*

              1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @jnc
                last edited by

                @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)

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom