0

How can I convert a string like the following:

"pinMode(2, INPUT_PULLUP)"

or

'Keyboard.print("Hello world")'

into actual code that the Arduino can act on?

1

You can't - not directly.

There are two things you can do:

  1. Build your "command" into a sketch and compile it, then upload it in to the Yun's AVR chip. The compiling will have to be done on your PC, and the HEX file uploaded to the AVR (you can do it directly through the Yun's web interface).

  2. Don't send sketch code, but send pre-defined instructions like "Turn on pin 3" which your sketch then interprets. That could be as simple as two bytes "P3" for instance. It's entirely up to you how you craft that.

Firmata might help with option 2 if uploading a new sketch every time isn't what you want to do.

4

There is a third option: install an interpreter on the Arduino, then just send it the program you want it to run. There are a few such interpreters available. A quick search showed:

There are probably many others.

The difference between this option and Majenko's option 2 is that this would allow you to send a complete program, with functions, conditionals, loops, etc., whereas with a Firmata or similar approach you would keep the program logic (functions, loops, conditionals) on the host computer, and only send simple commands to the Arduino.

0

You might also try the Firmata library, too. It provides similar functionality, and there are some libs for the computer side of it, if you are so inclined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.