BLE.begin() fails to run on Nano 33 IoT when running on battery

My goal is to use BLE on my Arduino Nano 33 IoT to transmit IMU data back to my computer. This will correctly run when the Arduino is connected to my laptop via a micro usb cable. However, I think due to the wire, the connection gets interrupted very frequently when I'm moving the Arduino and the range is also limited by the length of the cable.

So, I tried connecting my Nano to a breadboard using a power supply module and a 9V battery connected to it. I am able to successfully start the Nano, and by testing around with the code (turning the LED on at different steps), I determined that the BLE.begin() would return 0, causing it to run an infinite loop.

Here's the code:

#include <ArduinoBLE.h>
#include <Arduino_LSM6DS3.h>

#define BLE_UUID_ACCELEROMETER_SERVICE "1101"
#define BLE_UUID_ACCELEROMETER_X "2101"
#define BLE_UUID_ACCELEROMETER_Y "2102"
#define BLE_UUID_ACCELEROMETER_Z "2103"

#define BLE_DEVICE_NAME "Elfo"
#define BLE_LOCAL_NAME "Elfo"

BLEService accelerometerService(BLE_UUID_ACCELEROMETER_SERVICE);

BLEFloatCharacteristic accelerometerCharacteristicX(BLE_UUID_ACCELEROMETER_X, BLERead | BLENotify);
BLEFloatCharacteristic accelerometerCharacteristicY(BLE_UUID_ACCELEROMETER_Y, BLERead | BLENotify);
BLEFloatCharacteristic accelerometerCharacteristicZ(BLE_UUID_ACCELEROMETER_Z, BLERead | BLENotify);

float x, y, z;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  // initialize IMU
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1)
      ;
  }

  Serial.print("Accelerometer sample rate = ");
  Serial.print(IMU.accelerationSampleRate());
  Serial.println("Hz");

  digitalWrite(LED_BUILTIN, HIGH);

  //BLE.stopScan();
  // initialize BLE
  if (!BLE.begin()) {
    Serial.println("Starting Bluetooth® Low Energy module failed!");
    while (1)
      ;
  }

  digitalWrite(LED_BUILTIN, HIGH);

  // set advertised local name and service UUID
  BLE.setDeviceName(BLE_DEVICE_NAME);
  BLE.setLocalName(BLE_LOCAL_NAME);
  BLE.setAdvertisedService(accelerometerService);

  accelerometerService.addCharacteristic(accelerometerCharacteristicX);
  accelerometerService.addCharacteristic(accelerometerCharacteristicY);
  accelerometerService.addCharacteristic(accelerometerCharacteristicZ);

  BLE.addService(accelerometerService);

  accelerometerCharacteristicX.writeValue(0);
  accelerometerCharacteristicY.writeValue(0);
  accelerometerCharacteristicZ.writeValue(0);

  // start advertising
  BLE.advertise();

  Serial.println("BLE Accelerometer Peripheral");
}

void loop() {
  BLEDevice central = BLE.central();

  if (IMU.accelerationAvailable()) {
    digitalWrite(LED_BUILTIN, HIGH);
    IMU.readAcceleration(x, y, z);
    Serial.print(x);
    Serial.print(y);
    Serial.print(z);
    Serial.println();

    accelerometerCharacteristicX.writeValue(x);
    accelerometerCharacteristicY.writeValue(y);
    accelerometerCharacteristicZ.writeValue(z);
  } else {
    digitalWrite(LED_BUILTIN, LOW);
  }
}

I've been searching through previous articles, and the most typical suggestion is to remove while (!Serial); but I don't have that in my program anyways. I've been trying to debug this for quite a while now but I haven't made much progress because I'm new to Arduino.

9V batteries are for smoke alarms, and are totally unsuitable for powering anything that draws a significant amount of current, such as the radio when you try to execute BLE.begin().

You need a power supply capable of delivering 200-300 mA or more.

9V_not_for_use

Hmm I see, what specs should I be looking up to find a replacement? I get that it should deliver 200 mA at minimum, but I'm not too sure if there are other requirements I need to meet to help me determine what to purchase.

i'm also surprised that's the case because I have another arduino kit that came with the battery, but I assume that it was meant to be used for some of the other electronics.

The Arduino Nano 33 IoT can be powered by any 5V to 18V source capable of supplying at minimum the required current, such as a phone charger.

Check the docs for other power options.

Where did you find the minimum required current b/c I'm not too sure where to find that?

I was considering buying this battery pack and plugging it into the Vin which has a voltage regulator. I'm not too sure how to verify the current to see if that'll be sufficient to enable BLE usage.

AA batteries can deliver 2 Amperes or more, so no problem there.

WiFi and BLE might draw around 200 mA when transmitting. You can measure the current draw with your multimeter.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.