Sorry for such a novice question. But, I don't want to damage my h/w between changes in sketches and wired external configs that may create bucking I/O-line-driver pins in contention..
I notice that if I simply unplug the USB to my UNO, and later plug it back in, it's retained the code image and always auto-restarts the last sketch before I have a chance to download the correct new sketch that is set up for my external re-wiring..
Also if just hit RESET before disconnecting the UNO it simply restarts the prior sketch still in RAM so it does the same thing and will run code that's not suited for the external wiring changes I've just made...
Question: what's the quickest way to clear out the old sketch and PinMode code from RAM before downloading a new sketch:
Can I ClearRAM and if needed redefine all pins as INPUTs in an init process evoked just before I unplug to load new sketch code that does have the right PinMode and other initialization, and hence init/clear the card properly without having to download and run an init file between each switch in sketches?
Perhaps there is an easier SAFE way that I haven't thought of..
I'm hoping this question is clear. I've not seen what to do before switching sketches and projects addressed in the NBubie Tutorials.. Thanks IN advance JimS
Try a sketch similar to below. It's untested so I don't know if it will compile without errors.
void loop() {
}
jims123:
Sorry for such a novice question. But, I don't want to damage my h/w between changes in sketches and wired external configs that may create bucking I/O-line-driver pins in contention..
I notice that if I simply unplug the USB to my UNO, and later plug it back in, it's retained the code image and always auto-restarts the last sketch before I have a chance to download the correct new sketch that is set up for my external re-wiring..
Also if just hit RESET before disconnecting the UNO it simply restarts the prior sketch still in RAM so it does the same thing and will run code that's not suited for the external wiring changes I've just made...
Question: what's the quickest way to clear out the old sketch and PinMode code from RAM before downloading a new sketch:
Can I ClearRAM and if needed redefine all pins as INPUTs in an init process evoked just before I unplug to load new sketch code that does have the right PinMode and other initialization, and hence init/clear the card properly without having to download and run an init file between each switch in sketches?
Perhaps there is an easier SAFE way that I haven't thought of..
I'm hoping this question is clear. I've not seen what to do before switching sketches and projects addressed in the NBubie Tutorials.. Thanks IN advance JimS
Hi Jim,
You do not need to return the Arduino to a blank state. Say you set up a circuit like this:
pin 4 --> red LED anode (positive) --> 200-1000 ohm resistor --> ground
and write a sketch to make it blink out a beat. Then you want to change the circuit to use two LEDs.
You are correct: unplug the USB connector (and any external power - you'll find out about that when you run a motor) before making any changes. Then add this circuit to the above:
pin 9 --> blue LED anode --> 200 - 1000 ohm resistor --> ground
Again, you are correct: the Arduino will start by running the residing sketch. Open the sketch you want to change, Verify (compile) it, and Upload it. The Arduino will stop running the current sketch, blink some of the on-board LEDs, and after a few seconds, start running your new sketch.
jims123's problem is that a change in hardware might result in outputs driving outputs and hence a good chance of blowing things up.
Before making hardware changes, you can upload an empty sketch. All pins will be configured as input (high impedance) and hence no risk.
Oh, I see. The concept is still the same though, right? - just upload the new sketch?
In fact, I have written a sketch that turns everything off (set to INPUT) explicitly, then starts pin 13 blinking (but with a different rhythm, so I don't confuse it with a 'brand new blink pattern'.) It always pays to think about the circuit/sketch combination, so as to avoid any unlimited (or rather failure limited) currents from the onset. When I'm using an Arduino that is connected with jumper pins, I disconnect them while the program is uploaded, then pull the plug & reconfigure the circuit - reconnect the pins, and plug it back in.
Not quite in my opinion; unless the new sketch is our intermediate 'reset' sketch, either your version or the empty sketch.
Thanks a lot guys for all your thoughts on how to safely switch to a new sketch and new wiring. Sounds like there is no easy way to comment out the old code and run something like:
setup(){}
loop(){}
from within your active sketch (especially if it's a long one) so I'll create an "Initialize" sketch in a new file and save/ load and run it before unplugging to mod the external h/w..
I do have a couple more questions tho:
When this super simple Initialize sketch runs, does it actually place all the I/O pins into a high impedance / Hi-Z tri-state condition to protect them, or does it just flip them all into an I/O input state? is the normal state for all unused/non-initialized I/O pins a Hi-Z state?
Second:
Assuming I do NOT do this step above (like probably millions of other new Arduino users who never though about this)
Just how susceptible is a typical ATMEL Arduino to failure?
... if say a TTL INPUT or ground/+5Vcc jumper is left on a pin and then my new sketch code inadvertently initializes it as an output then sets it to the opposite state?
Can the pins typically tolerate this abuse .. a lot of new especially dedicated I/O chips can, so I'm wondering if I really do need to worry much about this risk at all... Yes in the case of larger voltages and currents in Motors etc..I know that they can blow out a pin more easily but will a say typical TTL or CMOS driver or jumpered voltage or GND in contention blow the Arduino driver .. if so about what % of the time?
I understand that I'll smoke the card if I'm not careful, but I suspect that the Arduinos actually can take considerable abuse since I don't hear of a lot of blown pins and cards and there's no tutorial caution on this topic the suggests any need to run an Init sketch between projects.
So, I wonder how often mis-initialization does actually damage the h/w in a typical Arduino card? I know it's happened to me a couple times yesterday and neither device blew up.. hence the post above..
Regards.
JimS
jims123:
Sounds like there is no easy way to comment out the old code and run something like:
When finished working...
• Click then New button.
• Click the Upload button.
• Wait a few seconds.
• Disconnect the board.
• Put the board away.
Two clicks and a short wait. Does that really qualify as "no easy way"?
Wow,
two clicks... that's about as simple as humanly possible.. I didn't think of doing that.
Thanks very much..
P.S I guess I should probably delete and move my "Second" question to a H/W section on the forum .. I'll do that
Regards,
JimS
You are welcome.
(I added "solved" to the title.")
No, you did not. You added "sovled" 
All my leds are sov leds.

Sorry about that. Trying to get a resume ready. Been a bit distracted.
Good luck with your quest!