Feather nRF52 Bluefruit LE crash with Neopixels and BLE UART

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
eventhorizon669
 
Posts: 4
Joined: Fri Dec 15, 2017 6:30 pm

Feather nRF52 Bluefruit LE crash with Neopixels and BLE UART

Post by eventhorizon669 »

I recently implemented the Neopixel Lamp design as detailed in https://learn.adafruit.com/ble-feather- ... it-diagram. All wiring is exactly per the design and my only change was substituting an Adafruit Feather nRF52 Bluefruit LE in place of the requested Adafruit Feather 32u4 Bluefruit LE.

Everything was going great then I became more ambitious and introduced Neopixel patterns (wipe, fade, etc.) that could be controlled via BLE UART commands. That's when things started falling apart.

The code was simple enough: listen to a BLE UART, upon receiving a packet start displaying a Neopixel pattern, and keep the pattern animating until another UART command said otherwise. On the client side, I just used the UART activity of the Adafruit Bluefruit LE Connect Android app.

The UART logic and the patterns worked beautifully, but I often found that the NRF52 would lock up the instant the Android client disconnected (by closing the UART activity).

It didn't always crash when disconnecting or sometimes took multiple connect/reconnect cycles before hanging, but it was a show stopper nonetheless. I found that if the NRF52 made it through a few disconnect cycles without crashing it would likely survive until the device was turned off/on again and the disconnect testing cycle restarted.

My first thought was, since the original design called for a 24 Neopixel ring, perhaps I was drawing too much current or had a bad USB connection. I tried every combination of different USB cables, USB ports both on my computer as well as via 2A wall chargers. I even checked current consumption via a hacked up USB extension cable and a multimeter, though I found I could crash even when drawing only 20mA.

I also tried using FreeRTOS Scheduler.startLoop() and Timer as alternatives to the old style loop() + millis() timeouts in case there was some peculiarity in how loops should work on this device. There was no discernible difference in behavior either way.

I'm not sure what else to try at this point so I have put together a minimal sketch to demonstrate problem.

Code: Select all

#include <Adafruit_NeoPixel.h>
#include <bluefruit.h>

#define PIN 30
#define PIXELS 1

long timeout = 0;
long interval = 1;
bool isLit = false;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRBW + NEO_KHZ800);
BLEUart bleuart;

void setup() {
  strip.begin();
  strip.show();
  Bluefruit.begin();
  Bluefruit.setTxPower(4);
  Bluefruit.setName("Bluefruit52");
  Bluefruit.autoConnLed(false);
  bleuart.begin();
  startAdv();
}

void startAdv(void) {
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();
  Bluefruit.Advertising.addService(bleuart);
  Bluefruit.ScanResponse.addName();
  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244);
  Bluefruit.Advertising.setFastTimeout(30);
  Bluefruit.Advertising.start(0);
}

void loop() {
  if (millis() >= timeout) {
    for (uint8_t i = 0; i < strip.numPixels(); i++) {
      if (isLit) {
        strip.setPixelColor(i, strip.Color(1, 0, 0));
      } else {
        strip.setPixelColor(i, strip.Color(0, 0, 1));
      }
    }

    strip.show();
    isLit = !isLit;
    timeout = millis() + interval;
  }
}
This sketch does nothing more than set up a single pixel Neopixel strip and open the BLE UART for connections. It does not read any data from the UART and will endlessly toggle the single Neopixel between the lowest intensity blue and red every millisecond.

While the sketch runs, the Neopixel should appear purple. If you connect to the BLE UART and disconnect (no need to send any data via the UART activity) eventually you should notice A) the Neopixel will remain frozen as either red or blue, and B) the BLE device will no longer be discoverable or accept connections. At this point, the NRF52 must be power cycled to resume normal operation.

In my own testing of the above sketch I have noted that the tighter the Neopixel update timing, the more likely a crash will happen upon UART disconnect. One millisecond may seem needlessly aggressive, but I have encountered crashes at up to 100ms timing, albeit with much less frequency.

Is there anything obvious that I'm doing wrong either in the code or the wiring? I see that NRF52 support was added to the Adafruit Neopixel library some time last year, but I can't help but wonder if I should have just stuck with the less powerful, but more mature Adafruit Feather 32u4 Bluefruit LE.

Thanks

User avatar
hathach
 
Posts: 1259
Joined: Tue Apr 23, 2013 1:02 am

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by hathach »

thanks for the detail report, we are able to reproduce the issue. It seems to be some sort of conflict between neopixel.show() with Softdevice. We are looking at it.

User avatar
hathach
 
Posts: 1259
Joined: Tue Apr 23, 2013 1:02 am

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by hathach »

It seems to be some sort of issue with the S132 v2.0.1. The issue seems to be gone with the newer Softdevice S132 v 5.1.0. Do you mind giving it a try
1. Update the bsp to latest 0.8.1
2. follow this guide to upgrade bootloader from using Softdevice v2 to v5. (basically select Tools->Bootloader -> 5.1.0 dual, select Tools->Programmer, then click burn)
https://learn.adafruit.com/bluefruit-nr ... bootloader
be patient and wait until the "Device Programmed" is printed.
3. It will erase all the sketch. Just keep the bootloader selection to version 5.1.0 and click upload the sketch to test again

Let's us know if this work for you.

Note: Again be patient when burning the bootloader, it is simple but quite dangerous

User avatar
eventhorizon669
 
Posts: 4
Joined: Fri Dec 15, 2017 6:30 pm

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by eventhorizon669 »

Thanks so much for the quick reply! I have mixed results to report.

What worked:
I updated the bsp and bootloader to the versions you suggested, reflashed the test sketch from my original post, and was no longer able to trigger a crash by disconnecting from the UART.

What didn't work:
After the positive results above, I bumped the pixel count in the sketch to 24 so I could use the entire Neopixel ring. Unfortunately, with all pixels in use, I can still cause a crash. The silver lining is, it is now harder to trigger a crash than before the bootloader upgrade. Sometimes it takes 4-5 attempts for the device to hang.

I'm encouraged by the progress made so far and would like to keep working toward zero crashes.

Please let me know if you are able to replicate the crash on your end.

Thanks again!

User avatar
eventhorizon669
 
Posts: 4
Joined: Fri Dec 15, 2017 6:30 pm

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by eventhorizon669 »

I had put this project on hold for the past month to work on other things, but I picked it back up this week. Unfortunately, I can still easily crash the NRF52 when using the BLE SoftDevice at the same time as heavy Neopixel activity.

While I appreciate the quick help you provided earlier in reducing the frequency of crashes, any instability is a dealbreaker for me. I've run out of things to try and am considering abandoning this microcontroller for my project.

Before I do so, do you have any other suggestions?

User avatar
hathach
 
Posts: 1259
Joined: Tue Apr 23, 2013 1:02 am

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by hathach »

Sorry, we are in hurry on another project and couldn't fix this particular issue as soon as we want. But we will definitely come back to this issue later in the future.

User avatar
Bene
 
Posts: 2
Joined: Sat Sep 27, 2014 5:07 pm

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by Bene »

Hi there, I am having exactly the same issue. Please help solving this, since neopixels and nrf52 are a natural combination many customers will use.

User avatar
eventhorizon669
 
Posts: 4
Joined: Fri Dec 15, 2017 6:30 pm

Re: Feather nRF52 Bluefruit LE crash with Neopixels and BLE

Post by eventhorizon669 »

This issue has been open for over 6 months with no resolution. Should I expect any further investigation from Adafruit?

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

Return to “General Project help”