Connect with us

Reading from 4 identical sensors using a Raspberry Pi...

Discussion in 'Sensors and Actuators' started by Netizensmith, Jul 10, 2017.

  1. Netizensmith

    Netizensmith

    4
    0
    Jun 9, 2017
    Hi, total electronics noob here. Am slowly teaching myself the basics but current project dictates that i must run before I can walk!

    I have 4 proximity sensors (VCNL4010) that can be controlled using I2C. However, they are have the same address and the address cannot be changed. The Pi only has 1 (maybe 2?) I2C so I need a way to cycle through each sensor and read it.

    Software is my thing so i can write the code needed to get the job done; what I'm stuck on is the best way to connect the hardware. Initial investigations point to using 4 transistors to control the current getting to each sensor so that only 1 is alive at any one time. Does that sound right? Is there a neater way to do it?

    I currently have an ExplorerHat Pro sat on top of the Pi. I've done this because it gives me a nice way to control 2 motors and also neatly labelled pins for the I2C stuff.

    Any advice appreciated!
     
    Last edited: Jul 10, 2017
  2. kellys_eye

    kellys_eye

    4,284
    1,145
    Jun 25, 2010
    You can use two digital ports to drive a 2-4 line encoder and select each device from the encoder output. Saves on two ports if that's a particular issue for you.
     
  3. Netizensmith

    Netizensmith

    4
    0
    Jun 9, 2017
    Had an idea this evening that I could just use the 4 output (5v tolerant) pins (which sink to ground when ON) to cycle power each sensor. Initial tests showed that if I wired a sensor to SDA and SCL and 5v in, with the GND set to one of the output pins then yes - when the output pin was set to OFF I got an error trying to access the sensor, but if I turned the pin ON then I could access the sensor correctly. Hurrah I thought. So, next step was to set up the other 3 sensors in the same way. However, supplying any more than 1 sensor with 5v AND plugging in the SDA and SCL pins causes ALL sensors to be unreadable, even if 3 of them have the GND hooked up to an output pin set to OFF and only one has it set to ON.

    Like I said, I'm a total noob but I got a meter out and checked the voltage across the VIN and GND of each sensor. The "activated sensor" shows just under 5v but the "INACTIVE" sensors still show 750millivolts. In fact they show this even if their GND isn't connected to anything. The act of connecting the SDA and or SCL pins is enough that I can read voltage across VIN and GND.

    Any advice / suggestions?

    Please feel free to correct my terminology too; only way I'll learn.

    Cheers.
     
  4. kellys_eye

    kellys_eye

    4,284
    1,145
    Jun 25, 2010
    You're discovering that logic high and logic low can fall with a 'range' of values and not necessarily be +5V (or +3.3V) and ZERO......

    Going back to your original idea, you can use transistors (better to use small FETs) to switch the supply lines to the sensors. Look for logic-compatible FET switching devices that are designed for this purpose to save on component count (if that's an issue) or just use 2N7000 or similar discrete device.

    Whilst this idea works you will have to program to account for start-up time of each device and it's not good practise to do this as individual devices may differ enough to mess with your system if one needs to be changed.

    Ideally you would power them all and switch between the data lines using logic gates to select/deselect the relevant lines. This keeps the devices 'alive' - subject to any standby power requirements they may include - and 'isolates' the data lines. This is necessary as in your own design, should one device go faulty it will 'pull' the others down with it and you'd lose data from all sensors when just the one has gone faulty.
     
  5. Netizensmith

    Netizensmith

    4
    0
    Jun 9, 2017
    Thanks very much! Yes I had worried about the start up time of the sensors. So, I'll look at FET switching devices to switch between the I2C lines? whilst keeping all the sensors powered continuously?

    Thanks again.
     
  6. kellys_eye

    kellys_eye

    4,284
    1,145
    Jun 25, 2010
    Not 'exactly' what I had in mind but a compromise I suppose!

    If all you wish to do is select the IC2 lines then use tri-state bi-directional buffer devices like the 74LS 245. Check out its data sheet and come back if there are any parts of it you don't understand.

    There are also dedicated I2C buffers that offer additional improvements to the circuit capabilities. Check out this device I Googled (first result!):

    http://www.ti.com/lit/ds/symlink/p82b96.pdf

    If you understand the tri-state concept and wish to make a professional end-result then it's always wise to Google for the latest manufacturers devices.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-