0

Feather M0 adalogger with BNo055 trouble.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M0 adalogger with BNo055 trouble.

by Wrenchesinthegears on Sun Feb 17, 2019 12:14 am

Hi guys,

I havn't posted on here before. So first of all, my name is Alex and I am a bit of a newby when it comes to electronics so please bare with me.

I have a Feather M0 adalogger, which I have had working logging analogue sensor data to the SD card which is great.

I am trying to build a logger that can log data from a BNo055 (adafruit breakout) as well as other analogue data.

I am currently just trying to get the BNo working with the feather and post data to the serial before I bother logging it but am having troubles.

I can't get the sensor to initialise. When it gets to the if (!bno.begin()) statement the program seams to hang, no updates on Serial after this.

I have the sensor wired with Vin attached to 3V out of the Feather M0, both grounds of the Feather attached to ground on the sensor. SCL to SCL, SDA to SDA.

I have tried adding extra pullup resistors on SDA and SCL (Tried both 10k, also tried each with 3k and 2k and visa versa) but this has not changed anything. When doing this i also add a wire from 3vo on the sensor to the 3v from the feather (tried with and without this).

Please forgive my messy code. I have tried to just take everything I need from the bno example codes to get it up and running.

Any help would be really appreciated.
Code: Select all | TOGGLE FULL SIZE
//BNo055 test/practise
// Based on Logger_A4

// Include libraries - For SD Card Comms
#include <SPI.h> // Used to communicate to SD card?
#include <SD.h> // A higher level sd library which also adds SdFat library.

// These libs for BNO055
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

// Define the on board LED pins as boardLED (red) and SDLED(green)
int boardLED = 13;
int SDLED = 8;

//BNO055 Sensor Vars
Adafruit_BNO055 bno = Adafruit_BNO055(55); // Initialiser
#define BNO055_SAMPLERATE_DELAY_MS (10); // Defines BNO055 sample rate (10 ms = 100 Hz)
sensors_event_t event; // Not sure what this does yet, some adafruit code puts this direct in the loop before each getEvent...

// Data logging Vars
File dataFile; // Declare a data file variable (class?)
String dataString; // Declare the dataString which will be built and written to SD.
String header; // Declare the header string (names of sensors for csv)


// Set up variables for the SD card.
// These classes are from the SdFat library I think.
Sd2Card card; // Needed for cardInfo
SdVolume volume; // Needed for cardInfo
SdFile root; // Needed for cardInfo I think.
const int chipSelect = 4; // Define the CS (chipselect) pin for the SD card, on the Feather M0 adalogger this is pin 4.

//------------------SETUP-------------------------------------------------------
// Run Once Code
void setup() {
  // Define the header for the CSV/txt output
  header = "time start,sensor 1,sensor 2,sensor 3,sensor 4,time end";
 
  pinMode(boardLED, OUTPUT); //Initialise the board LED
  pinMode(SDLED, OUTPUT); //Initialise the green board LED
 
  Serial.begin(9600); // Connect to serial for debugging purposes.
  while (!Serial) {
  // This makes the program wait until the Serial moniter is opened I think? 
  }
 
  //cardInfo(); // Runs the cardInfo function.. prints some stuff to serial and checks if SD card is around. pauses program if it isnt.

  SD.begin(chipSelect); // This line is needed to initialise the card for writing to.
  // Open data file
  dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(header);
    // dataFile.close(); //Save the file
    // print to the serial port too:
    Serial.println("Wrote to Card: ");
    Serial.print(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening file");
    digitalWrite(SDLED, HIGH);
  }
  Serial.println("reached just before bno if statement");  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<This is the last line I get on the serial, nothing after this so I'm assuming the next line is where it hangs.
 
  if(!bno.begin()) {
    Serial.println("No BNO detected");
    hangAndFlash(100);
  }
  delay(1000);
  Serial.println("verified bno");
  bno.setExtCrystalUse(true);

 
  flashLED(10, 200);

  Serial.println("Last line of Setup function");
}

