Problem Reading Strings With App From Arduino BLE Home » Arduino Ble Writevalue String » Problem Reading Strings With App From Arduino BLE Maybe your like Arduino Blink Led 10 Times Arduino Bluetooth 4.0 Seri Modül - Hm-10 Arduino Bluetooth Ble Hm-10 Arduino Bluetooth Controller Apk Download Arduino Bluetooth Controller App Android Loading Problem reading Strings with app from Arduino BLE MIT App Inventor Help ble fabicarlos July 26, 2020, 3:14am 1 Hello everyone, I'm having troubles when I try to read string data received from my Arduino. It connects perfectly via BLE but I only get Chinese characters on my phone screen and the App crashes. So far I haven't read correctly any String value, even when I try to receive only one string data I keep receiving the chinese letters. Error498×1080 30 KB I would really appreciate your help. Kind regards. Arduino Code #include <Arduino_LSM9DS1.h> #include <ArduinoBLE.h> BLEService gyroService("0000480f-0000-1000-8000-00805f9b34fb"); BLEStringCharacteristic LevelChar("00002a11-0000-1000-8000-00805f9b34fb", BLERead | BLENotify,100); unsigned int igUpdateTime; void setup() { Serial.begin(9600); igUpdateTime = millis(); if (!IMU.begin()) { //LSM9DS1 begin Serial.println("LSM9DS1 error!"); while (1); } if (!BLE.begin()) { Serial.println("BLE error!"); while (1); } // set advertised local name and service UUID: BLE.setAdvertisedService(gyroService); // add the service UUID gyroService.addCharacteristic(LevelChar); BLE.addService(gyroService); // start advertising BLE.setLocalName("gyro"); // start advertising BLE.advertise(); } float ac_x, ac_y, ac_z; float gy_x, gy_y, gy_z; float ma_x, ma_y, ma_z; String Level_String; void updategyroLevel() { if (IMU.accelerationAvailable()) { IMU.readAcceleration(ac_x, ac_y, ac_z); } if (IMU.gyroscopeAvailable()) { IMU.readGyroscope(gy_x, gy_y, gy_z); } if (IMU.magneticFieldAvailable()) { IMU.readMagneticField(ma_x, ma_y, ma_z); } Level_String=String(ac_x,3)+","+String(ac_y,3)+","+String(ac_z,3)+","+String(gy_x,3)+","+String(gy_y,3)+","+String(gy_z,3)+","+String(ma_x,3)+","+String(ma_y,3)+","+String(ma_z,3); // Level_String+=","+String(gy_x,3)+","+String(gy_y,3)+","+String(gy_z,3); // Level_String+=","+String(ma_x,3)+","+String(ma_y,3)+","+String(ma_z,3); LevelChar.writeValue(Level_String); // Serial.println(Level_String); } void loop() { // listen for BLE peripherals to connect: BLEDevice central = BLE.central(); // updategyroLevel(); // delay(50); // if a central is connected to peripheral: if (central) { while (central.connected()) { if(millis() - igUpdateTime > 1000){ igUpdateTime = millis(); updategyroLevel(); } // delay(2000); } } } IMUblock708×1859 145 KB IMU.aia (184.7 KB) Juan_Antonio July 26, 2020, 8:57am 2 BLE works by default with 20-byte packets. Try a simple String: Level_String= "123,456"; Gerriko_io July 26, 2020, 4:37pm 3 fabicarlos: BLEStringCharacteristic LevelChar("00002a11-0000-1000-8000-00805f9b34fb", BLERead | BLENotify,100); This is your problem. It is better to create a byte array for your data. Just remember at a float value requires 4 bytes. BLECharacteristic(const char* uuid, uint8_t properties, int valueSize, bool fixedLength = false); So in your Arduino code, if you used: BLECharacteristic LevelChar("00002a11-0000-1000-8000-00805f9b34fb", BLERead | BLENotify,100, true); This would send 100 bytes of data (a bit too much, but just here as an example) and this is an array of fixed size (i.e. data array cannot be less). fabicarlos July 26, 2020, 8:06pm 4 Hello, thank you for your answers @Juan_Antonio and @Gerriko_io I've solved the problem with the corrupted data (chinese symbols) using the "register for string" block instead of "read strings". But I have a new problem, I only can see 3 values on my app, I think the problem is with the list length. First I got this message: "Attempt to get item number 5 of a list of length 4" I tried to solve this problem by verifying the length of the list as you can see in the image (Blocks and app screen): WhatsApp Image 2020-07-26 at 3.23.22 PM498×1080 21.5 KB Bloques1320×2234 367 KB The Arduino code is the same I have already posted. @Gerriko_io I tried redefining as you suggested but I don't really know what I'm doing wrong, I get this message in the IDE. Is it maybe the way I'm defining the byte array? #include <Arduino_LSM9DS1.h> #include <ArduinoBLE.h> BLEService gyroService("0000480f-0000-1000-8000-00805f9b34fb"); BLECharacteristic LevelChar("00002a11-0000-1000-8000-00805f9b34fb", BLERead | BLENotify, 100, true); unsigned int igUpdateTime; void setup() { Serial.begin(9600); igUpdateTime = millis(); if (!IMU.begin()) { //LSM9DS1 begin Serial.println("LSM9DS1 error!"); while (1); } if (!BLE.begin()) { Serial.println("BLE error!"); while (1); } // set advertised local name and service UUID: BLE.setAdvertisedService(gyroService); // add the service UUID gyroService.addCharacteristic(LevelChar); BLE.addService(gyroService); // start advertising BLE.setLocalName("gyro"); // start advertising BLE.advertise(); } float ac_x, ac_y, ac_z; float gy_x, gy_y, gy_z; float ma_x, ma_y, ma_z; String Level_String; void updategyroLevel() { if (IMU.accelerationAvailable()) { IMU.readAcceleration(ac_x, ac_y, ac_z); } if (IMU.gyroscopeAvailable()) { IMU.readGyroscope(gy_x, gy_y, gy_z); } if (IMU.magneticFieldAvailable()) { IMU.readMagneticField(ma_x, ma_y, ma_z); } // Level_String=String(ac_x,3); Level_String=String(ac_x,3)+"|"+String(ac_y,3)+"|"+String(ac_z,3)+"|"+String(gy_x,3)+"|"+String(gy_y,3)+"|"+String(gy_z,3)+"|"+String(ma_x,3)+"|"+String(ma_y,3)+"|"+String(ma_z,3); // Level_String+=","+String(gy_x,3)+","+String(gy_y,3)+","+String(gy_z,3); // Level_String+=","+String(ma_x,3)+","+String(ma_y,3)+","+String(ma_z,3); LevelChar.writeValue(Level_String); // Serial.println(Level_String); } void loop() { // listen for BLE peripherals to connect: BLEDevice central = BLE.central(); // updategyroLevel(); // delay(50); // if a central is connected to peripheral: if (central) { while (central.connected()) { if(millis() - igUpdateTime > 4000){ igUpdateTime = millis(); updategyroLevel(); } // delay(2000); } } } ERROR1920×1020 59.1 KB I would really appreciate your help. Thank you so much Kind regards. Juan_Antonio July 26, 2020, 9:16pm 5 BLE works by default with 20-byte packets. (MTU) Try with block RequestMTU MIT App Inventor + Internet of Things MIT App Inventor brings the power and simplicity of app creation to the Internet of Things (IoT) and connected devices. Try out our latest tutorials and how-tos. Here a tutorial of BLE HM-10, it is another module and another code very different from yours, but maybe you can get some ideas. HM-10. BLE. Arduino UNO. Notify. Bluetooth. AT. iBeacon. Arrhythmia Tutorials and Guides Hello friends, I bought a wonderful HM-10 module with BLE for only $ 2. I have written my experiences on this Spanish website (http://kio4.com/arduino/161_HM10_BLE.htm) and I would like to share a summary in this Community. I have used the BluetoothLE 20190701 extension. I have connected the module to an Arduino UNO [hc10_3] I tried to use these libraries, but they did not work for me in Arduino UNO. CurieBLE.h is for Arduino 101 (Curie). ArduinoBLE is for Arduino MKR WiFi 1010,… Tag » Arduino Ble Writevalue String Write/Read A Simple String To/from A BLE Characteristic? - Arduino 101 Send Big String Through BLE - Project Guidance - Arduino Forum Nano BLE Can Read The Attributes But Doesn't Write Properly 'writeValue(char [20], Int&)' Is Ambiguous - Arduino Forum Using BLECharacteristic.writeValue() For Byte Arrays - Arduino Forum BLE Code To Take String Input From Another Bluetooth Enabled Deice Understanding BLE lue() - Arduino Forum Arduino Nan BLE 33 - How To Send Data Sending A String Over Bluetooth - Arduino Forum Ble.writeValue() How Do You Change A String Characteristic Dynamically? #199 - GitHub Data Received By BLE On The Wio Terminal Limited To The Number Of 3? BLE Characteristic Not Reading Full String At Once - Stack Overflow Arduino BLE Programming - Giovanni Organtini - Medium