0

Trouble using two I2C sensors (TSL2591, BNO055) with Feather
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trouble using two I2C sensors (TSL2591, BNO055) with Feather

by Miniucnchew on Mon Feb 05, 2018 12:46 pm

Hello,

Just like the title says, I can't seem to use both the TSL2591 light sensor and BNO055 9DOF together. I'm using the Feather Bluefruit 32u4. Both sensors work separately, but when they are both on the same I2C bus they have some odd behavior. The program I wrote initializes both of the sensors with the assumption that they wouldn't conflict. So if I start the board and serial monitor with the TSL2591's SDA pin unplugged, the BNO055 works completely fine and prints out the serial statements that I programmed. But if it starts up with both sensors connected, nothing shows up on the serial monitor. I think the program is getting stuck in the "if(!bno.begin())" line. However, if I start up the board and s.monitor with the TSL SDA pin disconnected, and then connected it after the BNO055 starts writing, the TSL starts working and the BNO starts putting out nonsense values.

I checked their addresses and the TSL2591 uses 0x29 while the BNO055 uses 0x28. I think maybe the problem is that the BNO055 can use 0x29 (with a jumper from the ADDR pin to +V), so it might be reserving both addresses? Or maybe the BNO055 library is blocking that address? I've posted my program below. The exact same program worked with a TSL2561 and a LSM9DS0.

Thanks


Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_ATParser.h>
#include <Adafruit_BLE.h>
#include <Adafruit_BLEBattery.h>
#include <Adafruit_BLEEddystone.h>
#include <Adafruit_BLEGatt.h>
#include <Adafruit_BLEMIDI.h>
#include <Adafruit_BluefruitLE_SPI.h>
#include <Adafruit_BluefruitLE_UART.h>

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"

#include <SPI.h>
#include <Adafruit_BNO055.h>

// Initiate Light Sensor Class
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);

// Initiate Accellerometer Class
#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);




#define BUFSIZE                        128   // Size of the read buffer for incoming data
#define VERBOSE_MODE                   false  // If set to 'true' enables debug output

#define FACTORYRESET_ENABLE         0
#define MINIMUM_FIRMWARE_VERSION    "0.6.6"

#define BLUEFRUIT_HWSERIAL_NAME      Serial1
#define BLUEFRUIT_UART_MODE_PIN        -1    // Set to -1 if unused

#define BLUEFRUIT_SPI_CS               8
#define BLUEFRUIT_SPI_IRQ              7
#define BLUEFRUIT_SPI_RST              4    // Optional but recommended, set to -1 if unused


/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}




void configureLightSensor(void)
{
  // You can change the gain on the fly, to adapt to brighter/dimmer light situations
  //tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)
  tsl.setGain(TSL2591_GAIN_MED);      // 25x gain
  //tsl.setGain(TSL2591_GAIN_HIGH);   // 428x gain
 
  // Changing the integration time gives you a longer time over which to sense light
  // longer timelines are slower, but are good in very low light situtations!
  //tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // shortest integration time (bright light)
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
  tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS);  // longest integration time (dim light)
}


unsigned long time_0, time_next;

void setup() {

  time_0 = millis();
 
  Serial.begin(115200);
  configureLightSensor();

 
  /* Initialise the accellerometer*/
  if(!bno.begin())
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }


  sensor_t sensor;
  tsl.getSensor(&sensor);
 
  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );
  //bno.setExtCrystalUse(true);


 
  /* Disable command echo from Bluefruit */
  ble.echo(false);

  //Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  //ble.info();

  /* Change the device name to make it easier to find */
  Serial.println(F("Setting device name to 'Bluefruit Keyboard': "));
  if (! ble.sendCommandCheckOK(F( "AT+GAPDEVNAME=Bluefruit Keyboard" )) )
  {
    error(F("Could not set device name?"));
  }

  /* Enable HID Service */
  Serial.println(F("Enable HID Service (including Keyboard): "));
  if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
  {
    if ( !ble.sendCommandCheckOK(F( "AT+BleHIDEn=On" )))
    {
      error(F("Could not enable Keyboard"));
    }
  }
  else
  {
    if (! ble.sendCommandCheckOK(F( "AT+BleKeyboardEn=On"  )))
    {
      error(F("Could not enable Keyboard"));
    }
  }
}




