+ 12

I am sending an Encoder value using Arduino ATMega168 with serial port and I am receiving the value in raspberry pi using

I am sending and Encoder value using Arduino ATMega168 with serial port and I am receiving the value in raspberry pi using python serial, before decoding format was in this form: b'\n' b'\r\n' b'0\r\n' When we decoded the data the value at the end contained note symbol. Now everything is good, but when we rotate the POT encoder anticlockwise, Arduino sends negative values, but our python program receives only "-" sign. So how do we receive negative values properly? import serial import time, threading import RPi.GPIO as GPIO def slider_encoder(): ser=serial.Serial("/dev/ttyUSB0",9600) #change ACM number as found from ls /dev/tty/ACM* ser.baudrate=9600 GPIO.setmode(GPIO.BOARD) #GPIO.setup(11, GPIO.OUT) while True: #do while read_ser=ser.read() if all(i not in (10, 13) for i in tuple(read_ser)): read_ser = read_ser.decode("utf-8") break print(read_ser) ## #### print("#########$

quot;) ## print(read_ser) #s#len_read_ser=len(read_ser) #s#read_ser=read_ser.decode('utf-8') #print(read_ser, "0" in read_ser) ## exit() #s#for i in range (len_read_ser): #s# if(read_ser[i]>"0" or read_ser[i]<"9"): #s# read_ser[i].translate({ord('a'): None}) #s#print(read_ser) ## print("$
quot;) #s#read_ser=read_ser[:len(read_ser)-3] ## print(read_ser) GPIO.setmode(GPIO.BOARD) ## GPIO.setup(11, GPIO.OUT) #s#if(len(read_ser)==2): #s# read_ser=read_ser[:len(read_ser)-1] ## read_ser=ser.readline() #s# read_ser=read_ser.decode('utf-8') #s#read_ser=read_ser[:3] ## print(read_ser) global sliderValue if "eme" == read_ser : print("diconnect") RobotController.disconn(self) elif(read_ser=="up"): #def select_up: pass ## RobotController.disconn(self) elif(read_ser==r"b'emer\\r\\n'"): pass ## RobotController.disc

11th Jun 2019, 4:53 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
1 Antwort