Hi, I have been using an Adafruit Feather Sense nRF52840 for a project recently and ran into an issue. I had been running a simple code on it when the device suddenly disconnected from my computer and crashed. If I plug in the board I can measure the correct voltage levels from both USB and 3V pins and the charge LED rapidly blinks as it should, but nothing else works. I have tried everything I can find to reset it but unfortunately there is not a lot of documentation for this exact model online. I'm open to any suggestions thank you for your help!
Code and schematics please ...
I'm reading output from an onboard accelerometer and sending that to the plotter on the bluefruit app via bluetooth while also using the data to control the on board neopixel.
Here is the code:
#include <bluefruit.h>
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>
#include <Adafruit_BMP280.h> // For On Board Temperature Sensor
#include <Adafruit_LSM6DS33.h> // For On Board Gyro/Accelerometer
#include <Arduino.h>
#include <Adafruit_TinyUSB.h> // for Serial
//LED Things
#if defined(USE_TINYUSB)
#include <Adafruit_TinyUSB.h> // for Serial
#endif
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 8 //Pin Controlling On Board LED
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
// BLE Service
BLEDfu bledfu; // OTA DFU service
BLEDis bledis; // device information
BLEUart bleuart; // uart over ble
BLEBas blebas; // battery
Adafruit_BMP280 bmp280; // temperautre, barometric pressure
Adafruit_LSM6DS33 lsm6ds33; // accelerometer, gyroscope
float temperature, pressure, altitude;
float accel_x, accel_y, accel_z;
float gyro_x, gyro_y, gyro_z;
float L;
int Red;
int Green;
int Blue;
short sampleBuffer[256]; // buffer to read samples into, each sample is 16-bits
volatile int samplesRead; // number of samples read
unsigned long adcvalue;
int adcin = A0;
float mv_per_lsb = 3600.0F/1024.0F; // 10-bit ADC with 3.6V i
void setup()
{
Serial.begin(115200);
//Initialize On Board Sensors
bmp280.begin();
lsm6ds33.begin_I2C();
//Initialize LED
pinMode(LED_BUILTIN, OUTPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// analogReadResolution(12); // Can be 8, 10, 12 or 14
#if CFG_DEBUG
// Blocking wait for connection when debug mode is enabled via IDE
while ( !Serial ) yield();
#endif
// Setup the BLE LED to be enabled on CONNECT
// Note: This is actually the default behavior, but provided
// here in case you want to control this LED manually via PIN 19
Bluefruit.autoConnLed(true);
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
// To be consistent OTA DFU should be added first if it exists
bledfu.begin();
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
// Start BLE Battery Service
blebas.begin();
blebas.write(100);
// Set up and start advertising
startAdv();
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
Serial.println("Once connected, enter character(s) that you wish to send");
}
void startAdv(void)
{
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
// Include bleuart 128-bit uuid
Bluefruit.Advertising.addService(bleuart);
// Secondary Scan Response packet (optional)
// Since there is no room for 'Name' in Advertising packet
Bluefruit.ScanResponse.addName();
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
* https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
// Forward data from HW Serial to BLEUART
// while (Serial.available())
// {
// Delay to wait for enough input, since we have a limited transmission buffer
// delay(2);
// uint8_t buf[64];
// int count = Serial.readBytes(buf, sizeof(buf));
// bleuart.write( buf, count );
// Read Temp/Pressure
temperature = bmp280.readTemperature();
pressure = bmp280.readPressure();
altitude = bmp280.readAltitude(1013.25);
// Read Accelerometer and Gyro
sensors_event_t accel;
sensors_event_t gyro;
sensors_event_t temp;
lsm6ds33.getEvent(&accel, &gyro, &temp);
accel_x = accel.acceleration.x;
accel_y = accel.acceleration.y;
accel_z = accel.acceleration.z;
gyro_x = gyro.gyro.x;
gyro_y = gyro.gyro.y;
gyro_z = gyro.gyro.z;
L=sqrt(pow(accel_x,2)+pow(accel_y,2)+pow(accel_z,2));
samplesRead = 0;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print("Barometric pressure: ");
Serial.println(pressure);
Serial.print("Altitude: ");
Serial.println(altitude);
Serial.print("Acceleration: ");
Serial.print(accel_x);
Serial.print(" ");
Serial.print(accel_y);
Serial.print(" ");
Serial.print(accel_z);
Serial.println(" m/s^2");
Serial.print("L = ");
Serial.println(L);
Red=random(0,256);
Green=random(0,256);
Blue=random(0,256);
//Set LED
if (L > 20) {
strip.setPixelColor(0, Red,Green,Blue);
}
strip.show();
delay(100);
adcvalue = analogRead(adcin);
char charBuf[20];
itoa(L, charBuf, 10);
bleuart.write(charBuf);bleuart.write('\n');
// Forward from BLEUART to HW Serial
// while ( bleuart.available() )
// {
// uint8_t ch;
// ch = (uint8_t) bleuart.read();
// Serial.write(ch);
// }
}
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
// Get the reference to current connection
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
/**
* Callback invoked when a connection is dropped
* @param conn_handle connection where this event happens
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
*/
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) conn_handle;
(void) reason;
Serial.println();
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.