SD card as an arduino "hard drive"?

Hard drive is the best way to explain what I want to try and do:

Have different modes of robotic operation (sketches) stored in the SD card, then have the Arduino access and change its own programming from just its own SD card. The SD card would be a 4 gig "virtual drive" pool of resource that the running microcontroller has access to.

I would try to start simple- a headbot that seeks light, but upon a noise, avoids light- simple to do as a single sketch, but I want the "photovore" and "photophobe" to be separate sketches on the sd card- that the arduino switches out with some sort of flush/download/restart mini reboot. All on its own.

If this is possible things could get very complicated/exciting very quickly- it could not only select its own programming based on current needs, but if properly designed, can modify its own programming as well from recorded success/failure logs biasing the variables of the next attempt (a form of learning)

I would love to experiment with this- not only just to expand the memory available to an arduino, but indeed to tinker with "feedback learning"- I have several tests I would like to try; from self taught 3 servo arm coordination time to target trials (where it starts off clumsy/erratic, but after several tries "learns" how to coordinate the joints fluidly), Wheeled vehicle self controlled speed control(learning how soon/how much to slow down to avoid obstacles, and how much time/distance it needs to come to a stop- all on its own based on range data/collision records), all the way up to... (kidding here) self aware AI.

But all of this is only practical IF there is a way for an arduino with an sd card on its back to be able to read, write, and most importantly: swap out its own sketch. Is it possible/do-able? Is there some fundamental problem that blocks this sort of interfacing?

This has me intrigued, and I would like an initial feedback on the prospects/prohibitions that may open a door or slam it shut in this path of Arduino Tinkering. Thank you.

[I asked this in the Storage forum, but it appears to be more relavent to this forum]

Hard drive is the best way to explain what I want to try and do:

Have different modes of robotic operation (sketches) stored in the SD card, then have the Arduino access and change its own programming from just its own SD card. The SD card would be a 4 gig "virtual drive" pool of resource that the running microcontroller has access to.

I would try to start simple- a headbot that seeks light, but upon a noise, avoids light- simple to do as a single sketch, but I want the "photovore" and "photophobe" to be separate sketches on the sd card- that the arduino switches out with some sort of flush/download/restart mini reboot. All on its own.

If this is possible things could get very complicated/exciting very quickly- it could not only select its own programming based on current needs, but if properly designed, can modify its own programming as well from recorded success/failure logs biasing the variables of the next attempt (a form of learning)

I would love to experiment with this- not only just to expand the memory available to an arduino, but indeed to tinker with "feedback learning"- I have several tests I would like to try; from self taught 3 servo arm coordination time to target trials (where it starts off clumsy/erratic, but after several tries "learns" how to coordinate the joints fluidly), Wheeled vehicle self controlled speed control(learning how soon/how much to slow down to avoid obstacles, and how much time/distance it needs to come to a stop- all on its own based on range data/collision records), all the way up to... (kidding here) self aware AI.

But all of this is only practical IF there is a way for an arduino with an sd card on its back to be able to read, write, and most importantly: swap out its own sketch. Is it possible/do-able? Is there some fundamental problem that blocks this sort of interfacing?

This has me intrigued, and I would like an initial feedback on the prospects/prohibitions that may open a door or slam it shut in this path of Arduino Tinkering. Thank you.

You will at the very least have to modify the bootloader on your Arduino to acomplish this.
Not a simple thing to do, but depending on your skills ......

I think thre was someone who did something similar a (rather long) time back.

Try to search the forum.

An Arduino can't read a new sketch from an SD card for itself, but it might be possible to have 2 Arduino's in which the first programs the second with an precompiled hexfile from SD card.

Never done it but it could be possible... (is 2 arduinos an option?).

Crossposted - Arduino Forum -

The other thread is in the storage section which is the most appropiate I think, please remove this thread to keep the discussion in on place,

thank you,

It might be worth having a look at Bitlash to see if it suits you.

The Bitlash interpreter (http://bitlash.net) runs on the Arduino and can execute scripts from SD card. And write data to files on the card.

It's not hard to integrate your robot management (or whatever) primitives into Bitlash and use them from Bitlash script.

It is most definitely not the same as loading sketches from SD card, but you can accomplish a lot of the same effect.

-br

lharvey619:
but I want the "photovore" and "photophobe" to be separate sketches on the sd card- that the arduino switches out with some sort of flush/download/restart mini reboot. All on its own.

Why? Why not leave them as part of the same sketch? There is no practical reason to split them up. If you are implementing code that needs 32-256k of code-space, you are probably using the wrong platform. Remember, the Arduino is based on a microcontroller and not a microprocessor.

lharvey619:
If this is possible things could get very complicated/exciting very quickly- it could not only select its own programming based on current needs, but if properly designed, can modify its own programming as well from recorded success/failure logs biasing the variables of the next attempt (a form of learning)

Exciting isn't the word I would use. Programs that can modify themselves quickly become impossible to debug. You don't want self-mutating code. You might want code that learns from a history of data, but the code itself should stay predictable.

Everything is doable, however it depends on resources available. Is my understanding correct - that you want to have sketches (source code) placed on an sdcard, where the sketches (source code) might be reconfigured on-the-fly and loaded back to arduino for an execution? If that is the the situation then you need a compiler included - this is hard to achieve with today's resources. When you think to have compiled sketches - hex files placed on the sdcard - this is doable today, however the reconfiguration/modification of the sketches on-the-fly will be hard, maybe not feasible (as you have to modify hex files). The other approach is to have many of compiled sketches (hex files) with various scenarios placed on the sdcard and to load the appropriate one based on the situation - this is doable.
The easiest way today is what Bill suggests - the scripts are interpreted by Bitlash, not compiled, and basically they mirror the arduino's standard functions. You can modify those scripts on fly based on changing situation and run them afterwards - this is doable. The scripts are functions so you may introduce a kind of AI approach then (self modification of the scripts on-the-fly).
The only thing you have to consider is that ie. sdfat+bitlash occupy most of the ram and flash of the arduino's mainstream chip - 328p - therefore you have to use atmega1284p or atmega128, 256 chips, or chipkit UNO32, MAX32.
Pito

what you might be able to do is make an operating system.
think of it, a real computer only runs 1 program, the OS, and the OS runs programs in its own format.
if you are capable of ding that learning code, this might be easy.
invent a code system, say the first char identifies main function type, second the subtype, third arg1 and so forth.
here is the command system of the redgame 1(home-made computer in minecraft):
GOTO if 0,GOTO if 0<,command argument,command,save answer to(RAM/register)
setting command to RAM will make command argument what to load.
setting command to ALU will make command argument select ALU mode and set GOTO to ALU output.
setting command to GOTO will make command argument select witch input to read.
setting command to GPU will make command argument select what the GPU does.

if you do not want to use GOTO, set GOTO to the current command ID+1.
the redgame worked in binary and was ridiculisly simple, but similar can be doe with arduino. I am also coding an OS, but the command system is undecided.

I hope I helped!

what you might be able to do is make an operating system.

But what you describe is, at best, an interpreter.

I am sure I saw a sdcard bootloader for arduino. Google it.