I was wondering if its possible to send code to the Arduino, and then have it execute this code.

What I'm trying to do is use an Arduino Mega with a bunch of stuff connected to it send code to an Uno with a TFT LCD display to do whatever the Mega tells it to do with the Adafruit GFX Library. I want to add things to this 'system' gradually so I want the whole program hosted on the Arduino Mega, and a minimal amount of code on the Uno.

Sorry I'm really new at this so if its not possible at all let me know!
Thanks in advance,


  • Just send the GFX commands (and arguments) as text using serial, and have the UNO parse this text and call the appropriate GFX function. But why would you need two micro controllers? Can't you have the Mega do the TFT stuff too?
    – Gerben
    Aug 31 '15 at 19:44
  • Sending code over serial is what the bootloader does. However this is a once-off for a given moment. It doesn't interactively execute code. You could send commands over serial to a device with a LCD display on it (eg. display "Hello, world").
    – Nick Gammon
    Aug 31 '15 at 20:46

No, it's not possible as you describe it.

The Arduino's main chip, the ATMega328p, is what is known as Harvard Architecture. This means that the Flash memory and RAM both occupy completely separate memory address spaces. The CPU in the chip is only able to fetch its instructions from the memory space the Flash is connected to (the Instruction Bus) and not the memory space the RAM is connected to (the Data Bus). This means it can only run instructions that are in Flash and not RAM.

It is possible to re-program the flash on the fly - after all, that's what the bootloader does, and while the actual act of reprogramming flash is fairly trivial, generating the instructions in the right way is far from trivial.

There are other options though.

  1. Use an interpreted language. I believe there are versions of BASIC available for the Arduino that would allow you to upload a program through the serial port and execute it.
  2. Define a protocol (or use an existing protocol) to send pre-defined control commands to the Uno. Firmata might be of use here.
  • Thanks for your help, that helps out a lot! Theres not to many functions in the Adafruit GFX library, so I could probably create a protocol to do all of what I'm looking for... Don't know why I didn't think of that. Thanks so much for your help! -Will
    – Will
    Aug 31 '15 at 20:55

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.