# Running code off a SD Card

**URL:** <https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109>\
**Category:** General Guidance\
**Created:** [July 7, 2022, 5:57am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109 "2022-07-07T05:57:12Z")\
**Posts on this page:** 19\
**Page:** 3

<div class="post-metadata">

**Author:** ![GoForSmoke](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/goforsmoke/32/1127097_2.png) [@GoForSmoke](https://forum.arduino.cc/u/GoForSmoke)\
**Post date:** [July 7, 2022, 7:43pm UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/48 "2022-07-07T19:43:24Z")

</div>

> [@PaulRB](#):
>
> == re-inventing the wheel

How do you beat square wheels for going up and down stairs?

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 8, 2022, 3:43am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/49 "2022-07-08T03:43:41Z")

</div>

So to recap, this will not work then.  
But would it work with a Nicla Sense ME?  
Or another one like it?  
Thanks everyone for your help!

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [July 8, 2022, 7:17am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/50 "2022-07-08T07:17:00Z")

</div>

> [@outbackhut](#):
>
> But would it work with a Nicla Sense ME?  
> Or another one like it?

Have you not been paying attention?  
In summery no it will not work unless you attempt to re engineer the boot loader code and override the normal operation of the ARM based processor.

To summarise the summery.  
If you have to ask, then you can't do it.

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 8, 2022, 7:40am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/51 "2022-07-08T07:40:37Z")

</div>

@Grumpy_Mike  
I mean do those have enough memory to store WAY more code than a Mega2560 🙄🤔  
I don't even need a SD card if another board would work, obviously

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [July 8, 2022, 1:14pm UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/52 "2022-07-08T13:14:33Z")

</div>

> [@outbackhut](#):
>
> mean do those have enough memory to store WAY more code than a Mega2560

It is very difficult to do a direct comparison because they get compiled into different machine codes, with different efficiency, to a greater or lesser extent depending on the compiler.

It also depends on how you write code, as to how effective or rambling it is.

But for only a first rough approximation look at the different amounts of flash memory in each alternative.

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 8, 2022, 11:10pm UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/53 "2022-07-08T23:10:14Z")

</div>

@Grumpy_Mike  
Thanks mate, will do!

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [July 9, 2022, 5:14am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/54 "2022-07-09T05:14:23Z")

</div>

> [@outbackhut](#):
>
> I mean do those have enough memory to store WAY more code than a Mega2560 🙄🤔  
> I don't even need a SD card if another board would work, obviously

As Grumpy\_Mike says, you don't know. You can easily test by installing the board package for a board of interest and compile your sketch for that board.

Below are some results for blink on different boards.

```arduino
Classic Nano
Sketch uses 924 bytes (3%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

Nano Every
Sketch uses 1118 bytes (2%) of program storage space. Maximum is 49152 bytes.
Global variables use 22 bytes (0%) of dynamic memory, leaving 6122 bytes for local variables. Maximum is 6144 bytes.

MKR Zero
Sketch uses 10996 bytes (4%) of program storage space. Maximum is 262144 bytes.
Global variables use 1992 bytes (6%) of dynamic memory, leaving 30776 bytes for local variables. Maximum is 32768 bytes.

Due
Sketch uses 10684 bytes (2%) of program storage space. Maximum is 524288 bytes.
No report on dynamic memory

M0
Sketch uses 11484 bytes (4%) of program storage space. Maximum is 262144 bytes.
Global variables use 2188 bytes (6%) of dynamic memory, leaving 30580 bytes for local variables. Maximum is 32768 bytes.

```

Oh shocker, the last 3 use around 200x as much RAM (dynamic memory) as the classic Nano. Don't let this discourage you to run the test, your results can be far better due to the way linkers work.

Note:

1. I only have the classic Nano; the other boards are installed to be able to help users on the forum. I did not update any of the packages before i ran the test so there might be little variations in the results if you run the test.

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 10, 2022, 10:54pm UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/55 "2022-07-10T22:54:13Z")

</div>

The current code I'm running which is 19% of program storage space, and 21% of dynamic memory, does not fit on ANY other boards except the Mega ADK.

It won't even compile for a Raspberry Pi at all - gives me heaps of errors.

---

<div class="post-metadata">

**Author:** ![mrburnette](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mrburnette/32/702556_2.png) [@mrburnette](https://forum.arduino.cc/u/mrburnette)\
**Post date:** [July 11, 2022, 12:12am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/56 "2022-07-11T00:12:06Z")

</div>

> [@outbackhut](#):
>
> The current code I'm running which is 19% of program storage space, and 21% of dynamic memory, does not fit on ANY other boards except the Mega ADK.

Bill Roy's bitlash was mentioned earlier. It can exist in SRAM and interpret BASIC scripts on the SD-card. It will not be overly fast in performance, but you can easily create a bunch of code 'overlay'ish kind of subprograms.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/6/9/269f85f705e6c6e73cedcc05b03ac09342aa9e40.jpeg)

Adafruit's CircuitPython runs natively currently on 6 official Arduino hardware platforms, just not clasic AVR-based h/w.  
[Downloads (circuitpython.org)](https://circuitpython.org/downloads)

Personally I would suggest, if you are really interested in OS-ish behavior on a Mega2560, then start with a known-clean task-switcher as a core and build out the rest:  
[Setting Up FreeRTOS on Arduino - Tutorials (exploreembedded.com)](https://exploreembedded.com/wiki/Setting_Up_FreeRTOS_on_Arduino)

For inspiration:  
[Linus-Torvalds - Google Search](https://www.google.com/search?q=Linus-Torvalds)

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 11, 2022, 12:15am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/57 "2022-07-11T00:15:58Z")

</div>

@mrburnette  
Is circuit python c++? That's the only language I can understand.  
What is freeRTOS? Does it work on SD cards?

---

<div class="post-metadata">

**Author:** ![mrburnette](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mrburnette/32/702556_2.png) [@mrburnette](https://forum.arduino.cc/u/mrburnette)\
**Post date:** [July 11, 2022, 12:22am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/58 "2022-07-11T00:22:12Z")

</div>

> [@outbackhut](#):
>
> Is circuit python c++?

It is written in C, but is its OWN complete language... well (very) well documented with volumes of reference materials.

PS: it will change your way of thinking about software problem solving.

Research FreeRTOS... I did provide a link.

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 11, 2022, 12:26am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/59 "2022-07-11T00:26:24Z")

</div>

@mrburnette

> [@outbackhut](#):
>
> circuit python

Is it able to be used on the normal arduino boards?

> [@mrburnette](#):
>
> Research FreeRTOS... I did provide a link.

I've tried it out - how do I use that for my own tasks?

---

<div class="post-metadata">

**Author:** ![mrburnette](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mrburnette/32/702556_2.png) [@mrburnette](https://forum.arduino.cc/u/mrburnette)\
**Post date:** [July 11, 2022, 12:34am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/60 "2022-07-11T00:34:00Z")

</div>

> [@outbackhut](#):
>
> Is it able to be used on the normal arduino boards?

Like provides the 6 supported real Arduinos.

> [@outbackhut](#):
>
> ow do I use that for my own tasks?

Were I trying to understand a fundamental knowledge component of **any OS** I would read the documentation.

Building software to implement a "command" is child-play:  
This does **not** an OS make... still, I once thought it clever.

[Don't Cross The Streams (FP scientific calculator serial co-processor) - Community / Exhibition / Gallery - Arduino Forum](https://forum.arduino.cc/t/dont-cross-the-streams-fp-scientific-calculator-serial-co-processor/144054)

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 11, 2022, 12:34am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/61 "2022-07-11T00:34:40Z")

</div>

> [@mrburnette](#):
>
> Like provides the 6 supported real Arduinos.

Not the normal ones though

---

<div class="post-metadata">

**Author:** ![mrburnette](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mrburnette/32/702556_2.png) [@mrburnette](https://forum.arduino.cc/u/mrburnette)\
**Post date:** [July 11, 2022, 12:41am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/62 "2022-07-11T00:41:36Z")

</div>

> [@outbackhut](#):
>
> Not the normal ones though

OMG ...  
Sorry, but obviously you are not being serious 😒

I really try and take inquiries in this forum seriously, giving Ops (young & old) the benefit of asking questions without the knowledge old farts like myself have struggled to acquire by virtue of years in the industry (@72, many years.) Please do your homework and do not disappoint with such lame terminology as "normal..."

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 11, 2022, 12:57am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/64 "2022-07-11T00:57:18Z")

</div>

@mrburnette

> [@mrburnette](#):
>
> Like provides the 6 supported real Arduinos.

Am I able to use the AVR boards - ie a mega?

---

<div class="post-metadata">

**Author:** ![outbackhut](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/outbackhut/32/1099892_2.png) [@outbackhut](https://forum.arduino.cc/u/outbackhut)\
**Post date:** [July 11, 2022, 1:04am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/65 "2022-07-11T01:04:52Z")

</div>

@mrburnette

> [@mrburnette](#):
>
> do not disappoint with such lame terminology as "normal..."

By normal I mean AVR boards.

---

<div class="post-metadata">

**Author:** ![GoForSmoke](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/goforsmoke/32/1127097_2.png) [@GoForSmoke](https://forum.arduino.cc/u/GoForSmoke)\
**Post date:** [July 11, 2022, 6:41am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/66 "2022-07-11T06:41:48Z")

</div>

> [@outbackhut](#):
>
> I've tried it out - how do I use that for my own tasks?

You can write functions that run as tasks.

If you can write a sketch to do one thing with delay() or other blocking code,  
I can show you how to convert it to run "in parallel" with other tasks (converted delay code) so smoothly you can run motors and sensors in coordinated fashion.

32K flash is a lot of code&data space for an 8 bit machine. But filling 256K?  
Until you know basic C through pointers and bit-logic, any big or hard projects you do will waste your time compared to doing small projects.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 7, 2023, 6:42am UTC](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109/67 "2023-01-07T06:42:20Z")

</div>

Closed on January 7, 2023, 6:42am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/running-code-off-a-sd-card/1010109.md?page=2)