float RMS_old = 0;
int fs = 1;
int count = 0;
float criterion;
float rms_crit = 0;
char* txt[] = {"Worn.     | 1 | \\n", "Not worn. | 0 | \\n"};

int sig = 0;
int long_term_move;


void loop() {

  // Possible vector values can be:
  // - VECTOR_ACCELEROMETER - m/s^2
  // - VECTOR_MAGNETOMETER  - uT
  // - VECTOR_GYROSCOPE     - rad/s
  // - VECTOR_EULER         - degrees
  // - VECTOR_LINEARACCEL   - m/s^2
  // - VECTOR_GRAVITY       - m/s^2
  imu::Vector<3> gravity = bno.getVector(Adafruit_BNO055::VECTOR_GRAVITY);
 
  sensors_event_t event;
 
  tsl.getEvent(&event);
  uint16_t lit = event.light;

  //bno.getEvent(&event);
 
  //uint16_t lit = tsl.getLuminosity(TSL2591_VISIBLE);

 
  float RMS_new = sqrt(pow(.1*gravity.x(),2)+pow(.1*gravity.y(),2)+pow(.8*gravity.z(),2));



  if (count%10 == 0)
  {
    if (rms_crit - 10*0.5 > 0.1) {long_term_move = 1;}
    else {long_term_move = 0;}
    rms_crit = 0;
  } else {
      rms_crit = rms_crit+RMS_old/(RMS_new+RMS_old);
  }
 
  criterion = 0.4*((lit <= 2) || (lit >=60000)) + 0.4*(RMS_new > 7 || RMS_new < 3.5) + 0.2*(long_term_move);

  Serial.println(criterion);

  if (round(criterion)) {
    Serial.print(count);
    Serial.print(" | Brace is being worn.     | 1 | ");
    Serial.print(lit); Serial.print(" | ");
    Serial.print(RMS_new); Serial.print(" | ");
    Serial.println(rms_crit-((count%10)-1)*0.5);
     
    sig = 0;
 
  } else {
    Serial.print(count); Serial.println(" | Brace is not being worn. | 0 | ");

   
    if (RMS_new < 6 && RMS_new > 4) { Serial.print("RMS is in unworn range (3.5 - 6) | "); Serial.println(RMS_new); }
    if (lit > 2) { Serial.print("Light sensor indicates not being worn: "); Serial.println(lit);}
    if (!long_term_move) { Serial.print("RMS didn't change enough | "); Serial.println(rms_crit-((count%10)-1)*0.5); }

    Serial.println("\n");

    sig = 1;
  }

  unsigned long time_stamp = round((millis() - time_0)/1000);


  ble.print("AT+BleKeyboard="); ble.print(TimeToString(time_stamp)); ble.print(" | ");
  ble.println(txt[sig]);

 
 
 
  if (!(ble.waitForOK()))
  {
    delay(100);
  }


  delay(200);
  RMS_old = RMS_new;
  count++;

  delay(fs * 1000);
}

// t is time in seconds = millis()/1000;
char * TimeToString(unsigned long t)
{
 static char str[12];
 long h = t / 3600;
 t = t % 3600;
 int m = t / 60;
 int s = t % 60;
 sprintf(str, "%04ld:%02d:%02d", h, m, s);
 return str;
}





Miniucnchew
 
Posts: 12
Joined: Tue Dec 15, 2015 4:20 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by franklin97355 on Mon Feb 05, 2018 1:30 pm

Can you post pictures of your boards and their connections? Files must be less than 1 meg in size.

franklin97355
 
Posts: 21077
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by Miniucnchew on Mon Feb 05, 2018 3:28 pm

Not at the moment because another team member is working on it, but I can tell you that I'm not using header, but rather long wire connections on a breadboard. I'm not using header because I will have to shove the circuit into a tiny box and I don't need all the pins. Could long wires be causing this?

Miniucnchew
 
Posts: 12
Joined: Tue Dec 15, 2015 4:20 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by franklin97355 on Mon Feb 05, 2018 5:30 pm

Data lines need solid connections to work correctly and wires through the holes is not enough. when I'm testing and don't want to commit to headers or pins I use mini clips like these.

franklin97355
 
Posts: 21077
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by Miniucnchew on Mon Feb 05, 2018 11:48 pm

