1

I am looking for a way to keep a program on my Arduino Nano 3.0, after uploading new sketches on it. I would like to have a program on it that will control th screen and buttons at it. The user will choose one of the programs displayed on the screen and execute/pause/stop them. These programs will be uploaded on the Arduino, while the previous programmes stay.

If you are familliar with the Lego Mindsdorm microcontroller, you probably know waht I am looking for.

Is there a way to do that.

  • 2
    You want something like a dual boot arduino – Gerben Jan 26 '17 at 15:11
  • 1
    looks to me like you just need one massive program which you flash onto the arduino, and theres a simple display and buttons that when it starts up allows you to select which "program" to run. Each time you add new programs its still the same big single program, but with more functions and you'd have to add more options to the GUI list. – KyranF Feb 25 '17 at 21:25
  • 1
    @Gerben, you continue to astound me. I thought you were just joshin' until I read that Hackaday. +1 – SDsolar May 17 '17 at 8:28
  • I have something similar - a text-to-Morse routine - that I use sometimes. While it might be fun to have it always-resident it was just as easy to make it a function and then append it to my sketches as-needed. The heavy lifting is finished, and I don't need it for every program, but can bolt it on quite quickly. – SDsolar May 17 '17 at 8:30
1

I'm not familiar with Lego Mindstorm, but I think I understand what you want and I am certain there is a way to do it, but I don't think it will be easy or even practical and I can't tell you exactly how to do it.

I'm pretty certain there will be a way to load a 'module' into memory and then make the program call that address. I haven't got a clue how you would do it though, sorry. GCC doesn't have a concept of DLLs like window does, but it does have shared libraries. Or you might look at just reading a block of memory in.

Other approaches might be to have all the 'programs' as functions within you main program and call them depending on the user's input. You can only do this if the 'programs' are small enough.

If you can refactor your 'programs' to extract the common code into functions and then have a data file (which could be read at runtime) that called the functions for each of your programming. Basically invent your own higher level programming language. This wouldn't work if your code was very different and you could factor it down to a small enough number of functions.

Would it be possible to just have a number of hex files (compiled programs?) all of which have the common screen/button handler in and then have the special code for the appropriate program. These could all be stored on an SD card and then loaded into memory by a second Arduino (sounds plausible to me, I'm sure someone will tell me whats wrong with that idea.)

An alternative based on the inverse of the above solution would be to have one Arduino to control the screen/buttons and it programs a second Arduino with the specialist code that is connected to the rest of your kit.

  • 2
    You cannot load code into RAM and then call that address: the AVR's Harvard architecture makes it impossible to run code from RAM. You need to load the code into flash, which is quite involved, and normally considered a bootloader's job. You will essentially have to write a custom bootloader. BTW, gcc doesn't support shared (aka dynamically linked) libraries on the AVR platform, only statically linked libs. – Edgar Bonet Jan 26 '17 at 15:17
  • A special bootloader and a jump-list to functions in a seperate part of the flash is possible. But it is very impractical. Adding a .h include file to the project with binary compiled code as PROGMEM data (and a jump-list to the functions) might be a challenging job for programmers. That is also very impractical. Perhaps the best way is to combine a number of normal libraries into a single .zip file which can be installed in the Arduino IDE. – Jot Jan 26 '17 at 17:27
0

The Arduino paradigm uses two programs on the target. The boot loader and the application. The processor is agnostic WRT this differentiation and runs the entire code set as one large application.

To put a 2nd application on an embedded processor is feasible. However, you would have to be intimately knowledgeable about how Arduino SDK works as well as the boot loader as you would have to create new features to relocate code normally found at fixed locations. A rather involved task.

Instead, consider simply adding your utility code to your application code in the Arduino SDK and replace the utility code already on the processor with the new image.

0

You want something like this using the serial monitor:

if((homeMenuActivated) == true)
{
  Serial.println ("Program Number 1");
}

I am kind of glad you asked this, as I am working on a similar program with arduinos that can do the same thing you want.

0

Is there a way to do that.

sure.

one way to do it is to use a pin to indicate which program you want to execute.

uint8_t execution_switch=0;  //execution switch. 0->run setup0()/loop0(), 1->run setup1()/loop1()

void setup(void) {
  pinMode(EXECUTION_SWITCH, INPUT_PULLUP); //execution switch as input + pullup
  execution_switch=(digitalRead(EXECUTION_SWITCH)==LOW)?0:1;
  if (execution_switch==0) setup0(); else setup1();
}

void loop(void) {
  if (execution_switch==0) loop0(); else loop1();
}

you can easily change it to accommodate multiple programs / multiple switch pins, or real time switch, ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.