Author Topic: Can you run code that lives on a connected EEPROM shield?  (Read 5014 times)

TylerB

  • Newbie
  • *
  • Posts: 1
Can you run code that lives on a connected EEPROM shield?
« on: September 06, 2012, 09:37:49 pm »
I want to make a complex-ish pair of little robot people, and I'm worried I won't be able to fit all of their instructions on the digispark. I wanted to know if I can put code on the eeprom and execute it to run patterns on an LED Grid or sound a buzzer based on a complex set of rules written on the eeprom.
Thank you for your time, I'm new to Arduino and appreciate the help!
« Last Edit: September 06, 2012, 09:37:49 pm by TylerB »

Dennis

  • Newbie
  • *
  • Posts: 15
Can you run code that lives on a connected EEPROM shield?
« Reply #1 on: September 08, 2012, 04:22:01 am »
NO!!! The ATtiny is using a Harvard architecture, which means that you ARE NOT able to store instruction code in your RAM/EEPROM! RAM and EEPROM are only data memory, NOT instruction memory!
Ok, that\'s only 99.9% the truth. There is one possibility to store instruction code in EEPROM. You have to translate every instruction to its binary representation and store this like a number to your EEPROM. To execute these instructions, you have to copy the binaries from your EEPROM to your Flash memory and manually jump to their Flash address.
As you can see it\'s a very very complex approach. A more easier way to solve memory problems is to use assembly instead of Arduino C programming. Assembly code is about 10 to 100 times SHORTER and FASTER than its C equivalent. Unfortunately assembly programming is a little bit more difficult than programming in C.

sparr

  • Jr. Member
  • **
  • Posts: 70
Can you run code that lives on a connected EEPROM shield?
« Reply #2 on: September 09, 2012, 06:16:59 pm »
10 to 100 is a severe exaggeration, even if you\'re using the slow Arduino I/O functions.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Can you run code that lives on a connected EEPROM shield?
« Reply #3 on: November 03, 2012, 06:52:03 pm »
It\'s fairly easy to make a little interpreter, but it\'s rather time consuming and if you\'re new to computer science, kind of tricky to understand. If you find your instructions don\'t fit, you can always switch to a little arduino or teensy later. There is also a lot of space you can reclaim by not using the arduino software, and writing code using the avr libc stuff, but this is a bit more difficult, especially if you\'re new to C.

You can also get help on the forum if you just need to cram a little more functionality in to a program. I\'ve gotten pretty good at cramming lately and am happy to give some tips if you share your code later, as I was recently challenged to make a program as small as possible!

SteveT

  • Newbie
  • *
  • Posts: 4
Can you run code that lives on a connected EEPROM shield?
« Reply #4 on: November 17, 2012, 08:14:59 am »
The new Arduino Due or Teensey 3 have a lot more program space and run faster.

If you search the Arduino forums there are several threads about saving code space. A couple of the tricks I remember:

Don\'t use libraries if you can do the same thing in a small piece of code or function.

String constants can really add up, such as debugging messages to spit out to the serial port. Comment out debugging print statements after that section of the code is working. If you need to send lots of long messages, or if you have a bunch of data that is needed, don\'t hard code it in the program. Put it in EEPROM or on an SD card and have the program read the data as needed.