I come from a different environment on MCU development, so I'm not sure of the facts.
If I program an Arduino UNO via the USB port, then remove the power, the program is lost. correct?
Then I have to re-download (server to arduino should be download not upload) again. Correct?
(This seems to be what is happening).
So, if I install a bootloader, will I be able to run the program just by powering up the UNO? Or is there something else that has to be done?
Do I need a special programmer to install the bootloader, or will any that has ICSP pins do? (I have a ME LABS programmer for PIC MCUs).
Basically I want the UNO to run the program as soon as power is available from a 12V PS, without any intervention. That way I can attach it to a timer to start and stop at specific times.
Sketch is retained, whether powered on or off, until another sketch is uploaded.
If power is removed, and external power is applied, the board will run the last sketch that was uploaded.
Bootloader is already installed. It is what allows you to upload over the USB port instead of using an ICSP programmer.
To bootload, you must use an ICSP programer supported by the IDE (present in tools -> programmer menu), or, for advanced user, by avrdude (and manually construct the command used to invoke avrdude,
Thanks Dr. Azzy for your straight and complete answer. That's what I thought SHOULD happen but this is what really happens:
Download a sketch into the UNO. Runs fine.
Remove USB power, attach 12 V PS.
Program does not run exact sequence (just lighting LEDS). Half the LEDs are okay, others are randomly lit.
Attach the USB connection. No display. Click reset button, get proper display.
I want to shut off the power, then turn on the power and everything works, not have to connect the server computer and/or reset the UNO manually.
My "other environment" was PIC MCUs. Never had an issue with startup (for over 10 years now, my PIC app starts up and shuts down every day, using a board I made myself.)
So?
BTW, I have a stock of UNOs and Leonardos. All do the same thing.
Typically the cause of this sort of problem is that you are using more current than the voltage regulator on your Uno can provide. When you power the Uno via USB your computer or whatever is powering the Uno directly at 5V but when you power it with your 12 V power supply the current is limited by the capability of the voltage regulator.
To verify this, try running a program that only powers a single LED with proper current limiting.
I found the problem and the solution appears so unrelated that it defies logic. Perhaps an expert out there could actually tell me what the problem was.
First, I had the problem as described, and decided after much inspection and testing that it wasn't a power issue.
Second, I was going to write to this forum on another topic, about arrays. I had an array of 7 elements that would send values to a port expander 16 bits at a time. The first 4 elements worked as expected, the next 3 would send garbage/random values.
Third, I had to declare int *OutsideArray[7], using the *, so I wouldn't get an int(int) error. Never had to use that before so was really perplexed that I needed it NOW.
All these problems have now gone away and my system is working normally. And yes, I can de-power the UNO and re-power with a running program.
My error was, I declared the array as such: int OutsideArray(7). That little subtle misconfiguration caused all the problems above. I think it had to do with bad write to protected memory area or something.
For those that might have missed it, the proper configuration is to use square brackets [], NOT parentheses (). It was so subtle that a similar declaration written above it (insideArray) was CORRECT but I didn't see the difference!!