I just picked up an Arduino Nano 33 IoT for a project, and I'm working on getting Bluetooth to connect to a mobile app I'm building, so I can send data from the board to my device.
However, whenever I set up the BLE connection, I can't get it to broadcast a different local name, other than Arduino. Further, when I attempt to connect to the device via that connection, it times out.
To test this, I'm using the LED sample that comes with the ArduinoBLE library:
/*
LED
This example creates a Bluetooth® Low Energy peripheral with service that contains a
characteristic to control an LED.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or
nRF Connect (Android), to interact with the services and characteristics
created in this sketch.
This example code is in the public domain.
*/
#include <ArduinoBLE.h>
BLEService ledService("180A"); // Bluetooth® Low Energy LED Service
// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("2A57", 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 Bluetooth® Low Energy module failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("Nano 33 IoT");
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(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for Bluetooth® Low Energy 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()) {
switch (switchCharacteristic.value()) { // any value other than 0
case 01:
Serial.println("LED on");
digitalWrite(LED_BUILTIN, HIGH); // will turn the LED on
break;
case 02:
Serial.println("LED fast blink");
digitalWrite(LED_BUILTIN, HIGH); // will turn the LED on
delay(500);
digitalWrite(LED_BUILTIN, LOW); // will turn the LED off
delay(500);
digitalWrite(LED_BUILTIN, HIGH); // will turn the LED on
delay(500);
digitalWrite(LED_BUILTIN, LOW); // will turn the LED off
break;
case 03:
Serial.println("LED slow blink");
digitalWrite(LED_BUILTIN, HIGH); // will turn the LED on
delay(1000);
digitalWrite(LED_BUILTIN, LOW); // will turn the LED off
delay(1000);
digitalWrite(LED_BUILTIN, HIGH); // will turn the LED on
delay(1000);
digitalWrite(LED_BUILTIN, LOW); // will turn the LED off
break;
default:
Serial.println(F("LED off"));
digitalWrite(LED_BUILTIN, LOW); // will turn the LED off
break;
}
}
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
digitalWrite(LED_BUILTIN, LOW);
}
}
When I use LightBlue to interrogate Bluetooth devices, I see one named "Arduino" (which I've verified is this board, not some other random device), and tapping on it times out.
I saw a previous post about this from a couple years back, but it was closed, with the OP saying that he had 4 boards, and only one of them had this issue, which suggests to me that it was a hardware problem. Is it possible that's the case here?