python - Send data to Arduino on keypress Raspberry Pi -
i'm trying build car (wild thumper) can drive raspberry pi. i'm using raspberry pi on ssh. should send data arduino knows when has go forward or when turn.
i've tried making scripts called jquery (apache on pi) , send integer on serial port requires delay , not ideal. (example forwardstart.py:)
import serial ser = serial.serial('/dev/ttyacm0', 9600) ser.open() # here delay needed ser.write('4') # go forward ser.close()
to solve tried looking single python script read keyboard , send correct integer. however, keylisteners require display , can't used on ssh.
can me python script or idea works?
thanks!
you should start reading here. idea like
import serial ser = serial.serial('/dev/ttyacm0', 9600) ser.open() # here delay needed try: while 1: try: key = sys.stdin.read(1) # wait user input actionkey = key2action(key) # translate key action ser.write(actionkey) # go forward except ioerror: pass finally: ser.close()
note: code fail, it's more pseudo-code illustrate idea.
Comments
Post a Comment