Feather M0 WiFi Data Stream

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Colin_H
 
Posts: 11
Joined: Sun May 15, 2016 3:53 pm

Feather M0 WiFi Data Stream

Post by Colin_H »

Hello,

I recently purchased the Adafruit BNO055 orientation sensor breakout and feather M0 WiFi development board to stream the orientation data in real time to my computer. So far I have successfully received the data on my computer when both my computer and the feather board are connected to my home WiFi network as well when my computer is connected directly to the feather board's access point, which is the end goal.

Right now I am streaming every 10 ms to get a decent feel for the time derivative of the orientation readings, so I figured UDP made more sense due to its reduced overhead. If this application is more appropriately suited by the use of TCP or maybe a combination of the two, I am all ears.

While I am excited about the progress, I have been experiencing some inconsistency in the reliability of the connection. Particularly, if I disconnect my computer or it goes to sleep, I am unable to reconnect to the feather's WiFi access point, or it will say that I am connected but no UDP packets come through. I have also noticed that the UDP packets will sometimes just stop transmitting from the board when my computer is still awake and connected. In both cases, I have to power cycle the board or re-upload the code to reconnect and start receiving data again. In some of my test programs not using the networking feature, I noticed the serial output in the Arduino IDE would sometimes lock up and stop printing, but I am not sure what to make of that as I am unable to consistently reproduce the behavior.

I am fairly familiar with networking concepts but am not as comfortable with what goes into establishing and maintaining a WiFi connection. Is there some advanced setting on my computer or on the feather board's ATWINC1500 chip that I am missing that may explain this behavior or is something wrong with my approach or maybe the feather board? I have been powering it through the micro usb jack with the same symptoms as when running it off of an alternative power source.

I can send my code over if it would help give you a sense of my direction for the project.

Thank You!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather M0 WiFi Data Stream

Post by adafruit_support_mike »

Wifi connections are much more vulnerable to noise and interference than wired connections. It isn't a question of if the connection will drop, but when.

Use the .checkConnected() method to see how the radio-level link is doing, and add some fallback code to re-establish the connection when it drops.

User avatar
Colin_H
 
Posts: 11
Joined: Sun May 15, 2016 3:53 pm

Re: Feather M0 WiFi Data Stream

Post by Colin_H »

Thank you for the feedback! I have implemented some fail safes using the status method in the WINC1500 library where I attempt to reconnect to bring the AP back up to no avail. Would interference cause the feed to drop completely or just drop a few packets here and there? I used a Raspberry Pi with a usb WiFi dongle for a similar project and was able to reliably retrieve data at the same rates without anything disconnecting in the same WiFi environment. I purchased the u.fl model of the feather board hoping that the signal would be less prone to interference than the chip antenna, but it still seems to happen when I move out of range of other WiFi networks. I also noticed that my operating system (Mac OS X Sierra) will still indicate that it is connected to the board's access point even when the board is powered down and the signal couldn't possibly be live, so I am not sure if there is some WiFi connection process at fault there as well.

If there are any better ways to get a more reliable wireless data stream to a computer, I would love to hear any suggestions you have. I came across your BNO055 iOS bluetooth stream tutorial but was hoping to get more range than what bluetooth can offer. I was also reading through your Adafruit IO tutorials but that does not seem appropriate for a real time data feed at the frequency I need.

In any case, my feather board has behaved more erratically than my Arduino Mega and Uno boards, so I just want to make sure there is not some problem with the board in play here before I did too deeply into the interference issue. Specifically, it takes much longer to upload code to the feather board, the code uploads sometimes fail, and the serial output to the Arduino IDE will frequently freeze.

Thank You!

User avatar
Colin_H
 
Posts: 11
Joined: Sun May 15, 2016 3:53 pm

Re: Feather M0 WiFi Data Stream

Post by Colin_H »

I also noticed that the ATWINC1500 supports peer to peer mode. Would it be more reliable to connect my computer and board using peer to peer than setting up the access point?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather M0 WiFi Data Stream

Post by adafruit_support_mike »

