it cant convert int to string
as you can see on the bottom it says unable to convert 1164 (the value of thumbposition) to list
it cant convert int to string
as you can see on the bottom it says unable to convert 1164 (the value of thumbposition) to list
A List is not an integer - show us your code
i know its not, im not trying to convert to an integer, the integer is the rounded thumbposition and sending it through writeString doesnt convert it a string
heres the arduino code
#include <Servo.h>
#define servo1 2
#define servo2 3
#define servo3 4
#define servo4 5
#define servo5 6
Servo Mservo1;
Servo Mservo2;
Servo Mservo3;
Servo Mservo4;
Servo Mservo5;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Mservo1.attach(servo1);
Mservo2.attach(servo2);
Mservo3.attach(servo3);
Mservo4.attach(servo4);
Mservo5.attach(servo5);
Mservo1.write(90);
Mservo2.write(90);
Mservo3.write(90);
Mservo4.write(90);
Mservo5.write(90);
pinMode(servo1, OUTPUT);
pinMode(servo2, OUTPUT);
pinMode(servo3, OUTPUT);
pinMode(servo4, OUTPUT);
pinMode(servo5, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
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);
if(RealServo >= 1000 && RealServo <= 1180)
{
int Servo1Input = RealServo;
Servo1Input = map(Servo1Input, 1000, 1180, 0, 180);
Mservo1.write(Servo1Input);
Serial.print("servo 1 = ");
Serial.println(Servo1Input);
}
else if(RealServo >= 2000 && RealServo <= 2180)
{
int Servo2Input = RealServo;
Servo2Input = map(Servo2Input, 2000, 2180, 0, 180);
Mservo2.write(Servo2Input);
Serial.print("servo 2 = ");
Serial.println(Servo2Input);
}
else if(RealServo >= 3000 && RealServo <= 3180)
{
int Servo3Input = RealServo;
Servo3Input = map(Servo3Input, 3000, 3180, 0, 180);
Mservo3.write(Servo3Input);
Serial.print("servo 3 = ");
Serial.println(Servo3Input);
}
else if(RealServo >= 4000 && RealServo <= 4180)
{
int Servo4Input = RealServo;
Servo4Input = map(Servo4Input, 4000, 4180, 0, 180);
Mservo4.write(Servo4Input);
Serial.print("servo 4 = ");
Serial.println(Servo4Input);
}
else if(RealServo >= 5000 && RealServo <= 5180)
{
int Servo5Input = RealServo;
Servo5Input = map(Servo5Input, 5000, 5180, 0, 180);
Mservo5.write(Servo5Input);
Serial.print("servo 5 = ");
Serial.println(Servo5Input);
}
}
}
wrap the thumb position with a MAKE A LIST block.
is this right?
.... I meant you App code
If you are using Serial.readStringUntil() in the Sketch, the value sent by the App can only be a single String, not a List (not an array).
So you have tried this:
... and it results in the error you reported?
No, because your Sketch Code is processing only 1 string, not a List of Strings
yeah, how do you make it a string instead of a list?
The WriteStrings Block will send a single string or a List of strings. If you don't want a List, send a single value - or change how the data is received/processed in the Sketch.
Arduino C does not have particularly good string splitting functions.
is this really the best way of going about things? cant i just send it as an integer and read it also as an integer in the arduino code? the only problem with that is that it reads wrong
cant we just try to fix that?
First things first, did you try my App code snippet? Error or OK?
its an error
Please download and post each of those event block(s)/procedures here ...
(sample video)
Back to basics:
Please answer these question just as I have listed
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)
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: