0

BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 combinat
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 combinat

by MCGEngineer on Tue Nov 06, 2018 4:58 pm

Hello,
In the past, I used the Blend Micro with the Adafruit 9DOF and didn't experience any of the following issues (which I have now experienced using just about every variation I can come up with). I don't see any record of the issues in the forums, so hopefully it's fixable.
Here goes: I'm using the Feather 32u4 in combination with the LSM9DS1 with an essentially unmodified version of the Bluefruitle example from https://github.com/don/cordova-plugin-ble-central/tree/master/examples/bluefruitle - the only change I've made to index.js is substituting the following lines in the onData function:
Code: Select all | TOGGLE FULL SIZE
onData: function(data) { // data received from Arduino
        console.log(data);       
        var myData = new Uint8Array(data);
        var xData = myData[0];
        var yData = myData[1];
        var zData = myData[2];       
        resultDiv.innerHTML = resultDiv.innerHTML + "Received: " + xData + ", "  + yData + ", " + zData + ", "+ "<br/>";       
        resultDiv.scrollTop = resultDiv.scrollHeight;
    },

All I'm doing in my test version is sending gyro data via a pretty bare-bones modification of the demo app, using i2c, with the SCL/SDA/Vin/Gnd holes on the LSM9DS1 connected to the Feather:
Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include <SPI.h>

#if not defined (_VARIANT_ARDUINO_DUE_X_) && not defined (_VARIANT_ARDUINO_ZERO_)
#include <SoftwareSerial.h>
#endif

#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
//#include "Adafruit_BluefruitLE_UART.h"
#include "BluefruitConfig.h"

#include <Adafruit_LSM9DS1.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!

// i2c
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1();

#define DIGITAL_IN_PIN     5

#define FACTORYRESET_ENABLE         1
#define MINIMUM_FIRMWARE_VERSION    "0.6.6"
#define MODE_LED_BEHAVIOR           "MODE"
#define BLUEFRUIT_HWSERIAL_NAME     Serial1

Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

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

float gyroRawMin, gyroRawMax;
float gyroMin = 0, gyroMax = 127.5;


void setupSensor()
{
  // 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_2G);

  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS1_MAGGAIN_4GAUSS);

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_245DPS);

  gyroRawMin = -287;
  gyroRawMax = 287;

}

void setup()
{
  Serial.begin(115200);

  if (!lsm.begin())
  {
    Serial.println("Oops ... unable to initialize the LSM9DS1. Check your wiring!");
    while (1);
  }

  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in Command mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    /* Perform a factory reset to make sure everything is in a known state */
    Serial.println(F("Performing a factory reset: "));
    if ( ! ble.factoryReset() ) {
      error(F("Couldn't factory reset"));
    }
  }

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

  /* No need to debug */
  ble.verbose(false);

  /*Wait for connection */
  while (!ble.isConnected())
  {
    delay(500);
  }


  if (ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION))
  {
    ble.sendCommandCheckOK("AT+HWModeLED=" MODE_LED_BEHAVIOR);
  }

  /*Set Module to DATA Mode*/
  ble.setMode(BLUEFRUIT_MODE_DATA);
  setupSensor();
  digitalWrite(DIGITAL_IN_PIN, HIGH);
}

void loop()
{
  static byte old_state = LOW;

  uint16_t value = digitalRead(DIGITAL_IN_PIN);
 
  lsm.read();  /* ask it to read in the data */

  /* Get a new sensor event */
  sensors_event_t a, m, g, temp;

  lsm.getEvent(&a, &m, &g, &temp);

  float scaleFactor = 1.0; // formerly 100.0
  float xUpG = scaleFactor * g.gyro.x;
  float yUpG = scaleFactor * g.gyro.y;
  float zUpG = scaleFactor * g.gyro.z;
  float xScaledG = map(xUpG, gyroRawMin, gyroRawMax, gyroMin, gyroMax);
  float yScaledG = map(yUpG, gyroRawMin, gyroRawMax, gyroMin, gyroMax);
  float zScaledG = map(zUpG, gyroRawMin, gyroRawMax, gyroMin, gyroMax);

  ble.write(xScaledG);
  ble.write(yScaledG);
  ble.write(zScaledG);
  delay(50);
}


