2

Using python3 and pyserial on a virtualmachine ,Ubuntu 17.10, Ran the code like this "User@user:$ python3 ardui.py".

I'm trying to get rid of the b' ... /r/n' just get text or string for example , I get this on python b' What's 9+10? /r/n' but Im trying to get only the "What's 9 + 10?" how can i get rid of the other text ?

int PB = 2;  //Its just a button that when pressed it gets store in the variable buttonState

void setup(){
Serial.begin(9600);
pinMode(PB, INPUT);
}

void loop(){
int buttonState = digitalRead(PB):
if(buttonState ==1){
  Serail.println("What's 9 + 10");
  delay(10);
}
else
{
Serial.println("21!");
delay(100);
}
}

And the python code is this one:

import serial
arduinoSerialData = serial.Serial('/dev/ttyACM0',9600)
while (1==1):
  if (arduinoSerialData.inWaiting()>0):
    myData = arduinoSerialData.readline()
    print (myData)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
papisilv
  • 41
  • 1
  • 7
  • Possible duplicate of [Convert bytes to a string?](https://stackoverflow.com/questions/606191/convert-bytes-to-a-string) – Stephen Rauch Apr 23 '18 at 01:04
  • so it will be something like myData = arduinoSerialData.readline()(b') – papisilv Apr 23 '18 at 01:12
  • 1
    i'v seen people doing this thing at the end .strip() – papisilv Apr 23 '18 at 01:14
  • 1
    I finally got it working you were right, so for anyone new like me ,having the same problem here is the solution after myData=arduinoSerial.readline() i added .()strip so i'll be like this "myData=arduinoSerial.readline().strip()" – papisilv Apr 23 '18 at 15:24
  • 1
    Then I added a new line just below that one like this "LDecode = myData.decode('UTF-8")" and done got rid of it !! – papisilv Apr 23 '18 at 15:25

1 Answers1

0

Just perform a strip (which removes white space and line feeds) when you read it in:

    myData = arduinoSerialData.readline().strip()
ZENNON
  • 126
  • 1
  • 5