NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Python script to drive an LED from the PC

July 08, 2010
by lcruz007
lcruz007's Avatar

Hi,

I am working on a simple project in which a python script will help the user interact with the MCU from the computer. The python script should drive an LED on and off depending on what the user writes and sends to the serial port.

However, I need the enter key to be automatic... That means that the user would only have to write the word, and then he or she would just wait a few seconds until the program presses the enter key by itself.

I don't know very well this language, so how do I do that with python? :p

I am using the raw_input() function, so that's why I am asking about the enter key... However, if you have any other suggestion, don't hesitate to share your idea!

Thanks in advance.

July 08, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi lcruz,

Most systems that take input from the console will wait for the user to press enter before passing the text over to the calling program, and unfortunately there are no good ways around it that I have found (if someone knows one, please correct me).

I think you pretty much have two options for what you want to do. You can try to get familiar with the python bindings for curses. Curses is basically the way to write terminal applications.

At that point however, it seems better to just go ahead and write a small GUI that captures the keyboard input, and then you can do whatever you want with it (as well as have the ability to present buttons, and other widgets to your user). There are many GUI modules for Python, I recommend PyGame. They have plenty of tutorials and great documentation.

Hope that helps.

Humberto

July 12, 2010
by lcruz007
lcruz007's Avatar

Thanks for your suggestion!! I will try them.

I also found this: http://www.rutherfurd.net/python/sendkeys/

It simulates any key I want, on this case after an small lapse of time it will simulate the enter key. I am using that for now...

Post a Reply

Please log in to post a reply.

Did you know that NerdKits has been featured on Slashdot, Hack A Day, Hacked Gadgets, the MAKE blog, and other DIY-oriented websites? Learn more...