2

I have tried to look in various foruns but couldn't find the solution for my problem. I'm trying to build a project where I have to use three VEML6070 sensors... These sensors obviously use the same address.

Hardware:

Raspeberry PI2 (I have one RPI3 and RPIZero that I could use)

Linux 4.19.85-1-ARCH #1 SMP PREEMPT armv7l GNU/Linux

Any help will be very much appreciated.

Config.txt:


dtoverlay=i2c-gpio,bus=5,i2c_gpio_delay_us=1,i2c_gpio_sda=20,i2c_gpio_scl=21
dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24

The result from i2cdetect -l is this:

i2c-3   unknown         3.i2c

i2c-1   unknown         bcm2835 I2C adapter

i2c-4   unknown        4.i2c

i2c-5   unknown         5.i2c

I have this Python example:

I replace i2cX with 3, 4 and 5 and the result is the same

import time
import busio
import board
import adafruit_veml6070

i2c5 = busio.I2C(board.SCL, board.SDA)
uv = adafruit_veml6070.VEML6070(i2c5)

(...) 

How can I do this with multiplexing in python?

At this point I just don't know if i2c5 = busio.I2C(board.SCL, board.SDA) or i2c3 = busio.I2C(board.SCL, board.SDA) or whatever makes sense.

EDIT - 31/12

Ok, thank you for you help and kind replies. I tried to find the answers for this issue without a mux but some of them were too complicated for me to understand.

So, I took a spare 4052 that I have here and connect all sensors. However to read all sensors with the same address I had to create three extra files - modules - and import them:

#uvsensor.py
import busio
import board
import RPi.GPIO as GPIO
import adafruit_veml6070

GPIO.setmode (GPIO.BCM)

GPIO.setup (5, GPIO.OUT)
GPIO.setup (6, GPIO.OUT)

GPIO.output(5, GPIO.LOW)
#GPIO.output(6, GPIO.HIGH)

def sensor_uv_1():
    GPIO.output(6, GPIO.HIGH)
    i2c = busio.I2C(board.SCL, board.SDA)
    uv = adafruit_veml6070.VEML6070(i2c)
    uv_raw = uv.uv_raw
    return(uv_raw)

and in the main file:

    import uvsensor
uv_1=uvsensor.sensor_uv_1()
print (uv_1)

The code needs a little tweaking to be proper organized (There is one last shot with a friend of mine that will try to modify the busio so it can read all three sensors.)

for now, all three sensors are working fine

  • 1
    Sorry, just tried to descriebe my problem the best and completely way that I can – Eddygrinder Dec 30 '19 at 1:13
  • 1
    Hi @ddygrinder, Welcome and nice to meet you. To get around multiple I2C devices same address problem, there are two general methods (a) hardware multiplexer, (b) multiple I2C buses. I have tried (a) and found it OK. For (b) it is NOT stable for Rpi3B+, though many guys claim it works, but NO ONE gave any details, not even raspbian version and date. I wasted perhaps 20 hours and finally gave up. I suspect that it works only for some os releases, ... – tlfong01 Dec 30 '19 at 2:01
  • But for Rpi4B, Rpi official docs says it is OK, I tried it and found I can set up I2c buses 1, 3, 4, 5, 6, but I can only use 4 buses at most, and only 2 or at most 3 are stable. I am still playing with I2C ADXL345 accelerator these days and found at least two buses are stable. You might like to look at my test results and feel free to ask me any newbie questions! :) This is my penzu diary on I2C: penzu.com/p/e072f2ae. – tlfong01 Dec 30 '19 at 2:04
  • One more thing, you seem to be using Arch and not Raspbian, no wonder your dtoverlay syntax is different from my raspbian. I have not tried recent debian, ubuntu or arch, though I from time to time read their man pages. – tlfong01 Dec 30 '19 at 2:17
  • 1
    And to do hardware mux, you can use TCA9546/9548 raspberrypi.stackexchange.com/questions/106478/…. – tlfong01 Dec 30 '19 at 2:35
2

If you want to continue to control your sensors on a single i2c bus, then you need to add a bus multiplexer to your system. It is another i2c device that will switch between downstream devices or buses. You will need to talk to it on i2c to tell it which downstream bus you want, before talking to the sensor. Since you are familiar with Adafruit, I suggest you consider their TCA9548A I2C Multiplexer, Adafruit PRODUCT ID: 2717. It allows you to have up to eight sub-buses, but requires you to add a layer of bus switching control to your software drivers.

| improve this answer | |
2

If I recall correctly joan's PIGPIO library can set up multiple bit-banging I²C interfaces on arbitrary pairs of GPIO pins without using a dtoverlay so you could simply put each one of these devices on a separate pair of wires (don't forget the pull-ups for the non-built in I²C bus pins).

It has been a while since I last played with my RPis but I recall that I wanted to run a secondary slower-speed bus as a long distance (well, around the house) I²C bus and that was the approach I was going to take - along with dedicated bus driver P82B715 ICs. {Running the bus at a slower clock rate allows for even worse capacitance figures than the x10 advantage those ICs give...}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.