Hi all, I am trying to interface 2x BMI088 modules using I2C.
Firstly when I use the i2c scanner, all 4 addresses are detected (2x gyro at 0x68 and 0x69, 2x accelerometer at 0x18 and 0x19). The addresses are changed by pulling high or low the ADO pin.
However when I run my program, and connect 2 sensors, the serial monitor shows no output. When I comment out the second sensor, I can see readings for one sensor (when altering the address in the code and the wiring of ADO accordingly, I can see readings for both sets of addresses). Similarly when I comment out the first sensor, I can see readings for one sensor even when changing the addresses in the code.
If anyone has any idea what conflict could potentially be the issue that would be greatly appreciated. Thanks
Can you tell what you have in front of you ? Which Arduino board, the bare BMI088 sensor chips or a module, and which module ? Do you have pullup resistors ?
If a I2C Scanner finds the chips, that means that (almost) everything is working.
I checked that library, and nothing bad got my attention, I think it is a good library. It should work with multiple sensors.
Your sketch is according to the example, all good as well.
You could add a Serial.println() to setup(), then you know a little more.
void setup()
{
int status;
/* USB Serial to print data */
Serial.begin(115200);
while(!Serial) {}
Serial.println("The sketch has started"); // <---- added
The library runs at 400kHz I2C speed, and the I2C Scanner runs at 100kHz.
The 400kHz is hard coded in the library. You could try to change that in the library to 100kHz for both the accelerometer and the gyro.
If you have a voltage mismatch on the I2C bus (5V Arduino board with 3.3V sensor) or if pullup resistors are missing, then it is normal that it works a little at 100kHz and not at 400kHz. If you use a breadboard and jumper wires, then expect this kind of trouble. Breadboards have bad contacts and jumper wires can be broken. Can you measure the 5V and 3.3V in your project ?
I have an Arduino Uno and 2x of the Seed Studio boards (Grove - 6-Axis Accelerometer&Gyroscope(BMI088) - Seeed Wiki). No pull ups, simply wires between SDA, SCL, GND and VCC. I have made solder bridges on both sensors to alter the addresses accordingly.
The i2c scanner gives me all 4 addresses as per the datasheet. That's why I am confused.
I'll check the setup println() and library running speeds. I am using a breadboard to merge the wiring to each, I have some cable connectors which may sort this. Thanks
The Serial.println() puts the text into a buffer and the text is transmitted in a interrupt. That means that the sketch continues while the interrupt is outputting the text.
It is not really confusing, there are still a number of possibilities that makes it work with the I2C Scanner and not with the library. The I2C bus is not a fault tolerant bus, it should work 100% or else it is a total fail.
Thanks for the link, they even provide a schematic.
This is the I2C level shifter on the Grove module:
You can use the module with a Arduino Uno board (which is a 5V board).
Because of the onboard I2C level shifter, there are also pullup resistors on the board. I put blue circles around them.
Can you show a photo ?
The VCC of the Grove module should be connected to the 5V pin of the Arduino Uno, otherwise the level shifters don't work.
Do you have a multimeter ? Can you get one ? I'm very curious about the 5V and 3.3V in your project.
There is something that I have not mentioned yet: The sensor could be a counterfeit, that only works in a very small margin of voltages and speed. However, I expect that good wires, good connections on the breadboard, good voltages, good I2C speed, will fix the problem.
I have checked the datasheet. All looks okay with it in terms of addressing etc.
Attached is a photo of the setup (apologies for the bad quality if so).
I have measured the voltage across the breadboard rails and its 4.98V. Similarly, both sensors read 4.98V across both VCC and SCL to GND. SDA to GND is 160mV roughly.
I have edited the BMI088.h file, changing the library i2c speed to 100kHz also, with no change in the serial monitor output.
Thanks for the photo.
You have SDA next to SCL in a cable. That is not okay. The I2C bus can not deal with crosstalk between SDA and SCL.
Since your sensors do not fit in the photo, they might be miles away
Use short wires to the sensor modules, about 20 cm. Split the wires. Use single separate wires. Do not use wires/cables that have SDA next to SCL.
The I2C bus is not the "bus" you think it is. It is not that kind of bus. The I2C signals are not supposed to go somewhere, and the I2C bus is not designed to go through a cable.
How far away are the sensors in your final version of the project ?
Could you read page 54 of the official I2C standard, document UM10204.pdf: UM10204.pdf at Pololu. Paragraph 7.5 "Wiring pattern of the bus lines". Never put SDA next to SCL.
The 10 cm is all they give you ! Beyond that, you must take care that SDA is not next to SCL.
In your project, you can have SDA next to SCL for 5cm to one sensor and 5cm to the other sensor.
A level shifter solves problems with voltage levels, but also makes the signal weaker. I give you 4 cm.
If you do everything right, then 50 cm is easy to reach, and 2 meters is possible for the I2C bus.
The main 4-way cable I am using between the sensor and breadboard came with the sensor and is simply plugged into a connector. They are around 20cm long. In the project, the sensors will be around 15cm apart and will be wired independently to a main PCB with connectors.
Thanks for the official i2c document, I will bare this in mind when designing future custom revisions of the PCB, adhering to the 10+cm suggestions.