Go Down

Topic: Maybe a stupid question, but how to you prevent old code from running... (Read 228 times) previous topic - next topic

maxiedaniels

I just got my Arduino in today, very excited. I'm a few lessons in now, but I have a question...

If I setup code for a circuit, upload it, then I disconnect the arduino and start a new circuit... how do I upload the new code for the new circuit without the old code automatically running? Couldn't I risk screwing something up by letting old code run on a new circuit?

JimboZA

There are a number of threads that suggest you may be right.

So what you could do is:


  • Power Arduino down

  • Dismantle old circuit

  • Power up, old sketch runs but no circuit attached

  • Load Bare Minimum sketch (empty setup() & loop()- File > Examples > 01 Basics)

  • Power down

  • Mantle* new circuit

  • Power up (Bare Minimum runs)

  • Load new sketch



*Well, if dismantle means take something apart, mantle must mean build it in the first place?
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

maxiedaniels

Makes sense. Thank you. Is that the standard procedure then? Just wanting to get things right from the get go.

JimboZA

Not sure if it's standard or not... standard (as in most common) is probably to build the new circuit under power and risk shorting something.

I think there's even been a suggestion to load BareMinimum when you've finished playing: that way next time you power up, the board's in a known condition, especially if you have many boards and just grab one.

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

krazydarcy

Correct me if I'm wrong,
Assuming you're running a relativly stock arduino without sd card reader or other storage,
when you upload the next sketch/program into the arduino the previous one gets erased from the arduino.
The memory it is stored in is non volitile (does not wipe as soon as power is lost) memory..

JimboZA


Correct me if I'm wrong,
Assuming you're running a relativly stock arduino without sd card reader or other storage,
when you upload the next sketch/program into the arduino the previous one gets erased from the arduino.
The memory it is stored in is non volitile (does not wipe as soon as power is lost) memory..


True but that's not what the OP's asking. His concern is that if he builds circuit B and powers up, the old sketch for circuit A will run before he loads the new sketch for circuit B, and that could have consequences.
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Grumpy_Mike

I always upload the new code before attaching the new software.

The other way of doing it would be to power up with the reset held down, then only release the reset when you get the message from the IDE that you are downloading code.

Go Up