Is it possible to run a .lua file, or a .jar file?

Dang... If I were able to run a .Lua I would be able to interact with the computer and play .mp3s and such.

You can interact with your computer by sending serial commands, and writing a program that runs on the computer to listen to them and do stuff. The arduino doesn't have a lua interpreter, a python interpreter, or a JRE on it, though, and probably doesn't have enough resources to run one.

How would I send a serial command from arduino?

By defining a serial port with SoftwareSerial and sending the data... (RTFM... Read That Fine Manual)!

Doc

Docedison:
By defining a serial port with SoftwareSerial and sending the data

Er.. no... the hardware serial port will work fine.

The DigitalReadSerial example shows how to read a switch and then write to the serial port.

If you're new to things, I've heard gobetweeno lets your arduino run programs on your computer. Try checking that out. I've never used it, though.

I've tried gobetwino, doesn't work with windows 7..

Also, I saw a tutorial on youtube by Jeremy Blum about serial communication, and he did it using the language processor, and he said that you can interact with your computer from arduino using any programming language... Now, that being said it should be possible with Lua, so how can this be done with Lua?

nate890:
I've tried gobetwino, doesn't work with windows 7..

Also, I saw a tutorial on youtube by Jeremy Blum about serial communication, and he did it using the language processor, and he said that you can interact with your computer from arduino using any programming language... Now, that being said it should be possible with Lua, so how can this be done with Lua?

Many different ways. This is the whole reason for "Processing". If you want to do a mini Processing in Lua, start writing code. Write a Lua app that listens on a connection. When it gets something, it gets that something, parses it in some manner and then acts on the stuff it parses out.

Your question is infinitely general. You will get better results trying stuff out. Get the Arduino logging to a Java or Lua app that simply reports changes when you hit a button or something. Then build on that.

.<.
Let's say there is a .Lua file, named open.lua, with the following code:
os.execute([[start "" "C:\Users\User\Documents\Song.mp3"]])
When that code is ran, a .mp3 file, named "Song" will play.

And this is why I was asking if it was possible to RUN A .LUA FILE from ARDUINO, not make a .Lua file detect when I want code to run (which would be super hacky, and it being Lua, I don't even think this would be possible (what above suggested)) Which is why "Write a Lua app that listens on a connection. When it gets something, it gets that something, parses it in some manner and then acts on the stuff it parses out." is more easily said than done.

An arduino can not automagically do anything on your computer except fill up its serial buffer. Something has to be written to read that serial buffer and do something with the contents. Lua can read the serial port, so one script is all you technically need.

Also, "When it gets something", when it gets what? There is no way, with Arduino (that I know of so far) that would allow me to send something that would be detectable. For instance, if Arduino was able to create a file, I could loop until a file is detected then execute code. But then again, Arduino can't do this.

What should be done on the Arduino team's part is to create a function that can interact with your computer (as simple as os.execute(), or system() (in C), instead of inefficiently having to do it through other programming languages.

"Lua can read the serial port, so one script is all you technically need."
Do you know how this would be done? No need for code, just an explanation. Thanks.

nate890:
What should be done on the Arduino team's part is to create a function that can interact with your computer (as simple as os.execute(), or system() (in C), instead of inefficiently having to do it through other programming languages.

An arduino can ONLY send serial data to the computer, and nothing in the arduino's software can change that.

You could write something similar to bash that reads from the serial port rather than a keyboard, which would be a generic handler.

"Lua can read the serial port, so one script is all you technically need."
Do you know how this would be done? No need for code, just an explanation. Thanks.

Nope, never programmed in lua. Have you googled it?

"Nope, never programmed in lua. Have you googled it?"
Not yet, gotta go out, will when I get back.

nate890:
What should be done on the Arduino team's part is to create a function that can interact with your computer (as simple as os.execute(), or system() (in C), instead of inefficiently having to do it through other programming languages.

That's a feature of the operating system, not the Arduino; the OS doesn't give serial devices access to the API to launch programs.

You can do this directly with a leonardo, it can be made to look like a keyboard and so can type commands directly into your computer to run anything you want.

"That's a feature of the operating system, not the Arduino; the OS doesn't give serial devices access to the API to launch programs."

That's why I'd launch it through a .lua file with the code that I showed using os.execute from the arduinio... Technically I want something to trigger the .lua file to make it execute.

nate890:
For instance, if Arduino was able to create a file ...

On which disk drive? You send me a photo of the disk drive attached to your Arduino, and I'll tell you how to create a file on it. Deal?

nate890:
"That's a feature of the operating system, not the Arduino; the OS doesn't give serial devices access to the API to launch programs."

That's why I'd launch it through a .lua file with the code that I showed using os.execute from the arduinio... Technically I want something to trigger the .lua file to make it execute.

Launching a script requires the same API call as launching a program, so there is still the issue of serial devices not being able to launch "stuff"

@Nick, thanks for the offer, but I think I almost have it... :slight_smile:

So far I can send serial data using a library I found (for Lua) but I can't seem to read serial data sent from the arduino...

nate890:

.<.
Let's say there is a .Lua file, named open.lua, with the following code:
os.execute([[start "" "C:\Users\User\Documents\Song.mp3"]])
When that code is ran, a .mp3 file, named "Song" will play.

Sure, just write some Lua that talks to the Arduino over a serial port. When it gets a message it likes, it invokes this command. Of course, this is really a round-about way of starting your OS and install specific handler for the .mp3 filetype. You could just as easily have a Perl script do this; or a .bat file; or a C program.

Lua can do this just as easily as any other language.

And this is why I was asking if it was possible to RUN A .LUA FILE from ARDUINO, not make a .Lua file detect when I want code to run (which would be super hacky, and it being Lua, I don't even think this would be possible (what above suggested)) Which is why "Write a Lua app that listens on a connection. When it gets something, it gets that something, parses it in some manner and then acts on the stuff it parses out." is more easily said than done.

Nonsense. Lua is complete language that has all sorts of libraries and OS specific hooks for all sorts of purposes like this. And if it can't do it, it can call a chunk of C code to do it.

However, to reinforce the same answer everyone else has given you: no, you cannot run a Lua app "from" the Arduino. Mostly because the question doesn't really apply. But you /can/ have the Arduino talk to an agent on any computer you like, and that agent can pretty much do anything you can dream up, including running a Lua script. The agent can even be written in Lua.

The Arduino can be coded to transmit over a variety of connections, from the built-in USB serial port to more complicated ethernet, Wi-Fi or other wireless options if you buy the hardware.

But the fundamentals are the same: you write an app that sends (or receives -- the concept is the same) over the connection of your choice. Assuming you want to use the USB port, there are easy libraries and examples showing how to do this on arduino.cc. Just get it working with the built-in serial monitor available in the Arduino IDE first.

Then you can work on writing an app that listens (or alternately listens and talks) on the other end of that connection. Based on the messages it receives on that connection, it plays a song or whatever. A "message" is whatever you want it to be. A string you reconstruct. A byte pattern you apply masks to that encode all sorts of state. The actual steps for doing this is left as an exercise for the reader. My advice is to solve the problem in discrete steps.

Synchronous serial communication is not hard, but the devil is in the details. And there are countless examples out there.