20180205_223809.jpg
20180205_223809.jpg (85.19 KiB) Viewed 648 times


I've soldered the SCL and SDA connections and still nothing. The code is definitely getting stuck at "if (!bno.begin())". So for some reason the feather can't find the BNO055.

Miniucnchew
 
Posts: 12
Joined: Tue Dec 15, 2015 4:20 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by jps2000 on Tue Feb 06, 2018 1:25 am

wiring looks poor due to the long ground lines.
GND is not only for the supply but also for a bus important.
So connect GND from each board directly to feather.
Add pullup resistors of 2k2 or 4k7 from SDA and SCL to 3v3

jps2000
 
Posts: 449
Joined: Fri Jun 02, 2017 4:12 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by Miniucnchew on Tue Feb 06, 2018 3:59 pm

I soldered the ground connections and put 2k2 pullups on the SDA and SCL lines. Unfortunately, the feather still can't find the BNO055. Anything else to try? Maybe it's a problem with my code?

Miniucnchew
 
Posts: 12
Joined: Tue Dec 15, 2015 4:20 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by adafruit_support_bill on Tue Feb 06, 2018 4:03 pm

The additional pullups are not necessary. Both of those breakouts have pullups on-board.

What do you see when you run the i2c scanner?
Try with each breakout separately, then again with both connected.
https://playground.arduino.cc/Main/I2cScanner

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by Miniucnchew on Tue Feb 06, 2018 4:11 pm

With both connected, I see:


Scanning...
I2C device found at address 0x28 !
I2C device found at address 0x29 !
done


The overview page says that the feather bluefruit 32u4 doesn't have pullups on it's i2c lines.

Miniucnchew
 
Posts: 12
Joined: Tue Dec 15, 2015 4:20 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by adafruit_support_bill on Tue Feb 06, 2018 4:49 pm

With both connected, I see:


Scanning...
I2C device found at address 0x28 !
I2C device found at address 0x29 !
done

What do you see when you connect them one at a time?

The overview page says that the feather bluefruit 32u4 doesn't have pullups on it's i2c lines.

Not necessary, since both the BNO055 and the TSL2591 have 10K pullups giving you an effective 5K. Adding 2K to that would give you an effective 1.4K which probably too strong.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by Miniucnchew on Wed Feb 07, 2018 4:00 pm

It identifies each of them independently.

Miniucnchew
 
Posts: 12
Joined: Tue Dec 15, 2015 4:20 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by adafruit_support_bill on Wed Feb 07, 2018 4:53 pm

If the BNO055 is not responding to the 0x29, then it is not likely an addressing problem. It is possible that there are issues with the wiring and the signals on the bus are marginal. Please post a photo showing your revised wiring.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by jps2000 on Thu Feb 08, 2018 1:36 am

It may be that there is too much traffic on the bus that the bno can not finish its talk
Is the bus running at 400k?
What happen when you do not talk to TSL in the loop but only to BNO. ( of course with both devices connected)

jps2000
 
Posts: 449
Joined: Fri Jun 02, 2017 4:12 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by gammaburst on Thu Feb 08, 2018 12:27 pm

In my experiments with Feather and BNO055, I had to use unequal I2C pullup resistors such as 4.7K on SCL and 2.2K on SDA. That partially relieves a marginal I2C timing situation caused by the BNO055.

gammaburst
 
Posts: 428
Joined: Thu Dec 31, 2015 12:06 pm

Re: Trouble using two I2C sensors (TSL2591, BNO055) with Fea

by mrusme on Tue Jul 23, 2019 10:02 am

I seem to be experiencing the same issue on an Arduino MEGA2560 r3. I had the BNO055 connected with its default address (0x28) and it worked perfectly fine. Now I've added the TSL2591 to the I2C bus and suddenly the BNO055 cannot initialise anymore. Running the I2C scanner shows that both sensors (0x28, 0x29) are found.

I'm currently working with a breadboard in between the Arduino and the sensors, where I have ~30cm long cables running from the Arduino to the breadboard and then another 30cm of cable from the breadboard to the sensors. All cables are identical in length.

Is there any trick for getting this combination to work? Thanks everyone! :-)

mrusme
 
Posts: 2
Joined: Tue Jul 23, 2019 9:56 am

Please be positive and constructive with your questions and comments.