I've connected my Arduino Nano 33 BLE Sense Rev2 to Arduino Science Journal with sensors fully functional when connected to Arduino IDE 2. As I need to use it as a health wearable, I'm trying to power with a USB battery pack, and there are no problems except the loss of the Nano33BLESenseRev2Firmware when I transit to the external power. A simple Blink sketch is permanently stored as usual, thus the loss seems to be related specifically to the firmware. Is this a normal behaviour? and which is the possible solution?
As a matter of fact I could verify that the sketch is retained, but the "Started IMU Initialized - Flash Initialized - address = xxx - name = BLE Sense - 3D1E" is not able to start without the Serial Monitor launch.
Have you tried another Nano 33 BLE, it sounds like it is not programing.
Is while(!Serial) in the code you are running?
as I specified, the uploaded sketch is retained after power off and on again. The problem seems that it needs to open the Serial Monitor on the IDE to start the BLE, and this is not done while disconnected from the USB port.
I can see :
#ifdef DEBUG
Serial.begin(9600);
while (!Serial)
;
Serial.println("Started");
#endif
![]()
Can you please post the sketch you are running.
it is the official sketch from the Examples of the 'Nano33BLESenseRev2Firmware.ino' suggested in the
https://support.arduino.cc/hc/en-us/articles/4408029337746-Upload-the-Science-Journal-firmware?queryID=341d7dda9fc0d488e0c71f2c649549d0&_gl=118868hd_gaMTA0MDQzNjUwOC4xNjc3NDM1NzY0_ga_NEXN8H46L5*MTY4MDg4ODE2OS4zOS4xLjE2ODA4ODgxODUuMC4wLjA.
#include "LowPower.h"
#include <arm_math.h>
#include "config.h"
#include <PDM.h>
#include <ArduinoBLE.h>
const int VERSION = 0x00000001;
#define SCIENCE_KIT_UUID(val) ("555a0002-" val "-467a-9538-01f0652c74e8")
#define RESISTANCE_PIN A0
#define VOLTAGE_BUFFER_SIZE 16
#define DEBUG 0
BLEService service(SCIENCE_KIT_UUID("0000"));
BLEUnsignedIntCharacteristic versionCharacteristic(SCIENCE_KIT_UUID("0001"), BLERead);
BLECharacteristic accelerationCharacteristic(SCIENCE_KIT_UUID("0011"), BLENotify, 3 * sizeof(float));
BLECharacteristic gyroscopeCharacteristic(SCIENCE_KIT_UUID("0012"), BLENotify, 3 * sizeof(float));
BLECharacteristic magneticFieldCharacteristic(SCIENCE_KIT_UUID("0013"), BLENotify, 3 * sizeof(float));
BLEFloatCharacteristic temperatureCharacteristic(SCIENCE_KIT_UUID("0014"), BLENotify);
BLEFloatCharacteristic pressureCharacteristic(SCIENCE_KIT_UUID("0015"), BLENotify);
BLEFloatCharacteristic humidityCharacteristic(SCIENCE_KIT_UUID("0016"), BLENotify);
BLEUnsignedIntCharacteristic proximityCharacteristic(SCIENCE_KIT_UUID("0017"), BLENotify);
BLECharacteristic colorCharacteristic(SCIENCE_KIT_UUID("0018"), BLENotify, 4 * sizeof(int));
BLEUnsignedShortCharacteristic soundPressureCharacteristic(SCIENCE_KIT_UUID("0019"), BLENotify);
BLEFloatCharacteristic resistanceCharacteristic(SCIENCE_KIT_UUID("0020"), BLENotify);
byte voltageBufferIndex = 0;
bool voltageBufferFilled = false;
short soundSampleBuffer[256];
short voltageSampleBuffer[VOLTAGE_BUFFER_SIZE];
void updateSubscribedCharacteristics();
void onPDMdata() {
// query the number of bytes available
int bytesAvailable = PDM.available();
// read into the sample buffer
PDM.read(soundSampleBuffer, bytesAvailable);
}
uint16_t getSoundAverage() {
uint32_t avg = 0;
for (int i = 0; i < sizeof(soundSampleBuffer) / sizeof(soundSampleBuffer[0]); i++) {
avg += soundSampleBuffer[i] * soundSampleBuffer[i];
}
return sqrt(avg);
}
void readVoltage() {
voltageSampleBuffer[voltageBufferIndex] = analogRead(RESISTANCE_PIN);
if (!voltageBufferFilled && voltageBufferIndex == VOLTAGE_BUFFER_SIZE - 1) {
voltageBufferFilled = true;
}
voltageBufferIndex = (++voltageBufferIndex) % VOLTAGE_BUFFER_SIZE;
}
uint16_t getVoltageAverage() {
uint16_t avg = 0;
byte upperBound = voltageBufferFilled ? VOLTAGE_BUFFER_SIZE : voltageBufferIndex;
for (int i = 0; i < upperBound; i++) {
avg += voltageSampleBuffer[i];
}
return avg / upperBound;
}
// String to calculate the local and device name
String name;
unsigned long lastNotify = 0;
void printSerialMsg(const char* msg) {
#ifdef DEBUG
if (Serial) {
Serial.println(msg);
}
#endif
}
void setup() {
#ifdef DEBUG
Serial.begin(9600);
while (!Serial)
;
Serial.println("Started");
;
#endif
delay(2000);
sensorsInit();
pinMode(RESISTANCE_PIN, INPUT); // Used for reading resistance
PDM.onReceive(onPDMdata);
if (!PDM.begin(1, 16000)) {
printSerialMsg("Failed to start PDM!");
blinkLoop();
}
if (!BLE.begin()) {
printSerialMsg("Failed to initialized BLE!");
blinkLoop();
}
String address = BLE.address();
#ifdef DEBUG
if (Serial) {
Serial.print("address = ");
Serial.println(address);
}
#endif
address.toUpperCase();
name = "BLE Sense - ";
name += address[address.length() - 5];
name += address[address.length() - 4];
name += address[address.length() - 2];
name += address[address.length() - 1];
#ifdef DEBUG
if (Serial) {
Serial.print("name = ");
Serial.println(name);
}
#endif
BLE.setLocalName(name.c_str());
BLE.setDeviceName(name.c_str());
BLE.setAdvertisedService(service);
service.addCharacteristic(versionCharacteristic);
service.addCharacteristic(accelerationCharacteristic);
service.addCharacteristic(gyroscopeCharacteristic);
service.addCharacteristic(magneticFieldCharacteristic);
service.addCharacteristic(temperatureCharacteristic);
service.addCharacteristic(pressureCharacteristic);
service.addCharacteristic(humidityCharacteristic);
service.addCharacteristic(proximityCharacteristic);
service.addCharacteristic(colorCharacteristic);
service.addCharacteristic(soundPressureCharacteristic);
service.addCharacteristic(resistanceCharacteristic);
versionCharacteristic.setValue(VERSION);
BLE.addService(service);
BLE.advertise();
lowPower();
}
void loop() {
BLE.poll(1000);
while (BLE.connected()) {
lowPowerBleWait(100);
updateSubscribedCharacteristics();
}
}
void updateSubscribedCharacteristics() {
if (accelerationCharacteristic.subscribed()) {
if (IMU.accelerationAvailable()) {
float x, y, z;
IMU.readAcceleration(x, y, z);
float acceleration[3];
acceleration[0] = x;
acceleration[1] = y;
acceleration[2] = z;
accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration));
}
}
if (gyroscopeCharacteristic.subscribed()) {
if (IMU.gyroscopeAvailable()) {
float x, y, z;
IMU.readGyroscope(x, y, z);
float gyroscope[3];
gyroscope[0] = x;
gyroscope[1] = y;
gyroscope[2] = z;
gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope));
}
}
if (magneticFieldCharacteristic.subscribed()) {
float x, y, z;
if (IMU.magneticFieldAvailable()) {
IMU.readMagneticField(x, y, z);
float magneticField[3];
magneticField[0] = x;
magneticField[1] = y;
magneticField[2] = z;
magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField));
}
}
if (soundPressureCharacteristic.subscribed()) {
uint16_t sound = getSoundAverage();
soundPressureCharacteristic.writeValue(sound);
}
bool doTemperature = temperatureCharacteristic.subscribed();
bool doHumidity = humidityCharacteristic.subscribed();
if (doTemperature || doHumidity) {
float temperature = HS300x.readTemperature();
if (doTemperature) {
temperatureCharacteristic.writeValue(temperature);
}
if (doHumidity) {
float humidity = HS300x.readHumidity();
float dp = temperature - ((100.0 - humidity) / 5.0);
float humidityCalibrated = 100.0 - (5.0 * (temperature - dp));
humidityCharacteristic.writeValue(humidityCalibrated);
}
}
if (resistanceCharacteristic.subscribed()) {
readVoltage();
uint16_t measuredValue = getVoltageAverage();
float voltageRatio = 1024.0f / measuredValue;
resistanceCharacteristic.writeValue(voltageRatio);
}
if (proximityCharacteristic.subscribed() && APDS.proximityAvailable()) {
uint32_t proximity = APDS.readProximity();
proximityCharacteristic.writeValue(proximity);
}
if (colorCharacteristic.subscribed() && APDS.colorAvailable()) {
int color[4];
APDS.readColor(color[0], color[1], color[2], color[3]);
colorCharacteristic.writeValue((byte*)color, sizeof(color));
}
if (pressureCharacteristic.subscribed()) {
float pressure = BARO.readPressure();
pressureCharacteristic.writeValue(pressure);
}
}
The problem seems that it needs to open the Serial Monitor on the IDE to start the BLE, and this is not done while disconnected from the USB port.
the loss seems to be related specifically to the firmware. Is this a normal behaviour?
"Started IMU Initialized - Flash Initialized - address = xxx - name = BLE Sense - 3D1E" is not able to start without the Serial Monitor launch.
This is certainly not normal behaviour. I can not replicate your environment, and my BLE peripheral sketches all start and connect to a central when the Nano BLE is not connected to the serial monitor over usb.
I would think your issue may be on the central side, as I don't think the text you quoted about "Started IMU" is part of the of the Nano BLE side of things and it is in the app which is connecting to and reading from the Nano.
You may want to try using some of the more simple Nano 33 BLE sense library sketches and a phone app like Light Blue to confirm that the issue of restarting BLE without the serial monitor is not with the Nano 33 side of things.
Thanks for your advice,
I tried with a simple BLE sketch: (Enhanced advertising) from the Examples on the IDE.
#include <ArduinoBLE.h>
BLEService myService("fff0");
BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast);
// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop'
const uint8_t manufactData[4] = {0x01, 0x02, 0x03, 0x04};
const uint8_t serviceData[3] = {0x00, 0x01, 0x02};
void setup() {
Serial.begin(9600);
while (!Serial);
if (!BLE.begin()) {
Serial.println("failed to initialize BLE!");
while (1);
}
myService.addCharacteristic(myCharacteristic);
BLE.addService(myService);
// Build scan response data packet
BLEAdvertisingData scanData;
// Set parameters for scan response packet
scanData.setLocalName("Test enhanced advertising");
// Copy set parameters in the actual scan response packet
BLE.setScanResponseData(scanData);
// Build advertising data packet
BLEAdvertisingData advData;
// Set parameters for advertising packet
advData.setManufacturerData(0x004C, manufactData, sizeof(manufactData));
advData.setAdvertisedService(myService);
advData.setAdvertisedServiceData(0xfff0, serviceData, sizeof(serviceData));
// Copy set parameters in the actual advertising packet
BLE.setAdvertisingData(advData);
BLE.advertise();
Serial.println("advertising ...");
}
void loop() {
BLE.poll();
}
The behaviour of the Nano Sense was exactly the same. After battery powering it does not start advertising and (Blueligth verified) a Serial Monitor opening is needed to start. At this moment it's an unsolved mistery. Unfortunately I don't have another Sense device to verify if the problem is chip-specific. However, a simple Blink sketch does not have the same problem: the blinking is mantained after battery charging.
It appears you have a back feed that is not accounted for. Post an annotated schematic showing "ALL" connections power sources etc and include links to technical information on all hardware devices.
After battery powering it does not start advertising and (Blueligth verified) a Serial Monitor opening is needed to start.
while (!Serial);
The enhanced advertising sketch has this line in it. It stops the program until a Serial connection is made.
Comment that line and see if it works with the battery. You can also try with powering from USB with a phone charger. There will be no monitor to open.
Thank you. The problem has been solved. ![]()
You are correct for the enhanced advertising sketch, but what was the issue with the Science Journal sketch posted in reply #8.
With this code the while(!Serial) would not have been called.
#define DEBUG 0
#ifdef DEBUG
Serial.begin(9600);
while (!Serial)
;
Serial.println("Started");
;
#endif
EDIT: My error
#define DEBUG 0 makes #ifdef true. I was confusing #ifdef with #if
About the solution, I have commented the while (!Serial) line in the Science Journal sketch, not in the enhanced advertising sketch, and it works now when passing to the USB battery powering.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.