//------------------LOOP--------------------------------------------------------
void loop() {
  delay(1);
  //sensors_event_t event;
  // Make a data string for assembling each line of data to log.
  dataString = "";
  Serial.println("X: ");
  bno.getEvent(&event);
  Serial.println("X: ");
  Serial.println(event.orientation.x, 4);
  Serial.println("Y: ");
  Serial.println(event.orientation.y, 4);
  Serial.println("Z: ");
  Serial.println(event.orientation.z, 4);
  delay(100);
  // Build the string
  dataString += millis(); // Time stamp start
  dataString += ",";
  dataString += analogRead(15); // Sensor 1
  dataString += ",";
  dataString += analogRead(16); // Sensor 2
  dataString += ",";
  dataString += analogRead(17); // Sensor 3
  dataString += ",";
  dataString += "sensor 4"; // Sensor 4
  dataString += ",";
  dataString += millis(); // Time stamp end
 
  //Serial.println(header);
  //Serial.println(dataString);
  if (millis() < 30000) {
 
    //dataFile = SD.open("datalog.txt", FILE_WRITE);
    // if the file is available, write to it:
    if (dataFile) {
      dataFile.println(dataString);
    } 
  } else {
    dataFile.close();
    //hangAndFlash(100);
  }
}
Attachments
52601904_359791938192262_3305186838481731584_n.jpg
52601904_359791938192262_3305186838481731584_n.jpg (34.13 KiB) Viewed 71 times
Last edited by franklin97355 on Sun Feb 17, 2019 1:00 am, edited 1 time in total.
Reason: Please use code tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the code button above the reply box and past your code between the tags created.

Wrenchesinthegears
 
Posts: 4
Joined: Sun Feb 17, 2019 12:03 am

Re: Feather M0 adalogger with BNo055 trouble.

by franklin97355 on Sun Feb 17, 2019 1:08 am

The picture is a bit small but everything looks to be wired OK. Take a look at this lesson and try the code there. Also, you might try moving your boards to a different spot on the breadboard as sometimes the sockets don't make good contact.

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

Re: Feather M0 adalogger with BNo055 trouble.

by Wrenchesinthegears on Sun Feb 17, 2019 3:07 am

Hi Franklin, thanks for fixing up my post.

I have now re-wired it on the other side of the breadboard to check the connections to no avail.

I have tried the example code, and just tried it again. Strangly enough I don't even get Serial comms with the example code. As in I don't even see "Orientation Sensor Test" pop up in the Serial moniter. I even tried removing the bno055 all together and still don't get this.

Code:
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
 
Adafruit_BNO055 bno = Adafruit_BNO055(55);
 
void setup(void)
{
  Serial.begin(9600);
  Serial.println("Orientation Sensor Test"); Serial.println("");
 
  /* Initialise the sensor */
  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);
  }
 
  delay(1000);
   
  bno.setExtCrystalUse(true);
}
 
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);
}


Edit: I added a while (!Serial) before the Serial print and now it does post the "Orentation Sensor Test" to the serial moniter, but then thats it.....

Even with the BNO completly removed it just hangs. Surely it should come up with "Ooops, no BNO055 detected... etc etc" on the Serial moniter when ive got nothing even connected to SDA and SCL?

I'm wondering if tis an issue with my libraries or somthing but I have installed the libraries as required by the M0 and by the BNo.

Wrenchesinthegears
 
Posts: 4
Joined: Sun Feb 17, 2019 12:03 am

Re: Feather M0 adalogger with BNo055 trouble.

by Wrenchesinthegears on Sun Feb 17, 2019 4:18 am

As a test I tried this Arduino I2C scanner code and it worked https://playground.arduino.cc/Main/I2cScanner , returning a device on 0x28 as expected.

Still having trouble as above with the other codes though.

Wrenchesinthegears
 
Posts: 4
Joined: Sun Feb 17, 2019 12:03 am

Re: Feather M0 adalogger with BNo055 trouble.

by Wrenchesinthegears on Tue Feb 19, 2019 3:02 am

I got this working.

Firstly, it seamed my libraries were not installed properly, as i tried the code without connections on arduino mega, which also didn't work until I reinstalled libraries.

Then retrying the feather I had the same issues.

Eventually found I Had to delete a line in the BNO055 library (line 283 or so i think), which was an error warning that comes up for feather or arduino zero automatically.
Not sure why. Is it because the feather uses i2c address 0x28 on board and its reserved?

Anyway, deleting this line of code and changing my bno055 i2c address by pulling the adr pin high made it all work together.

I'm now able to log at 100Hz (just).

Wrenchesinthegears
 
Posts: 4
Joined: Sun Feb 17, 2019 12:03 am

Please be positive and constructive with your questions and comments.