Hi I'm new of App Inventor and I'm trying to read data from an Arduino33Ble or send data to it.
I can send data as byte but I'm not able to read data from Arduino also if withNRF Connect I see the data received.
I hope someone can give me any suggestion to fix the issue.
Thanks Roberto.
Here the App Inventor block :
This is the arduino sketch jusr related to read data from Arduino.
#include <ArduinoBLE.h>
const int led_Pin = LED_BUILTIN; // pin to use for the LED
const int button_PIN = 3; // pin to use for the button
const int cmd1=0;
// never add BLENotify to a characteristic that has a BLEwrite parameter only
BLEService batteryService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
BLEIntCharacteristic batteryLevelChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLEWrite | BLENotify );
void setup() {
Serial.begin(9600);
// set LED pin to output mode
pinMode(button_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// Set a local name for the BLE device.
// This name will appear in advertising packets and can be used
// by remote devices to identify this BLE device.
BLE.setLocalName("BatteryMonitor");
//Here we will add and set the value for the Service UUID and the Characteristic.
BLE.setAdvertisedService(batteryService);
batteryService.addCharacteristic(batteryLevelChar);
BLE.addService(batteryService);
// Start advertising BLE.
// It will start continuously transmitting BLE advertising packets and
// will be visible to remote BLE central devices until it receives a new connection.
BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
}
void loop(){
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
digitalWrite(LED_BUILTIN, HIGH);
while (central.connected()) {
int battery = analogRead(A0);
int batteryLevel = map(battery, 0, 1023, 0, 100);
Serial.print("Battery Level % is now: ");
Serial.println(batteryLevel);
batteryLevelChar.writeValue(batteryLevel);
}
}
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}