Having the connection drop at the radio level is equivalent to unplugging an Ethernet cable.. you lose all communication and don't get anything until you reconnect and reconfigure the network interface.

Beyond that, there's nothing specific I can say about error prevention and link management. Do as much debugging as you can to figure out what's happening when the connections drop, and see if you can find any common factors that could be prevented or mitigated.

User avatar
Colin_H
 
Posts: 11
Joined: Sun May 15, 2016 3:53 pm

Re: Feather M0 WiFi Data Stream

Post by Colin_H »

Through further debugging, I have come to suspect my connection loss is actually due to my feather board freezing up when reading data from the BNO055 over i2c. I thought the BNO055 itself may be locked up, so I ran a few "freeze tests" where I just poll the BNO055 registers as fast as possible in a tight loop. Sure enough, the feather's serial output froze, and the board become unresponsive until I re-uploaded the code. I ran similar tests where I repeatedly just sent UDP packets over WiFi, and the connection does not seem to drop, even when I move the board around a lot and throw it in the air!

I ran a series of different tests to figure out when exactly things, and one key trigger I observed in a variety of cases (i.e. different sample times and burst lengths) is that the introduction of motion to a stationary board seems to lock things up. This leaves me to believe that the BNO055's filtering may be getting held up and can not handle the constant requests for new values, but I am not sure what to make of it because the advertised data output rate of the filter is 100 hz.

I ran the same tests on my Arduino Mega and was unable to freeze the board up, however. Even when repeatedly polling 30 registers in a tight loop, I can not get the Mega to freeze up like the feather did. In combing through the Adafruit_WINC1500 library, I noticed that the key i2c functions do not check for errors (there is a todo comment in the current branch), so I am not sure if there is some i2c timeout I should account for with the Wire.read() function. I know the BNO055 uses clock stretching, so could this potentially be the culprit? I thought I had read that the feather M0 board supports it, but I am too sure now after re-reading the data sheet. The BNO055's data sheet does not offer much detail on the clock stretching other than that it uses it, so I am not sure if the clock is more likely to get stretched during rapid movement or any other time my code seems to freeze up.

I am not married to the feather board I purchased and may just try an ATWINC breakout for my mega board since it seems to work, but I am curious to hear what you make of my observations. I know UART communication with the BNO055 is also an option.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather M0 WiFi Data Stream

Post by adafruit_support_mike »

The M0 supports clock stretching, so that shouldn't cause the board to lock up. It's possible that you're seeing interaction between the BNO055's timing and the Wifi code though.

Does the code freeze inside a library call, or in something like a loop in your main code that polls the BNO055 for data?

User avatar
Colin_H
 
Posts: 11
Joined: Sun May 15, 2016 3:53 pm

Re: Feather M0 WiFi Data Stream

Post by Colin_H »

I also thought there may be some interaction, but my "freeze tests" are actually just requesting data from the BNO055 in a tight loop without engaging that ATWINC at all. Unless the ATWINC can still affect the i2c communications even when I am not using it.... I do not have any other i2c devices in my circuit, so I am not sure what additional interactions could be at play. I ran similar code with just the ATWINC and was unable to freeze the board after repeatedly sending UDP packets in a tight loop with no delays, so I am more suspicious of the BNO055 i2c communications.

In any case, I put a bunch of print statements inside the readLen function of the Adafruit_BNO055 library. I was able to freeze the board 6 times, 3 in my full code and 3 in my "freeze tests" involving just the BNO055, and each time the code gets stuck on the Wire.requestFrom() method. I have tried both true and false as the optional third arguments to no avail. Let me know if this leads you to suspect anything else!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather M0 WiFi Data Stream

Post by adafruit_support_mike »

Post the code you're using for the test (between CODE tags please) and we'll take a look.

User avatar
Colin_H
 
Posts: 11
Joined: Sun May 15, 2016 3:53 pm

Re: Feather M0 WiFi Data Stream

Post by Colin_H »

The code is below. I just updated my Arduino IDE and libraries to no avail. It is still difficult to pinpoint when it happens. I have run it a few times where it will not freeze, and then other times when it freezes within a few seconds. One thing I have not tried yet is trying the code on my feather board with another BNO055 sensor. Let me know what you think!

