How do I read keyboard input without waiting for the user to press Enter?
How do I read keyboard input without waiting for the user to press Enter?
Hi,
I want to print character in i2c LCD display from keyboard through pi pico. But the issue is in input() and sys.stdin.read(1) character is not getting visible until ENTER button is pressed.
Kindly help...
I want to print character in i2c LCD display from keyboard through pi pico. But the issue is in input() and sys.stdin.read(1) character is not getting visible until ENTER button is pressed.
Kindly help...
Re: How do I read keyboard input without waiting for the user to press Enter?
It may as well be that the character is not sent from the PC until you push enter. Which terminal program do you use to connect to the Pi Pico, and how is it configured, I use sys.stdin.read() in my on-board editor for exactly reading character key by key. (see https://github.com/robert-hh/Micropytho ... pye_gen.py, line 24, https://github.com/robert-hh/Micropytho ... ter/pye.py, line 274 ff).
input() waits indeed on the Pi Pico side until an enter key arrives.
input() waits indeed on the Pi Pico side until an enter key arrives.
Re: How do I read keyboard input without waiting for the user to press Enter?
I'm using Thonny IDE connected to Pi Pico
Re: How do I read keyboard input without waiting for the user to press Enter?
I do not know how thonny handle it's REPL window. You could try to use a simple terminal emulator for REPL, like putty or TeraTerm (windows) or picocom (linux, raspbian) or screen (mac). These are known to send single keystrokes.
Re: How do I read keyboard input without waiting for the user to press Enter?
Thonny only sends when 'return' is pressed. As suggested, use a terminal program which sends each key as pressed.
A more advanced option is to build your own MicroPython firmware with an additional USB Virtual Serial Port so you can read from that using a terminal program while still having access to the full REPL.
I build my MicroPython with three USB Virtual Serial Ports; one for the REPL, one for raw data comms, the other for diagnostics, logging, whatever.
https://www.raspberrypi.org/forums/view ... p?t=305834
A more advanced option is to build your own MicroPython firmware with an additional USB Virtual Serial Port so you can read from that using a terminal program while still having access to the full REPL.
I build my MicroPython with three USB Virtual Serial Ports; one for the REPL, one for raw data comms, the other for diagnostics, logging, whatever.
https://www.raspberrypi.org/forums/view ... p?t=305834
Re: How do I read keyboard input without waiting for the user to press Enter?
@hippy Excellent idea.
Re: How do I read keyboard input without waiting for the user to press Enter?
Thanks for the suggestion.
Now I tried to connect a USB keyboard to pi pico and pressed a character to get it displayed on the i2c LCD screen using sys.stdin.read(1) but shows nothing.
Now I tried to connect a USB keyboard to pi pico and pressed a character to get it displayed on the i2c LCD screen using sys.stdin.read(1) but shows nothing.
Re: How do I read keyboard input without waiting for the user to press Enter?
You have to use a terminal emulation program like Putty for the test. I would not expect a directly attached keyboard to work. It would not be powered, and it will definitely not send ASCII or UTF-8 character codes itself. And the rp2 must operate in host mode. Did you manage to set it as such?
Re: How do I read keyboard input without waiting for the user to press Enter?
Hi,
I've attached a 5v supply to VSYS so the USB keyboard is getting power the only issue is how to use Pi Pico in USB host mode.
I've attached a 5v supply to VSYS so the USB keyboard is getting power the only issue is how to use Pi Pico in USB host mode.