Arduino Self-programming

Is it possible to use the arduino to read a text-file whose content is another arduino program code and reprogram itself using the new code obtained from the text-file?

Also, if anyone ever makes a commercial product that they prototype using the arduino then what do you do for the commercial version? Use just the atmega chip with the bare-bone components?

Sure, just need to rewrite the bootloader to retrieve code from sd card, instead of from the serial interface. This has been discussed before, I don't know that anyone has done it.

Nick Gammon has written a sketch to load hex programs from one arduino to another http://www.gammon.com.au/forum/?id=11638 and I have cards on order to that combines 328, regulators, SD card, 3.3V buffer into one little card to run that sketch, standalone with no PC needed (except to initially load .hex files onto SD cards), from battery or wallwart. One version will just load a single file named firmware.hex, and a 2nd version will allow selection of files named 00.hex up to ff.hex. That code is not created yet, waiting on board delivery to have a test bed.

Commercial, yes: Use just the atmega chip with the bare-bone components and other parts as needed.

twirap: Is it possible to use the arduino to read a text-file whose content is another arduino program code and reprogram itself using the new code obtained from the text-file?

If by "text-file" you mean human-readable source code, then no - you can't. If, however, you mean the binary compiled hex file - then yes, in theory you can, as CrossRoads mentioned. Modifying the bootloader isn't trivial - and incorporating a "bare-bones" (to keep the bootloader as small as possible) SD card reading routine just makes things more difficult - but not impossible.

I think something like this was done for the UzeBox, or maybe one of the "gameduino" devices out there...

...ah, a bit of googling will always do you wonders:

http://gamebuino.com/wiki/index.php?title=Bootloader

That reminds me on FORTH, which I used a lot on my old microprocessor systems. A complete FORTH system with editor, interpreter and compiler fits into a few KB of flash memory, and could compile source files to flash, just like a bootloader does.

A problem is the small RAM of many microcontroller chips, so that most current FORTH systems use cross compilation on a development system. I couldn't dig yet into the available FORTH systems, perhaps there exists one that does what we want.

could compile source files to flash, just like a bootloader does

The C++ files we use are all pre-compiled on the PC, the bootloader is just transferring the resulting hex files into memory. No interpreting at all. Think I missed some of the point you are making with Forth.

www.bitlash.net is an interpreter for Arduino.

Everybody can load binary files, that's only a matter of the applicable boot loader ;-)

The OP asked for loading from text files,that's why I remembered FORTH for that purpose.

Thanks for your link to bitlash, looks interesting as well :-)

Ok. I was reading "text-file whose content is another arduino program code" as being the hex file that would be installed.

You could write an interpreter that runs text.

You could write an interpreter that runs text.

I think that's what bitlash does. Example:

> print "Hello, world!", millis()
Hello, world! 11939
>

Looks like Basic.

One thing about interpreters, they make a lot of early lessons very easy to learn when run on a decent terminal. You can set up variables and try expressions on the command line before turning anything into a program. Check it, Use it, Run it. With arrays and logic, it does teach fast. OTOH, interpreter BASIC is slow.

I had something even more primitive than BASIC. I had a TI-59 calculator. For each program step it recorded 2 values as consecutive digits, the row and column of the button pushed -- that's an index into the microcode in human-readable form. That could maybe be emulated easier than a Basic interpreter with expression decoder. Every user-code step is what button to push next. Thing is, what buttons for the basic AVR set?