I want to connect the arduino nano ble to my PI4
and "wait" for the PI to send me simple data "1" \ "0" - in order to turn on led for start.
this is what I wrote on the arduino side :
#include <ArduinoBLE.h>
void setup() {
Serial.begin(9600);
while (!Serial);
if (!BLE.begin()) {
Serial.println("- Starting Bluetooth® Low Energy module failed!");
while (1);
}
BLE.setLocalName("Arduino Nano Test Led ");
// BLE.setAdvertisedService(gestureService);
// gestureService.addCharacteristic(gestureCharacteristic);
// BLE.addService(gestureService);
// gestureCharacteristic.writeValue(-1);
BLE.advertise();
Serial.println("Nano 33 BLE (Peripheral Device)");
Serial.println( BLE.address()); //will hsow device MAC address
Serial.println(" ");
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
// print the central's MAC address:
Serial.println(central.address());
while (central.connected()) {
Serial.println("this is what I got");
Serial.print("rssi = ");
Serial.println(BLE.rssi());
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}
I can see it's working
2 questions:
why the arduino get disconnectd after ~ 20 seconds?
Your topic was MOVED to its current forum category as it is more suitable than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.