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

2 Answers2

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.

Graham
  • 21
  • 1
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...}

SlySven
  • 3,631
  • 1
  • 20
  • 46