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?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.Sign up to join this community
You can't - not directly.
There are two things you can do:
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).
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.
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.