I want to use an Arduino Nano for (LED) light control.
When I switch on the power (5V on the 5V pin) it takes about 5 seconds before the arduino starts executing the "Setup" routines. I tried to use local instead of global variables, but this does not speed up anything. While waiting for the Setup to start, the onboard LED (D13) blinks a few times irregularly... ???
Then everything runs normally...
Is there away to speed up the startup?
Here is the sketch :
//byte n;
//int R;
//int G;
//int B;
bool SW = HIGH;
//////////////////////////////////////////////////////
void setup()
{
// next two lines are there to have PWM on D9, D10 and D11 to the same frequency.
// if I leave this lines out : same slow start ...
// the waiting time happens BEFORE
TCCR1B = TCCR1B & B11111000 | B00000001;// set timer 1 divisor to 1 for PWM frequency of 31372.55 Hz (D9 + D10)
TCCR2B = TCCR2B & B11111000 | B00000001; // set timer 2 divisor to 1 for PWM frequency of 31372.55 Hz (D3 + D11)
pinMode(9, OUTPUT); // B out
digitalWrite(9, 0); //
pinMode(10, OUTPUT); // G out
digitalWrite(10, 0);
pinMode(11, OUTPUT); // R out
digitalWrite(11, 0);
for (byte n = 56; n < 255; n++)
{
analogWrite(9, n - 56);
analogWrite(10, n);
analogWrite(11, n);
delay(4);
}
pinMode(A0, INPUT_PULLUP); // SW
pinMode(A1, INPUT); // MAIN
pinMode(A2, INPUT); // R in
pinMode(A3, INPUT); // G in
pinMode(A4, INPUT); // B in
}
//////////////////////////////////////////////////////
void loop()
{
// doesn't matter for this issue/problem
// if here is code or not : problem stays the same.
}
Don't hesitate to ask for more info ...
In advance : THANKS !
The delay before starting is while the Arduino bootloader program is checking to see if there is a new program to upload.
It is possible to upload a program using ICSP and effectively removing the bootloader. After that programs will start very quickly but you will have to continue to use ICSP every time you want to change the program until such time as you re-install the bootloader.
WOW Robin2 ! That was fast ! (I restarted my Nano again, and before it started to run, you already answered !! :o ) THANKS !
Now I'll go searching for that "ICSP" stuff you mentioned.
You have any idea where to look ?
Again : thanks for your incredibly super fast reply !
PaulVdB:
Now I'll go searching for that "ICSP" stuff you mentioned.
You have any idea where to look ?
What Robin is trying to say is that although you can remove this delay, you probably don't want to. The alternative is less convenient for beginners, and you will need an extra piece of hardware. A suitable piece of hardware would be, for example, a USBasp programmer. You may need an adaptor also, for the 6-pin header on the Nano.
You enter a room and switch the light on. It (gradually) goes from zero to full white "immediately".(Soft start)
Then (by pushing a button) you can choose to dim, and/or mix your own room color (I use RGB led strips)
Switching off the light, it goes off immediately.
Switching it back on, it starts again from zero etc...
(lemme know if you're interested in the sketch and corresponding electronics)
All those features are programmed and are working fine, but I can't live with the fact that I have to wait 5 seconds in the dark (that's long!) before I see where I step... would you ?
Now I looked into the ICSP thing, but still wondering if it's going to give me the result I need.
Once the Nano is programmed through the ICSP, and has to start to live on it's own, isn't the bootloader not gonna look for changes/new uploads and start the program immediatly ? Do I have to remove/delete the bootloader? (and how ?)
Oh... and BTW, I'm certainly NOT an expert, but neither I can call myself a beginner. I'm "playing" with Arduino's for a few years now, I am a qualified electronics engineer but I do lack (alot of) C++ experience. I am sure that a real "C++ programmer" can rewrite my programs with only half or less lines of code, and probably will laugh or be bored while reading my code. But I never got "stuck" with things I wanted to achieve... And I never ran out of program space on my Arduino's ... If my sketch doesn't fit in a Nano (my favorite) I poor it in a Mega ...
Nevertheless : !!TANX!! again for your remarks !
I'm not sure at what point it was added, but the current version of optiboot checks to see if the reset was caused by powering on the chip, and if so goes directly to the sketch bypassing the bootloader.
david_2018:
I'm not sure at what point it was added, but the current version of optiboot checks to see if the reset was caused by powering on the chip, and if so goes directly to the sketch bypassing the bootloader.
That sounds like the simplest solution - if it can be implemented on the nano (I don't have nanos so I have no idea)
PaulVdB:
Once the Nano is programmed through the ICSP, and has to start to live on it's own, isn't the bootloader not gonna look for changes/new uploads and start the program immediatly ? Do I have to remove/delete the bootloader? (and how ?)
Uploading a program with ICSP will overwrite the bootloader.
Paul__B:
If it takes 5 seconds - and particularly if "the onboard LED (D13) blinks a few times irregularly", then something is clearly wrong.
Not to mention that!
Well, maybe there's something wrong with my Nano ... but I can upload, over write, run (even other) sketches over and over ... So what do you think is wrong ? Is it something I should worry about ?
nevertheless thanks for your remark !
AJLElectronics:
Why can you not run the Arduino all the time?
About the "always on" remark : I might do this for this project, because it's kinda urgent, and I first want to experiment with the ICPS thing. But I hate to have things running all the time (although the power consumption is neglectable). Another thing is that this project will be used in an often-unattended place, and I can't afford to use super guaranteed parts (even the nano itself could be "dangerous"!) When the power is off nothing can happen. IF there's something wrong with some part, it will be noticed it when the power is applied. (and of course something will BE in that room/place) ...
Nevertheless, to every one who commented this thread, 1K thanks !
CrossRoads:
Sounds like normal bootload behavior to me.
Thanks ! What a relief !!!
I was getting worried that weird things might happen... (invading of aliens or things like that, sending my bank passwords to the bad people ... )