Hi all,
I'm facing a new issue which I do no understand.
On a Arduino mega 2560, I got 4 things connected:
- 3 BNO055 in i2c, each of them has the same i2c addresse 0x28
- 1 i2c multiplexer (TCA9548A)
I got two pieces of codes to check them.
A first one here, scanning i2c address on the different ports of the multiplexer:
/**
* TCA9548 I2CScanner.pde -- I2C bus scanner for Arduino
*
* Based on code c. 2009, Tod E. Kurt, http://todbot.com/blog/
*
*/
#include "Wire.h"
extern "C" {
#include "utility/twi.h" // from Wire library, so we can do bus scanning
}
int i = 0;
#define TCAADDR 0x70
void tcaselect(uint8_t i)
{
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
// standard Arduino setup()
void setup()
{
while (!Serial);
delay(1000);
Wire.begin();
Serial.begin(115200);
Serial.println("\nTCAScanner ready!");
scanIMUs();
Serial.println("\ndone");
}
void loop()
{
Serial.println("\nTCAScanner ready!");
scanIMUs();
Serial.println("\ndone");
delay(1000);
i++;
Serial.println(i);
}
void scanIMUs()
{
for (uint8_t t=0; t<8; t++)
{
tcaselect(t);
Serial.print("TCA Port #"); Serial.println(t);
for (uint8_t addr = 0; addr<=127; addr++)
{
if (addr == TCAADDR) continue;
uint8_t data;
if (! twi_writeTo(addr, &data, 0, 1, 1))
{
Serial.print("Found I2C 0x"); Serial.println(addr,HEX);
}
}
}
}
Which is able to check, for at least 6080 runs that the three IMUs are conencted to port 0,1 and 2 of the multiplexer (See 6080 successfullruns.png).
Another code, doing the same but with something extra: conenction to the IMUs once the adresse has been found.
/**
* TCA9548 I2CScanner.pde -- I2C bus scanner for Arduino
*
* Based on code c. 2009, Tod E. Kurt, http://todbot.com/blog/
*
*/
#include "Wire.h"
extern "C" {
#include "utility/twi.h" // from Wire library, so we can do bus scanning
}
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#define TCAADDR 0x70
Adafruit_BNO055 bno1 = Adafruit_BNO055(55);
Adafruit_BNO055 bno2 = Adafruit_BNO055(55);
Adafruit_BNO055 bno3 = Adafruit_BNO055(55);
int i = 0;
void tcaselect(uint8_t i)
{
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
// standard Arduino setup()
void setup()
{
while (!Serial);
delay(1000);
Wire.begin();
Serial.begin(115200);
Serial.println("\nTCAScanner ready!");
scanIMUs();
tcaselect(2);
delay(1000);
bno1.begin();
if (!bno1.begin())
{
Serial.println("BNO055 1 not detected");
}
else
{
Serial.println("BNO055 1 detected");
}
tcaselect(1);
delay(1000);
bno2.begin();
if (!bno2.begin())
{
Serial.println("BNO055 2 not detected");
}
else
{
Serial.println("BNO055 2 detected");
}
tcaselect(0);
delay(1000);
bno3.begin();
if (!bno3.begin())
{
Serial.println("BNO055 3 not detected");
}
else
{
Serial.println("BNO055 3 detected");
}
Serial.println("\ndone");
}
void loop()
{
scanIMUs();
tcaselect(2);
delay(1000);
bno1.begin();
if (!bno1.begin())
{
Serial.println("BNO055 1 not detected");
}
else
{
Serial.println("BNO055 1 detected");
}
tcaselect(1);
delay(1000);
bno2.begin();
if (!bno2.begin())
{
Serial.println("BNO055 2 not detected");
}
else
{
Serial.println("BNO055 2 detected");
}
tcaselect(0);
delay(1000);
bno3.begin();
if (!bno3.begin())
{
Serial.println("BNO055 3 not detected");
}
else
{
Serial.println("BNO055 3 detected");
}
Serial.println("\ndone");
i++;
Serial.println(i);
Serial.println("");
}
void scanIMUs()
{
for (uint8_t t=0; t<8; t++)
{
tcaselect(t);
Serial.print("TCA Port #"); Serial.println(t);
for (uint8_t addr = 0; addr<=127; addr++)
{
if (addr == TCAADDR) continue;
uint8_t data;
if (! twi_writeTo(addr, &data, 0, 1, 1))
{
Serial.print("Found I2C 0x"); Serial.println(addr,HEX);
}
}
}
}
This code shows an eratic behaviour (part 1 and part 2.png):
- From the start, the three 0x28 are detected
- Then, I tried to connect to the IMUs:
- 2a. At the start, no conenction is possible
- 2b. Everytime I press the reset button of the arduino, I'm loosing a 0x28
- 2c. When I unplug and replug the 5V pin supplying the multiplexer and the IMUs, I can find all of them and the connection are working for a single run.
I was first guessing this behavior was due to few poor connection on the classical white female pins board. I bought PCB board, solder everything together and the problem still remains.
Having the three IMUs connected with bno.begin tells me the Imus are fine.
Having some eratic connections with the IMUs (even when reset and +5v are pushed or disccoencted) leads to first hypothesis: it seems to the be a software issues, maybe IMUs should be disconnected once used of the TCA port msut be closed, I do not know.
I'm really lost to find the solution. Signal looks ratehr fine with the scope.
Any idea how to solve this issue or test to perform?
Kind regards