Running a sketch code from sd card?

hi everybody
is it possible to run a sketch code from sd card on arduino?
if that can be possible then i can simply edit code with my phone then run it on arduino.

sorry for my english

You can't - the program has to be in program memory.
I suppose it would be possible to write a bootloader that reads from an SD and writes into progmem, but I think it would be a bit of a squeeze.
Alternatively, you could read interpreted code from SD, and have an interpreter on the Arduino read and execute it, but then you'd be quite restricted for RAM.

If by sketch code you mean the human readable C source code, then no that would not be possible on a Arduino board. The sketch needs to be compiled with gcc compiler that only runs on PC platform and generates a HEX file binary machine code that the Arduino bootloader can load into the Arduino's program memory for execution.

Lefty

converting to hex wouldnt be a problem on a symbian phone but compiling c code is not possible.
but i got a linux mobile computer n810 maybe it can compile c code.

by the way ,
do we have to use c as programming language on arduino
for example python doesnt need compiling

for example python doesnt need compiling

Yes, but how big is the python interpreter?
Would it cram into 16Kbytes?
I somehow doubt it.

Although this post is completely silly, you could allocate memory, load the SD card sketch into that memory and then jump to that location, in theory.

void (*app_start)(void);

void *pBin;

void begin()
{
     // allocate the memory for the sketch
     pBin = malloc(512);
     app_start = pBin;

    // todo: copy the SD card file into pBin

     // this executes the pBin code.
     (*app_start)();
}

// never gets called.
void loop()
{
}

But... Your memory availability is going to suck because you already have the bootloader, SD launching code and then only a very limited amount of RAM to do the rest of the code with. Stack is already three functions deep (main, begin, app_start), and the RAM is 512 bytes smaller immediately when your SD program starts for its own operation.

for example python doesnt need compiling

It is compiled at runtime, you would need a python interpreter in your sketch.

load the SD card sketch into that memory and then jump to that location, in theory.

Not on a Harvard architecture you couldn't.
Like the AVR.

Not on a Harvard architecture you couldn't.

You beat me to it :).

On a Harvard architecture, the program and data memories are two completely separate physical memories each with its own address space. They don't even have to be the same word-size.

@AWOL: [edit]&Oracle[/edit] nice, thanks. I wasn't aware of that.

I see now that you can't even manipulate the stack pointers to run 'data' as I was theorizing in my previous post.

As I said, if you can write a bootloader to read a hex file off SD, and write that to progmem, then it could work, but you may have to compromise, like only being able to read from specific sectors, and not really using a proper filesystem.

As I said, if you can write a bootloader to read a hex file off SD, and write that to progmem, then it could work, but you may have to compromise, like only being able to read from specific sectors, and not really using a proper filesystem.

More fundamentally you could then only read/load/run pre-compiled HEX files, not run new remotely defined new sketches as the OP apparently had in mind.

Lefty

There is http://bitlash.net/ which is sort of a basic interpretter with arduino-like keywords. Since it fits in a 168, and since an SD-card primitives also fit in a 168, there shouldn't be a huge problem teaching bitlash to read programs from an SD-card...

That's a good point, it wouldn't be arduino code but you could in theory write different code and store it on a microSD card for the arduino to run it. Even implement a real time clock module to run a different code each day...

Anyone got enough experience of bitlash to give that a go? I would also be interested if this is possible...

Mowcius