Nano 33 IOT bluetooth connectivity issues

Hi,

I'm new to arduino and just trying out a few basic examples with my Nano 33 IOT. I have installed the arduinoBLE package and am trying to use the LED example.

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

const int ledPin = LED_BUILTIN; // pin to use for the LED

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("LED");
  BLE.setAdvertisedService(ledService);

  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);

  // add service
  BLE.addService(ledService);

  // set the initial value for the characeristic:
  switchCharacteristic.writeValue(1);

  // start advertising
  BLE.advertise();

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

void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, LOW);          // will turn the LED off
        }
      }
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

When I start the serial monitor I see the "BLE LED Peripheral" text suggesting that things are working, and I can see the board on my phone (Pixel 4a) via light blue. When I go to connect, I get the message "Connected to central:" followed by the MAC address of my phone, however, light blue still says "connecting" after a bit the message "Disconnected from central:" comes up in the serial monitor. On the phone I get the message "No Data Available, failed to establish a connection to device, please select another device or try again".

I have tried this with several devices (my laptop, my phone, my wife's phone) all with the same result. Any ideas what the issue could be? The BLE function on the board is clearly working as the device is visible to be connected with, but it doesn't seem to be able to complete a connection properly. I thought about pairing my phone with the board first, but that also failed. Is there some security setting maybe that I'm missing?

Thanks in advance!

@manny_hedgehog, your topic has been moved to a more suitable location on the forum. Because you can compile and upload, this does not relate to the Installation and Troubleshooting section :wink:

Welcome to the forum.

Pairing is an optional feature in BLE and not supported by the ArduinoBLE library. Your app can simply connect.

Can you try another BLE app? I use BLE Scanner, nRF Connect and EFR Connect on iOS but believe all of them are available on Android as well.

There is no security you need to worry about. The ArduinoBLE library handles everything for you.

Can you confirm which version of the IDE, Board support and ArduinoBLE library you are using?

Please also try the BatteryMonitor sketch. It is just reading the analog pin 0 and picks some random noise to simulate a battery voltage. The sketch uses notifications. You should be able to see an automatically changing value in the app.

To make sure it is not the USB port on your laptop. Comment out while(!Serial) this will allow the sketch to run without the Serial Monitor open. Make sure to compile and program your sketch again. Then connect your Arduino to a USB battery pack or USB wall charger. Test again with your phone.

Another test you can do is run a WiFi sketch. Most parts of the radio are the same, but the firmware and software are different. If you have issue with that as well there may be a problem with your hardware.

Hi Both,

Thanks for the swift response and moving this to the correct section.

After a lot of playing about I reinstalled the board and updated the wifiNINA firmware which seems to have resolved the issue. I was unable to upgrade the firmware without reinstalling the board, so I am not sure what the issue was - could it be that the initial install was corrupted somehow? I only got the board the same day I posted the original message so can't imagine I was using an out of date board install.

Either way, this seems fixed now so thanks.