0

I have connected my Arduino to the USB and I want to read data from it, but also to send commands through serial.

The problem is that it prints to the terminal what the Arduino sends, but not until I send command from the PC. I searched over other posts, and this happens because the input is blocking. I have read many posts on stackoverflow, such as this: link_1

but everything I tried from there, does not work. I found this post: link_2

but I have problem with termios, and as I searched it does not cooperate with windows. Is there any way to make the code work without blocking and waiting from the input to write something? I started learning python programming python a few weeks, so maybe I missing something from code.

  • What issue did you have using the msvcrt module? – Tom Sitter Feb 06 '18 at 14:50
  • Does the mscvrt module work on its own if you remove all the Arduino code? – Tom Sitter Feb 06 '18 at 15:22
  • I execute this code: import msvcrt while True: if msvcrt.kbhit(): print("you pressed",msvcrt.getch(),"so now i will quit") ser.write("you pressed",msvcrt.getch(),"so now i will quit") but I don't see any reaction to the arduino nor to the python shell.... –  Feb 07 '18 at 10:30
  • I use this code: import msvcrt while True: if msvcrt.kbhit(): ch = msvcrt.getch() if ch in '\x00\xe0': # arrow or function key prefix? ch = msvcrt.getch() # second call returns the scan code if ch == 'q': print("Q was pressed") elif ch == 'x': sys.exit() else: print("Key Pressed:", ch) from here: https://stackoverflow.com/questions/22365473/python-windows-msvcrt-getch-only-detects-every-3rd-keypress in python 3.5 but it does not work.Does it need any extra commands for python 3.5? –  Feb 09 '18 at 12:27
  • Replace the `set.write` with `print` to see if it comes in the python terminal – Tom Sitter Feb 09 '18 at 18:59

0 Answers0