Converting 4 bytes to integer

I deleted uuid just for the sketch I uploaded , uuids are there . I am using Arduino portenta, it has on board ble

1 Like

Yes, I have seen your post on the Arduino forum. :owl:


...but which Portenta model?

1 Like

Your Sketch has a lot of Serial printing - where is that going? It would usually be picked-up by the App.

Its portenta H7 model , does the BLE on it has differences from other Ble's who use the same lib ?

1 Like

Well I'm hoping it doesn't. There are a myriad of BLE solutions for Arduino so it's a matter of finding the correct one for the board and the data.

So where is all the Serial printing going to? Are you running the Arduino Serial Monitor on your PC?

1 Like

Yea serial is for me to see if everything works , i am not sending them over to BLE . its on my serial monitor .

Hard to find the info but indeed, the Portenta H7 is compatible with the ArduinoBLE lib.

Yes , if it wasnt i would be able to send values i cant read :stuck_out_tongue: .
I thing the solution is right in front of me but i cant really find it , maybe i am not converting right but i cant really know , the serial monitor is printing me good values , but the phone prints me bad whatever that is and uploads 0

Ok, so the data is not a List, it's a single string representing an integer. As a single string, you can plug it into a Label. It will present the value in a label like this: [1234] (hopefully)

Make sure you are using the latest MIT BLE Extension version 20200828

Your BLE Connected Block is correct but for one thing: utf16 = false.

Re the StringsReceived Block, that can be whittled down:


When the App is running, right-mouse on the 'get stringValues' Block and select "Do It" - this should show what the App is receiving.

In the Sketch, it's best to give the device a name that does not include spaces.

Try this:
ArduinoBLE_ToApp.txt (3.1 KB)

//ArduinoBLE_ToApp.ino  02/10/2020 19:24:08

// include the library code:
#include <SoftwareSerial.h>
#include <ArduinoBLE.h>

string sEcgValue;
unsigned int iEcgValue;
unsigned int igUpdateTime;
#define SERVICE_UUID        
#define SENSOR_PIN  A0
#define LO_PLUS_PIN 10
#define LO_PLUS_MIN 11

BLEService ECGservice(SERVICE_UUID);
BLEIntCharacteristic ECGchar(CHARACTERISTIC_UUID_TX, BLERead | BLENotify);

void setup()

         pinMode(LO_PLUS_PIN, INPUT); // Setup for leads off detection LO +
         pinMode(LO_PLUS_MIN, INPUT); // Setup for leads off detection LO -

         // begin initialization
         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
            The name can be changed but maybe be truncated based on space left in advertisement packet
         BLE.setAdvertisedService(ECGservice);  // add the service UUID
         ECGservice.addCharacteristic(ECGchar); // add the ecg  characteristic
         BLE.addService(ECGservice); // Add the battery service
         ECGchar.writeValue(0); // set initial value for this characteristic
         /* 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 */
         // start advertising

         Serial.println("Bluetooth device active, waiting for connection...");

         igUpdateTime = millis();

void loop()
         //Execute Comms every 200 milli seconds
	     if(millis() - igUpdateTime > 200)
               igUpdateTime = millis();

               // wait for a BLE central
               BLEDevice central = BLE.central();
               // if a central is connected to the peripheral:
               if (central) 
                         Serial.print("Connected to central: ");
                         // print the central's BT address:
                         // while the central is connected:
                         while (central.connected())
                                 iEcgValue = analogRead(SENSOR_PIN);
                                 sEcgValue = string(iEcgValue);

               // when the central disconnects, turn off the LED: 
               Serial.print("Disconnected from central: ");       

1 Like

Note, if the 200 milliseconds time interval can be increased, increase it for better reliability.

I see what you did , nice , didnt know that for the app inventor that i can see what i receive . Gonna test it tomorrow , since i am a good 14 hrs straight on computer , but why software serial ?
Will let you know asap , thank you so much Chris.

Unless you actually like sending [ ] wrappers in your URL, you will need to
unwrap the list of stringValues using either a select list item 1 or a for each item in list loop.

This actually makes alot of sense, i think i tried that earlier today but obvioulsy failed .

This is a common error with this block result.
One guy unwrapped the banana, then ate the peel.

1 Like

i think i keep eating peels the last 2 days

... It's not a list of values ABG, just the one, but that should work (select from a list of one) or of course use a text Block to remove the [].

So, using ABG's suggested method (the more elegant I think):


I used Your block with my Sketch , not the one you sent because there were some mistakes i noticed .
And the Label text Shows me Letters and weird symbols.
The sketch you provided i understand what it wants to do but its trying to assign a String characteristic to an Int , i changed the characteristic to char and i am getting no matching function errors when i am Writing String value to it , which is weird .
Seems it needs to be converted to a Char array[] ,which i tried to do earlier but i am getting the dtostrf function not declared in the scope