I writing a gamepad serial-driver for Arduino UNO, so, in Arduino IDE coord resives good. But in PySerial adding b' and \r\n' in the end. I added replace()
, but nothing changed...
There is code:
import pyautogui, sys
import time
import serial
ArduinoSerial=serial.Serial('/dev/ttyUSB0',115200) #Specify the correct COM port
time.sleep(1) #delay of 1 second
a = 1
while a:
ArduinoSerial.readline()
print(ArduinoSerial.readline());
data=str(ArduinoSerial.readline())
data = data.replace("\r\n", "")
print(data)
(x,y)=data.split(":") # read the x and y axis data
(X,Y)=pyautogui.position() #read the current cursor's position
x=int(x)
y=int(y)
pyautogui.moveTo(X+x,Y-y) #move cursor to desired position
There is output:
ilyabot@ilyabot-HP-Pavilion-dv6-Notebook-PC:~/Рабочий стол$ python3 joy_driver.py
b'0:0\r\n'
b'0:0\r\n'
Traceback (most recent call last):
File "joy_driver.py", line 21, in <module>
x=int(x)
ValueError: invalid literal for int() with base 10: "b'0"