I am trying to send integers over serial using the serial monitor in the ardunio IDE (then python from a raspberry pi after I debug using serial monitor), and can get single numbers to work with code below, but as soon as I use 10 or 100 it will automatically fill the next variable as 0. I have tried to use serial.readString
then convert to an int afterwards, but this is throwing an error also.
int varX = 0;
int varY = 0;
int varZ = 0;
int varCounter = 0;
void setup() {
Serial.begin(115200);
grabNewVars();
}
void grabNewVars()
{
while (varCounter < 3)
{
if (Serial.available() > 0) {
if (varCounter ==0)
{
varX = Serial.parseInt();
}
if (varCounter ==1)
{
varY = Serial.parseInt();
}
if (varCounter ==2)
{
varZ = Serial.parseInt();
}
varCounter++;
}
}
}
void loop()
{
Serial.println("varX = " + String(varX));
Serial.println("varY = " + String(varY));
Serial.println("varZ = " + String(varZ));
Serial.println("variables received, run main loop");
delay(100000);
}