Arduino to python serial read split


Question

Hi I am staring out and have cracked sending multiple bits of information from Python to my Arduino. I now would like to send information from my Arduino to python I have looked at may examples but they all send to show only one line of information being sent.

his is what i am stuck with.The Arduino is sending a start number 255 then an ID then the information it looks like this on the terminal window.

255  start chr

1    ch ID

99   Value

I want to split these back into there individual arrays in python.

thanks for any tips.

1
0
2/25/2013 1:00:21 PM

Print the Arduino items into a line with a delimiter such as a comma like so:

  Serial.print(VALUE 1);
  Serial.print((" , "));
  Serial.print(VALUE 2);
  Serial.print((" , "));    
  Serial.println(LAST VALUE);

Using println for the last value will combine all previous print into one line. With Arduino Serial Monitor results something like this:

VALUE 1 , VALUE 2 , LAST VALUE

You can easily split the values in python and assign a variable to each value like taking values from an array:

SERIALDATA= sensorData.readline() #Read line of text from Arduino
DATASPLIT= SERIALDATA.split(' , ') #Splits the line of text into array of strings composed of each individual sensor data

pyVALUE1= DATASPLIT [0]
pyVALUE2= DATASPLIT [1]
pyFINALVAL= DATASPLIT [2]
1
3/24/2017 3:34:47 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon