Arduino + Python: External commands

Hi everyone!

I've a question: It's possible execute system commands from Arduino to PC using python and serial port?
For example, after I pressed a button in Arduino, one LED turn on and, using python, create a .txt file with string "LED on"? It's possible?

I know in inverse, send commands from python to arduino from pyserial, but from arduino to python I don't know if it was possible.

Waiting for an answer.

Best Regards.

You write Python code to read the serial port. You write Arduino code to write to the serial port.

Yes, but my question is: How I programme an arduino event to call a python script?

I can send commands from python to arduino, but not in reverse.

This Python - Arduino demo may help.

You can just send data from the Arduino with the usual Serial commands

...R

Thanks!

I'll check

I've an Idea: If I create a new library in C/C++ to execute system commands?

MacgyverPT:
If I create a new library in C/C++ to execute system commands?

What has that got to do with your original question?

In my opinion it would be easier to use Python.

...R

MacgyverPT:
I've an Idea: If I create a new library in C/C++ to execute system commands?

To be used where? The Arduino doesn't have an operating system, so executing operating system commands doesn't make sense.

Building a new library for use on the PC is an admirable task, but completely unrelated to the Arduino.

To be used in arduino, like another libs we have on own sketch.

I know the Arduino doesn't have an Operation System.

MacgyverPT:
To be used in arduino, like another libs we have on own sketch.

This may make sense to you but not to me, based on the other information you have provided in this Thread.

...R

@MacgyverPT

I think everyone has pointed you in the direction you nee to pursue...

Your C/C+ comment doesnt make sense to me either..??

The arduino has the built in ability to send data to the serial port.... (why are you trying to re-invent the wheel?)

The connection between Arduino and Phyton script is the serial port itself..

You can either:

send data FROM Python TO Arduino..
or
send data FROM Arduino TO Python..

once the data has been received at its 'end point'.... that end point has to 'do whatever its programmed to do' with the data that was sent.

If you send a 'command' to Arduino from Python... how do you expect the Arduino to 'execute a system command'..???

Same with vice versa... if you send a 'command' from Arduino to Python... can python do what you want/intend it to do?