Controlling LEDs based on program status - based in python controlled via USB??

I'm looking into a project and wanted a general idea if it's something within the capabilities the arduino can deliver.

Basically I've got a program in python which will check the status of some software. Based on that status I want it to alter LEDs which will be front mounted to the case.

Is it possible to send instruction to the arduino via USB from a python script?

Ideally (in my mind) I would program the arduino to check for flags of some type (I.e. if status = off then LED red = on) then based on the checks the python script would carry out, It would send the change to the arduino so it knows the flag has changed.

I have programmed for years I expect it's something in time I could learn but I wanted some general guidance on if it's doable and what route / hardware would be best.

http://arduino.cc/playground/Interfacing/Python

When attached to the computer the Arduino will act like a serial device, so standard serial libraries work just fine. The "Prototyping API" linked from the page above makes it especially easy to do.

Any Arduino with a USB interface would be fine for a project like this.

One caveat: When the Arduino serial port is opened by your Python program, the Arduino will reset.

I strongly agree with @Chagrin. Arudino and Python go very well together.

Based on the advice I’ve done a little research and found a section of code for both the Arduino and the python script which sends a value to the Arduino via serial and get a LED to flash x amount of times. I’m pretty sure I can based my script around this.

Few questions if I can

  1. Is there a maximum number of LEDs any given Arduino can support? (part of my project is a circular set of 8 LEDs which will flash in a pattern to create a circular rotating light) Ideally to keep options open I could do with allowing 12 LED’s to be individually controlled.

  2. When doing a little research I came across a comment suggesting that you can bridge something on the arduino unit to disable to unit from resetting on serial connection? Is this true? Would there be any real advantage in this? realistically what kind of time does the unit take to reinitialise to accept another instruction via serial?

Any advice on which unit is maybe most suitable or one to avoid? Ideally I’m looking for minimal cost that will get the job done :stuck_out_tongue:

Dynamis_dk: 1) Is there a maximum number of LEDs any given Arduino can support?

Yes. In total the processor can handle 200 mA. Each pin has an absolute maximum rating of 40 mA but a good rule of thumb is to keep the current below 20 mA. There are per-port current limits as well. Obviously, you are also limited by the number of pins.

If the 12 LEDs can be all lit simultaneously, using the per-pin limit of 20 mA, the processor current would be 12 * 20 = 240 which is too much. This would very likely also exceed per-port limits. If you keep the per-pin current below 10 mA, 12 * 10 = 120 mA you should be fine.

2) When doing a little research I came across a comment suggesting that you can bridge something on the arduino unit to disable to unit from resetting on serial connection? Is this true?

Yes. 10 uF or higher capacitor for the Uno. 120 ohm resistor for the Duemilanove. Or, cut the RESET-EN trace with a knife.

Would there be any real advantage in this?

Yes. When the processor resets all the data is cleared to startup values. By disabling RESET you can have a program with state.

realistically what kind of time does the unit take to reinitialise to accept another instruction via serial?

Approximately one second.