Using 2 IMUs on 1 Arduino Mega

Hi there, I am working on a project that requires the usage of 2 IMUs.

My IMU is BNO055 from Adafruit.

From what I understand, IMUs need to be connected to the SDA and SCL port for it to function.

The Arduino Mega itself has Port 20 and 21 as SDA and SCL respectively, and in addition, the two unlabeled ports above AREF are also SDA and SCL.

I tried the Sensor Test coding provided for by Adafruit at Arduino Code | Adafruit BNO055 Absolute Orientation Sensor | Adafruit Learning System

And it worked when I used either Port 20 and 21 or the two unlabeled ports.

However, I cannot figure out how to code it such that I can get 2 readings from the 2 IMU simultaneously.

From the test coding they provided, it does not seem like they specified which ports they asked the program to read from.


void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);

/* Display the floating point data */
Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
Serial.println("");

delay(100);
}

Any help would be appreciated.

Thank you!

I think what I really need to know is how to allocate which port I would like Arduino to read the IMUs from, since if that is possible, then I could get readings from the 2 IMUs from 2 different port pairs.

"The Arduino Mega itself has Port 20 and 21 as SDA and SCL respectively, and in addition, the two unlabeled ports above AREF are also SDA and SCL."
They are the same pins.

Does BNO055 have an Address select pin? Set it high for one device, low for other, and then you use two different I2C addresses to talk to them one at a time.

See page 91 of the datasheet for the base address to use for each device:
"4.6 I2C Protocol
The I²C bus uses SCL (= SCx pin, serial clock) and SDA (= SDx pin, serial data input and
output) signal lines. Both lines are connected to VDDIO externally via pull-up resistors so that
they are pulled high when the bus is free.
The I²C interface of the BNO055 is compatible with the I²C Specification UM10204 Rev. 03
(19 June 2007), available at http://www.nxp.com. The BNO055 supports I²C standard mode
and fast mode, only 7-bit address mode is supported. The BNO055 I²C interface uses clock
stretching.

The default I²C address of the BNO055 device is 0101001b (0x29). The alternative address
0101000b (0x28), in I2C mode the input pin COM3 can be used to select between the
primary and alternative I2C address as shown in Table 4-7."
https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST_BNO055_DS000_14.pdf

Thank you! I tried reading it, and it got me somewhere.

So now I managed to get the Arduino to read from 2 different IMUs, but the intervals between the changes were kind of unpredictable.

I couldn't figure out when the Arduino would read from which IMU.

The current coding is like


while (q < 2)
{
digitalWrite (7, HIGH);
digitalWrite (9, LOW);

Serial.print ("IMU A");
Serial.println("");
Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
Serial.println("");

delay(500);

q++;
}

while (y < 5)
{
digitalWrite (7, LOW);
digitalWrite (9, HIGH);

Serial.print ("IMU B");
Serial.println("");
Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
Serial.println("");

delay(500);

y++;
}

What I tried was to let one turn off while the other is on, alternatingly. However it is not switching with each instance.

I think right now the problem is with the coding rather than the physical set up.

I am not quite certain how else I should proceed with the coding, since I could not figure a way to request Arduino to Serial.print an orientation from a specific IMU.

Post your full code please. You need to initialise 2 BNO055 instances with 0x28 and 0x29 as their addresses. Set 1 sensor's ADR pin to high and the other's to low.