Sending realtime data EMG to my Android via BluetoothLE

Don't draw, just present the data in a Label

Don't use delay() it will interrupt your hardware and thus start producing erroneous results.

if (switchCharacteristic.written()) .... it is never written!
The Serial comms is with your Arduino Serial Monitor, not the App.

Put the "if(millis() - lgUpdateTime > 1000)" within your "while (central.connected())"

switchCharacteristic.write(nilai_sensor); //To App
switchCharacteristic.write(nilai_sensor2); //To App

Note, the "nilai" vars should be shorts, not ints.

Actually, I just noticed that Juan's chart wants a string - so change your Characteristic from Short to String:

BLEStringCharacteristic switchCharacteristic(CHARACTERISTIC_UUID, BLERead | BLEWriteWithoutResponse);

//Send to App:
char sSensorVals[16];
sprintf(sSensorVals, "%u,%u\0", nilai_sensor, nilai_sensor2);

is this what i should write in my sketch?

Yes - also, sorry, but to use sprinf() the values from the sensors should be type unsigned int.

If it's an unsigned int, can it be accepted by the app, sir?

And if i use the above, do i use this too?

It's an unsigned int for sprintf(), which creates a string (char[16]) to send to the App.

Example result of Sprintf(): 234, 765

Formatted this way, it can populate a Label in the App as directed by Juan.

It does mean, in the App, you should register for and read Strings instead of Shorts.

A large cup of coffee might help at this point :upside_down_face:

1 Like

Nope, you are now sending each pair of values as one String.

there is an error sir, is my sketch wrong?

Can't tell from a Screenshot.........

I'm sorry sir, this is it

Well, it's a good idea to declare your variables before using them :thinking:

Collect the values, then combine them into a String:

I haven't tested the rest of your code, my Arduino compiler isn't launching.

Edit: I have now tested your code. I can see it is supposed to activate the motors but currently the code isn't going to do that, the Arduino is not receiving commands from the App.

Staying with the issue as per the Topic Title, try this Sketch:

I assume you have changed your Project Blocks accordingly to receive Strings and then set each String in a Label as per Juan's instructions. Note, we are using a 'C' String which is actually a special array of chars. There is also a 'C++' String compatible with Arduino but not compatible with all libraries.

So how do I get my sketch to receive commands from the app as well as transmit data?

I have tried the sketch that you sent and I have seen it in the app, but after I changed it so that it could appear as a graphic an error like this appears

That will be similar to your original LED Sketch, but you have to bear in mind that you can't send and receive at the same time (unless there are two communication channels between the hardware and the App). Think of a Bluetooth signal as water running through a pipe - it can't go in both directions at the same time.

However, lets not get ahead of ourselves - fix the current issue first.

Yes sir, let's do that :blush:

By the way, this is my blocks

That's Juan's department. Is there an example Project that you can study?

I can study from this sir, but like you said for graphics don't need to use a clock