Is it possible to read data from a virtual I2C Bus i created on my Raspberry Pi 4 Modell B?

9 views (last 30 days)
Hello,
I'm currently trying to use an Acceleration sensor (LSM6DS3: https://content.arduino.cc/assets/st_imu_lsm6ds3_datasheet.pdf) on a virtual I2C-Bus I implemented on my Raspberry Pi. The reason I have to use a virtual bus is that i have to read out data from five LSM6DS3 sensors. So it works without problems on the Raspberry Pi itself. He recognises the virtual bus and is able to read ouf the device and it's data. Now when I use the I2C Master Read Block (https://www.mathworks.com/help/supportpkg/raspberrypi/ref/i2cmasterread.html) from the Raspberry Pi Package, it gives me a BUS_ERROR message. As far as I understand it means that the bus I want to read from doesn't exist.
The sensor itself has also a block (https://www.mathworks.com/help/supportpkg/raspberrypi/ref/lsm6ds3imusensor.html) where I can change the parameter of "I2C module" and I believe it's the number of the bus I want to use. Problem is when I start my simulation he show me values unequal zero, but freezes. So he recognizes this virtual bus and I really dont know how to fix this problem or what causes the problem.
My virtual bus occupies GPIO 17 and GPIO 27, the wires are also correctly connected and I activated the internal Pull-Up resistors, which show a resistance of 10kOhm as in the Datasheet mentioned.
I would be very happy if you could help me and if you need further information I will add them.
Thanks a lot and greetings

Answers (1)

Sandeep
Sandeep on 30 Aug 2023
Hi Ramona,
It is my understanding that you are facing issues while using the LSM6DS3 acceleration sensor on a virtual I2C bus implemented on your Raspberry Pi. It is possible to troubleshoot step by step.
  1. Make sure that the virtual I2C bus is set up correctly. Double-check the wiring connections for GPIO 17 and GPIO 27, ensuring that they are connected properly to the corresponding pins on the LSM6DS3 sensor. Also, verify that the internal pull-up resistors are enabled correctly.
  2. Check if the virtual I2C bus is recognized by your Raspberry Pi. You can use the i2cdetect command in the terminal to scan for connected I2C devices. Run the following command:
sudo i2cdetect -y <bus_number>
If the sensor is detected, it indicates that the virtual bus is working fine. In that case, the issue might be with the MATLAB/Simulink code you are using to read data from the sensor.
The `BUS_ERROR` message when using the i2cmasterread block from the Raspberry Pi Package, it could be caused by various factors.
1. Ensure that you have selected the correct bus number in the parameters of the i2cmasterread block. It should match the virtual bus number you are using.
2. Verify that the I2C address specified in the i2cmasterread block matches the address of the LSM6DS3 sensor.
3. Check if there are any other conflicting processes or software accessing the I2C bus. Make sure that you have exclusive access to the bus while reading data from the sensor.
Hope you find it helpful.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!