No kidding.
wow. What a revelation! Thank you so much!
i guess you missed the point
you're suggestion to the OP that monitoring the serial interface must be "constantly looping" doesn't explain the timing nor that other thngs can be doen within loop().
it seems many OPs don't really understand how fast even the relatively slow Arduino processor is and how much is can do.
i did say "And you understand" implying that you do, but maybe the OP does not.
Is it possible to store seldom used functions (subroutines) in EEPROM and run it by calling it thru SERIAL MONITOR? From previous statements in this post, looks like a yes.
@barryfields
How about pointing to those statements, so we can see what you've misinterpreted?
I guess I took this too far. Sooo, if a function (subroutine) can fit in ram, then what would it take to store it in eeprom and call it out later?
The function I was describing in that post would be part of your code, uploaded before runtime. The serial monitor is sending characters; the code interprets those characters to initiate functions that act on the dataset in it's memory, or EEPROM. You don't store the functions in EEPROM, it's just data that is manipulated.
There was no suggestion that code was stored in EEPROM, nor that code that resides there can be run.
There was no suggestion that code was stored in EEPROM, nor that code that resides there can be run.
So, it cannot be done? I have seen references to using a boot loader to accomplish this. I do not know if it is advisable or worth it.
I am trying to learn stuff.
I don't know that it can't be done, though I suspect not. However, I'm having a hard time coming up with a viable use case. For example, a routine that one might download via Serial and store in EEPROM doesn't have much use in the rest of the code, unless it already knows about variable locations in that code, which would likely require, at a minimum, that it have access to variable definitions known at compile time, and address allocations often not known until the linker gets invoked. In that case, just write a new version of the code. So, describe your hypothetical use case to me, and I'll see if I bite.
Is it possible to store seldom used functions (subroutines) in EEPROM and run it by calling it thru SERIAL MONITOR? From previous statements in this post, looks like a yes.
this diagram shows that EEPROM is only accessible from the peripheral data bus while code and variabls in SRAM are accessed thru separate buses.
An example would be a diagnostic program that would check the viability of the modbus, I2C buss and SPI buss and the specific devices on those busses. It would only be used to diagnosis problems.
There are peeps here that know a whole lot more than I do. All I can do is ask dumb questions that might spark some creativity.
In Windows, I can run a program from a USB stick (eeprom). Is there a way to make the 2560’s eeprom look like a USB stick? Could one loop the eeprom “program” out one uart port and back into another?
Could the seldom used “program” be better stored on the SD card?
I am not edumacated enough to know how far afield these questions are.
Thanks for your patience
Yes, there is a lot, what atmega2560 can do, but maybe in little different way ![]()
- It can store data in EEPROM - else by reprogramming it, or the running program can store the data anytime. (there is guaranteed Write/Erase Cycles:10,000 Flash/100,000 EEPROM)
- it can store data in RAM and act on it (which is temporary)
- it can store and retrieve data from the SD card (which is slow, but may be huge configuration)
- if you change your bootloader, it can even reprogram its FLASH on the fly, by pages, without reboot
- and it can reboot and continue in the program, if programmed so
But there are some things you should know (about ATmega series) :
- it can run program only from FLASH memory (as the program counter cannot possibly point anywhere else. It is HW limitation. It is modified Harward architecture)
- only program in “bootloader area” may write into FLASH
- program may write to EEPROM (which is slow and limited number, but survive power down) and to RAM (fast, does not survive)
- the program may read RAM, EEPROM and FLASH and act on the values
- via SPI (and other protocols) you can read and store data on external devices, like SD card
- Serial connection is one of many ways how to communicate with the program
You can write program, which would interpret commands and configuration in really sofisticated ways.
I have this project going MHF-002 (Mega Home FORTH) | Hackaday.io where I am using ATmega2560 too, and it runs FORTH (but you may implement anything else, like BASIC for example). I am slowly writing documentation there, like 2 chapters per week or so, now I am at 1/2 of HW part, the SW will follow later. But there is also link to github, where the SW is residing now.
There is a lot of functions stored in FLASH and there is configuration (“program”) stored in RAM, which directs, what functions and how are called. It can be saved to the SD card and loaded later, it can save its data there too (as many values as fits on SD - much more, than can be realistically used)
It can communicate via Serial, or via PS/2 keyboard and VGA monitor (which needs PE7 pin, it is not connected on Arduino Mega, so I made my own PCB for it).
I can upload new data and FORTH programs over Serial, via PS/2 or from SD card anytime without rebooting and it then acts on it.
(And I connected even more RAM there, so instead of 8kB it may use 64kB native and another 128kB+64kB + 8kB by other ways - lot place for values
)
Yes, it can be done somehow (both SD card and EEPROM ), but you need different approach.
You cannot run the code there, but you can interpret it and obtain similar result.
In Windows, I can run a program from a USB stick (eeprom). Is there a way to make the 2560’s eeprom look like a USB stick?
all programs on a PC based OS are stored in a file system and copied into RAM for execution. The PC accesses programs for execution, variables and peripherals through the same bus. the Arduino processor had several different buses and is designed to execute out of it's flash memory.
even though both its flash and EEPROM may use the same technology (flash memory), they are on different buses that do not allow execution from the peripheral data bus that the EEPROM is accessible from.
Is it possible to store seldom used functions (subroutines) in EEPROM and run it by calling it thru SERIAL MONITOR?
it's hard for me to imagine running out of code space for programs. almost all my programs use a function that processes commands invoked thru the serial monitor customized for the application. i often use it to exercise sub-functions during developement and add diagnostic functions for testing
of course it helps to write efficient code and avoid redundant code (e.g cut&paste)
Here is one of my previous models running from Arduino Nano (on right side on breadboard) - https://github.com/githubgilhad/NanoHomeFORTH - it runs from FLASH, but you may enter your own code (from the keyboard under breadboard), that is stored in RAM and interpreted.
Here is the actual code:
: ascii 0 BEGIN DUP EMIT 1 + DUP 256 - 0= UNTIL DROP ;
the command show decode it from internal presentation (top part of screen), on the bottom part of screen you can see, that I entered the command ascii and it executed and printed all characters on the screen.
Other commands can use all previously defined commands (buildin as well as in RAM). With SD card it can be used to store more new commands.
: ascii 0 BEGIN DUP EMIT 1 + DUP 256 - ==0 UNTIL DROP ;
This is in FORTH language, which uses stack for all parameters and results, here is step by step explanation:
: define new word (function)
ascii name of the new word
0 push zero on stack (it will be counter in the cycle)
BEGIN start cycle block
DUP copy top item on stack (now there is two number on the stack)
EMIT pop number from stack, show it as character
1 push number one on stack
+ pop 2 numbers from stack, add them, push result on stack (we just increased counter)
DUP copy the counter on stack
256 push number on stack (0x100 hexadecimal)
- pop 2 numbers from stack, subtract them, push result on stack
==0 test if top of stack is zero
UNTIL if it was not, run cycle again from BEGIN
DROP pop the counter from stack and discard it, so nothing is left there
; end of definition
basically it is roughly equivalent of something like that in C
void ascii () {
for (int i = 0 ; i != 256 ; i = i + 1) {
Serial.write(i);
};
}
and it is stored in RAM on Arduino and it is still executed, as can be seen on the picture (I was testing it, it could written better). And it could be stored on SD card (if there would be one) and retrieved later and executed again
Thank you all for your input. A lot to digest.
I apologize for my absence. Long story short:
I was hospitalized in mid December for dramatic digestive issues (complicated with advanced prostate and bone cancer). After 3 weeks, the decision was made to put me on hospice and send me home to die.
Fortunately, my family and close neighbors said ”Oh no you don’t”. They all took turns giving me 24/7 support. Over the next 2 months, they encouraged me, fed me, wiped my butt and nursed me back to some semblance of normalcy. I still have a long trek back.
Thanks be to God for my extended family for without them I would not be here.
I wish to continue my Arduino SOLAR project as it helps keep me alive. I can only ask for your patience and continued support.
Bless ya’ll