Generally what happens is that the data starts out transmitting fine - and then within 5-10 minutes, the gyro data is no longer transmitted. (Usually there's no software acknowledgement that a disconnect has occurred - no error notification appears in the app and the blue light indicating BLE connection on the Feather remains on - but gyro values keep printing - they're just no longer updated with gyro movement.)

I have a BUNCH of Feathers and LSM9DS1 gyros and have soldered some myself and had some soldered by friends, assuming that some sort of hardware issue was responsible - but the whole procedure above has now been tried several times from scratch and has been replicated in all versions.

The working theory is that the issue is related to Cordova being an old (and maybe obsolete?) framework (per this: https://www.netguru.co/blog/why-you-should-migrate-your-app-from-ionic-cordova-or-phonegap-to-react-native), so I'm planning to start trying to rebuild my app in Swift (which would be frustrating since I have spent the last several months migrating it from the old Cordova app interface into one that meshes with the Bluefruitle back-end code - so I would rather not start with a new programming language altogether, especially since it's hard to tell if it will fix my underlying problem).

Have you experienced this before and do you have any idea what might be going on? Any help would be greatly appreciated.
Last edited by MCGEngineer on Thu Nov 08, 2018 6:24 pm, edited 1 time in total.

MCGEngineer
 
Posts: 16
Joined: Tue Mar 10, 2015 2:14 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by adafruit_support_carter on Thu Nov 08, 2018 1:38 pm

Can you also print the sensor values in the serial console and watch the output there? See if that continues to run OK even when you lose BLE connectivity? This will check to see if it's something lower level than the BLE comms.

adafruit_support_carter
 
Posts: 6938
Joined: Tue Nov 29, 2016 2:45 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by MCGEngineer on Thu Nov 08, 2018 2:56 pm

Thank you. That's a helpful question/point. I ran this experiment and confirmed that the serial data (on the left - will read 63, 63, 63 when gyro is not moving) continues to reflect the gyro data even when the data transmitted over BLE to the iPad (on the right - bottom line should read 0, 0, 0 only when gyro is not moving) stops working.
(As noted before, this change usually takes a few to several minutes to take place; the iPad-shown data presents normally for a while.)
https://www.dropbox.com/s/no3y36wkxcqzpsk/2018-11-08%2013.53.36.mp4?dl=0

MCGEngineer
 
Posts: 16
Joined: Tue Mar 10, 2015 2:14 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by MCGEngineer on Thu Nov 08, 2018 2:59 pm

By the way, after this point is reached, the BLE-disconnect button in the Adafruit software doesn't work anymore - presumably that's because something has gone awry in the connection process, but no error is thrown in the app or in the XCode console. It just doesn't do anything (i.e. go back to the device selection screen).

MCGEngineer
 
Posts: 16
Joined: Tue Mar 10, 2015 2:14 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by adafruit_support_carter on Thu Nov 08, 2018 6:12 pm

By the way, after this point is reached, the BLE-disconnect button in the Adafruit software doesn't work anymore

That repo you linked isn't an Adafruit repo. What is the Adafruit software you are referring to here?

adafruit_support_carter
 
Posts: 6938
Joined: Tue Nov 29, 2016 2:45 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by MCGEngineer on Thu Nov 08, 2018 6:23 pm

That's correct, sorry. I think it was a typo and I meant "iPad" - but in any case, I'm referring to this app compiled from the repository I linked in my first post, which is the only Cordova-specific project I found online (other than ones from this same author) with Feather BLE support:
https://github.com/don/cordova-plugin-ble-central/tree/master/examples/bluefruitle

MCGEngineer
 
Posts: 16
Joined: Tue Mar 10, 2015 2:14 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by adafruit_support_carter on Fri Nov 09, 2018 12:22 pm

The basic sensor reading is still working, as your test showed. So it seems like it's something happening somewhere in the BLE part of things. Try looking through that persons issues:
https://github.com/don/cordova-plugin-b ... ral/issues
and make a new one if you need to.

adafruit_support_carter
 
Posts: 6938
Joined: Tue Nov 29, 2016 2:45 pm

Re: BLE Connectivity issues with Bluefruit 32u4/lsm9ds1 comb

by MCGEngineer on Fri Nov 09, 2018 4:00 pm

Thanks, I'll investigate there. Much appreciated.

MCGEngineer
 
Posts: 16
Joined: Tue Mar 10, 2015 2:14 pm

Please be positive and constructive with your questions and comments.