Code: Select all

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

/* 
 *  BNO055_freeze_test - repeatedly reads registers from the BNO055 orientation sensor over i2c
 *    for debugging purposes. The Feather M0 WiFi board has been freezing up when reading 
 *    form the  orientation sensor, the hope is to get more detail on when this is happening. 
 *    Most of the setup was copied from the raw_data example in the Adafruit_BNO055 library.
*/

/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (10)
Adafruit_BNO055 bno = Adafruit_BNO055();

/**************************************************************************/
/*
    Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void)
{
  // Feather board needs some more time
  while (!Serial);
  delay(1000);
  Serial.begin(9600);
  Serial.println("Orientation Sensor Raw Data 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);

  /* Display the current temperature */
  int8_t temp = bno.getTemp();
  Serial.print("Current Temperature: ");
  Serial.print(temp);
  Serial.println(" C");
  Serial.println("");

  bno.setExtCrystalUse(true);

  Serial.println("Calibration status values: 0=uncalibrated, 3=fully calibrated");
}

/**************************************************************************/
/*
    Arduino loop function, called once 'setup' is complete (your own code
    should go here)
*/
/**************************************************************************/
void loop(void)
{
  // the call to getVector will eventually freeze the board up
  // the guilty party appears to be the Wire.requestFrom method inside the readLen
  //  method of the Adafruit_BNO055 class
  // the end application requires these 5 vectors be read, even though they are not
  //  used explicitly in this test
  imu::Vector<3> accel = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  imu::Vector<3> gyro= bno.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
  imu::Vector<3> linAccel = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
  imu::Vector<3> gravity = bno.getVector(Adafruit_BNO055::VECTOR_GRAVITY);

  // serial output helps us figure out when the board froze
  Serial.print("heading: "); Serial.print(euler.x());
  Serial.print(", gravity: "); Serial.println(gravity.z());

  // experiment with different delays to see when the board will freeze
  delay(BNO055_SAMPLERATE_DELAY_MS);
}

User avatar
Helitronix
 
Posts: 7
Joined: Wed Apr 15, 2009 10:01 pm

Re: Feather M0 WiFi Data Stream

Post by Helitronix »

Was there any resolution to this issue? I am experiencing something similar.

In my case, I have connected 3 x BN055 to a Feather M0 via the TCA9548A I2C Multiplexer and am experiencing lockups with the I2C transfers as well. The code executes properly for a short while, anywhere between 30 seconds and several minutes before it fails. I'm only one evening into debugging this problem, so I don't have more data to share just yet.

If anyone has any ideas, I'd really like to hear them.

Joel

User avatar
plc_gremlin
 
Posts: 23
Joined: Mon Jul 09, 2012 12:34 pm

Re: Feather M0 WiFi Data Stream

Post by plc_gremlin »

I am experiencing a similar problem.
BNO055 connected to a Teensy 3.2. It definitively seems to be an I2C comms issue will cause the Teensy to completely lock up. I am just running the example code.
In my case, I can stream values to Serial for long periods but when I touch the board with my hand while moving it, the Serial Stream will freeze(teensy locks up) and only a power reset will resolve.
It could be related to all the weak pullup resistor issues and too tight I2C timing that people have posted about. Overall, I'm fairly disappointed in the BNO055 breakout.
I really only need a reliable magnetometer so will be looking for a different solution most likely..

User avatar
gammaburst
 
Posts: 1015
Joined: Thu Dec 31, 2015 12:06 pm

Re: Feather M0 WiFi Data Stream

Post by gammaburst »

The BNO055 designers apparently forgot to include a delay between SDA rise and SCL rise at the end of the clock-stretching cycle. That causes a tight timing situation, almost violating their own data sheet timing requirement. If you touch those signals with your finger, and if your finger capacitance slows the risetime of SDA significantly more than SCL, then communication fails. Some microcontrollers have weak default I2C pullups, and can't talk to the BNO at all without some help. To partially improve the situation, I install additional pullup resistors, such as 2.2K on SDA and 4.7K on SCL.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”