1

Here, I am able to sent data from Arduino to python. But, here Arduino sent data of TWO variable A0 and A1. And in python side, this all data store in one variable named data. Now how can I split data of A0 and A1 from data in python ?

Arduino Code :

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int A0 = analogRead(A0);
  int A1 = analogRead(A1);

  Serial.print(A0);
  Serial.print("\t");
  Serial.print(A1);
  Serial.println();
}

Python Code :

import serial

arduino = serial.Serial('COM12', 9600, timeout = .1)

while True:
    data = arduino.readline()

    if data:
        print data
0

1 Answer 1

1

It has nothing to do with Arduino; you just need to split a string (data) into multiple (2) integers.

So a0, a1 = map(int, data.split()) will work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.