5 VL53L0X sensors on one I2C line. [SOLVED]

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Sasi
Posts: 44
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 12:11 pm
Has thanked: 10 times
Been thanked: 7 times

Flowcode v10 5 VL53L0X sensors on one I2C line. [SOLVED]

Post by Sasi »

Hello,

I would like to ask for a little help.
I want to use 5 VL53L0X sensors on one I2C line.
Can this be solved somehow with the current component macro?

If not, would you modify it so that the sensors are individually addressable?
It would also be nice if the modified version did not have the XSHUT pin connected to the MCU I/O pin.
In this case, it is the Flowcode user's responsibility to properly set the XSHUT legs before running the component macro's Initialise command.

Thank you in advance for your help.

Regards,
Sasi
Last edited by Sasi on Wed May 08, 2024 1:53 pm, edited 1 time in total.

BenR
Matrix Staff
Posts: 1760
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 447 times
Been thanked: 607 times

Re: 5 VL53L0X sensors on one I2C line.

Post by BenR »

Hello Sasi,

The VL53L0X device has a fixed I2C address and so you can only use one on a specific I2C bus. So the options are use different I2C busses for each sensor or use something like this to multiplex the I2C signals to the device you want.

https://www.adafruit.com/product/2717

I can probably generate a Flowcode library for this IC fairly easily if you want to try this.

edit: Yes the TCA9548A component was very straightforward to add so it's now available via the help -> Library updates.

Sasi
Posts: 44
Joined: Wed Dec 02, 2020 12:11 pm
Has thanked: 10 times
Been thanked: 7 times

Re: 5 VL53L0X sensors on one I2C line.

Post by Sasi »

Hello Ben,

Thank you for your suggestion. I was not familiar with this circuit before.
I thought of a similar solution, with 2 pieces 4051 analog multiplexers, until I found examples of re-addressing on the Internet.
The VL53L0X sensors do have a fixed I2C address, but this can be changed after power-up.
The procedure is as follows:
The XSHUT pin of all sensors of the I2C line is set to LOW level.
Then the XSHUT pin of one sensor goes HIGH and the new address is written into the sensor's 0x8A register using the default address.
After that, initialization of the sensor can begin, of course using the new address.
Then the XSHUT pin of the next sensor is set to HIGH..... until all of them have been re-addressed.

I tried this in an Arduino environment and it worked.
Later I want to use a PCF8574 I/O expander on the same I2C bus to control the XSHUT pins.
I don't know how much work it is to implement this in Flowcode, but I would love it. :D :D :D

Regards,
Sasi

BenR
Matrix Staff
Posts: 1760
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 447 times
Been thanked: 607 times

Re: 5 VL53L0X sensors on one I2C line.

Post by BenR »

Hi Sasi,

Aha thanks for the information. I've now added a new ChangeI2CAddress macro to the component which should do the address change for you. You will have to manage the XSHUT pins yourself using output icons to ensure you're only talking to a single device.

The latest version of the component is now available via Help -> Library updates.

The UpdateAddressRegister parameter will allow you to update the address on the device and then with this set to 0 you can then use a single component to talk to multiple sensors.

A typical program might look like this.

Code: Select all

Use XSHUT to enable device 0
Initialise
ChangeI2C Address 0x10, 1

Use XSHUT to enable device 1
Initialise
ChangeI2C Address 0x11, 1

Use XSHUT to enable all devices

Main program

ChangeI2C Address 0x10, 0
Sample Device 0

ChangeI2C Address 0x11, 0
Sample Device 1
Or you could just use multiple components if you wish.

Let us know how you get on.

Sasi
Posts: 44
Joined: Wed Dec 02, 2020 12:11 pm
Has thanked: 10 times
Been thanked: 7 times

Re: 5 VL53L0X sensors on one I2C line.

Post by Sasi »

Hi Ben,

Super. :D
I tried it with esp32 MCU and SSD1306 display.
I have attached the program in which 3 VL53L0X sensors work on the same I2C bus. It works very well.
Thank you very much.

Regards,
Sasi
Attachments
3_VL53L0X_sensors_on_same_I2C_bus.fcfx
(20.94 KiB) Downloaded 7 times

Post Reply