Hello,
I have a small problem with my MIT App Inventor application.
I'm trying to do something rather basic: Send a byte to my arduino when I press a button. And then, if it works, send a float when I move a slider.
The problem is that I get nothing. However, when I use the "BytesWritten" function, the correct value is displayed in my Label.
Trying with the nRF Connect application, I manage to send a bytes on my "button" UUID. But not with MIT :(. Have I forgotten something? Do I need a special authorization that nRF connect asks for without me seeing it but that I have to do manually on MIT app ?
Thanks in advance for your help.
My Arduino code :
#include <ArduinoBLE.h>
// Définition de l'UUID pour le service et la caractéristique
BLEService appandroid("0bd217e8-f703-11ee-a951-0242ac120002"); // Crée un service BLE personnalisé
BLEByteCharacteristic boutonCharacteristic("0bd21a0e-f703-11ee-a951-0242ac120002", BLERead | BLENotify | BLEWrite); // Caractéristique pour la valeur du bouton
BLEFloatCharacteristic sliderCharacteristic("0bd21e5a-f703-11ee-a951-0242ac120002", BLERead | BLENotify | BLEWrite); // Caractéristique pour la valeur du slider
float sliderValue = 0;
byte boutonvalue = 0;
void setup() {
Serial.begin(9600);
// Initialise le BLE
if (!BLE.begin()) {
Serial.println("Starting BLE failed!");
while (1);
}
// Déclare le service et la caractéristique
BLE.setLocalName("Arduino2040-Slider");
BLE.setAdvertisedService(appandroid);
appandroid.addCharacteristic(sliderCharacteristic);
appandroid.addCharacteristic(boutonCharacteristic);
BLE.addService(appandroid);
// Commence à diffuser le service BLE
BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
}
void loop() {
// Écoute les connexions BLE
BLEDevice central = BLE.central();
// Si une connexion est établie
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
// Tant que la connexion est active
while (central.connected()) {
// Attend la mise à jour de la valeur de la caractéristique du slider
if (sliderCharacteristic.written()) {
// Lit la nouvelle valeur du slider
delay(10);
sliderValue = sliderCharacteristic.value();
Serial.print("Received slider value: ");
Serial.println(sliderValue);
// Faites ce que vous voulez avec la valeur du slider ici
}
if (boutonCharacteristic.written()) {
delay(10);
// Lit la nouvelle valeur du slider
boutonvalue = boutonCharacteristic.value();
Serial.print("Received bouton value: ");
Serial.println(boutonvalue);
// Faites ce que vous voulez avec la valeur du slider ici
}
delay(10);
}
// La connexion a été perdue
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
}
Screen of my MIT App :