When the output from my BLE app arrives on the arduino its just gibberish

  1. multiple
  2. individually
  3. i dont know, it worked just fine with other projects before
  4. arduino uno
  5. im using the AT-09

OK - progress. Less haste is the message!

I think you probably made the wrong Bluetooth choice, there doesn't seem to be anything in your Project that benefits from using BLE instead of BT Classic.

I don't understand your "Real Servo" code but it seems to differentiate between the possible sources of the integer value.

Instead of: Serial.readStringUntil('\n');

We can try: Serial.parseInt() (therefore Secondinput should be initialised as an int)

OutputInteger

well its not really benefiting from BLE, i just have BLE laying around so i kind of just used what i have lol

so like before, its reading, its just not returning the right values, the value on the first slider should be between 1000-1100, and here im getting numbers like 0,4, and 7

OK, try Write Bytes instead of Write Int (Fields of Block same as Int)

Failing that, we can return to sending a single string like so:

OutputString

its the same but with wilder numbers getting longer the longer i moved the slider

im going to try the single string now

1 Like

aw man, more gibberish

this is the code block

here's the snippet of the code

if(Serial.available()>0){
String Secondinput = Serial.readStringUntil('\n');
Serial.print( "SecondInput(" );
Serial.print( Secondinput );
Serial.println( ")." );
int RealServo = Secondinput.toInt();
Serial.print("Real Servo = ");
Serial.println(RealServo);

also i want to ask why "\n" is strung in with thumbposition? whats "\n" for?

That should be write strings!

(and read until \n in the Sketch)

It signals "end of string" for Serial.readStringUntil('\n');

Something Else:

To use Serial.available(), you must include the Software Serial Library.

Simplified Sketch for testing (if the last test with your Sketch also failed)
Note, enter the pin numbers for the AT-09.

BLE_ReceiveString.ino (1.9 KB)

.... but it's nice looking gibberish :grimacing:

I wonder if the Slider.PositionChanged event is firing too quickly one after another.

That could be factored out as a test by moving the PositionChanged blocks to a test Button.Click event, working off the Slider.thumbPosition value.

1 Like

oh sorry i was doing this at 1am

ALMOST THERE

"SecondInput" is picking up the right values, all i need to figure out now is why its converting into 0 in RealServo

if(Serial.available()>0){
String Secondinput = Serial.readStringUntil('\n');
Serial.print( "SecondInput(" );
Serial.print( Secondinput );
Serial.println( ")." );
int RealServo = Secondinput.toInt();
Serial.print("Real Servo = ");
Serial.println(RealServo);

so i tried to use atoi() but people online said that i have to convert the string to a charracter array, and yeah they were right

heres the toCharArray() definition on the arduino website

Syntax

myString.toCharArray(buf, len)

Parameters

myString : a variable of type String.
buf : the buffer to copy the characters into. Allowed data types: array of char.
len : the size of the buffer. Allowed data types: unsigned int.

i dont know what these parameters do

here's my code

if(Serial.available()>0){
String Firstinput = Serial.readStringUntil('\n');

Serial.print( "first input(" );
Serial.print( Firstinput );
Serial.println( ")." );

Firstinput.trim();

int Secondinput = Firstinput.toCharArray();
int RealServo = atoi(Secondinput);
Serial.print("Real Servo = ");
Serial.println(RealServo);

You shouldn't really declare variables in the loop, that takes up more memory each time. Your Sketch has plenty of space left for some global vars.

Can the issue with RealServo = Secondinput.toInt() be as per the Arduino Reference - Secondinput does not start with a number? The Serial Monitor seems to say it's fine.

You go to a lot of trouble decorating the results, it's better to keep it simple so that it's easier to spot issues.

Could you send the Real Servo value from the App and still identify which servo by the value range?

you mean just use the string value for the rest of the code?

edit : just tried it, nope it needs to be an int

Yes, but a better idea, try this:
RealServo = 0;
RealServo = (RealServo + Secondinput.toInt());

so it works, kind of

it works when i only tapped the slider, as you can see servo 1 is activating

but then it returns symbols when slided

if(Serial.available()>0){
Secondinput = Serial.readStringUntil('\n');

Serial.print("second input = ");
Serial.println(Secondinput);

RealServo = 0;
RealServo = (RealServo + Secondinput.toInt());

Serial.print("Real Servo = ");
Serial.println(RealServo);