Blink example seems to not follow the code

Hello,

I am new to the Arduino world. I started with the blink example since I will need a few of these in my project and noticed that the reset toggles PIN 13 three times before initializing the example code. This may exist on all PINs but I do not have an oscilloscope to verify, besides many members most likely know this answer already. I searched "reset causes PIN 13 to toggle" and was absolutely floored to find only one thread that resulted from that search ((Solved! ..Software Solution) How to prevent Output pins floating on boot - General Electronics - Arduino Forum). I was not very satisfied or at least very confused by "saturation" and exactly what the solution was but I gathered that using pull down resistors for the digital PINs will avoid this. This also happens during power up as well.

I observe:
3 fairly quick pulses followed by a 1 second OFF state followed by a short duration HIGH state. The program then continues as expected.

I assume:
The code started after the third quick pulse. This would mean that the first high pulse was too short as described in the code. I changed the statement "int ledState = LOW" in the code to init the PIN to HIGH and was surprised to see that the only change was a longer LOW state after the last short pulse. I have no idea how I can tell when the code actually starts based on the above experiment. I thought that maybe the timer started during the initialization before the code initialization. Best guess so far.

Why is PIN 13 toggling?
This PIN is being driven, this is not floating voltage so I have no idea how a pull up resistor will change this PIN's state during the Reset function. If I had an oscilloscope I expect to see a square wave during the reset which is why the LED is on long enough to see and does not have any dimming whatsoever. Floating voltage I would expect to see a shark-tooth wave but only one pulse and fast enough that the LED would not be visible. Floating voltage does not sustain current. I do not mind being wrong so please correct me if I am.

Is PIN 13 useful to me (I never want to see a PIN changing state without the code directing it to)?

Using ARDUINO UNO genuine from italy and the example code is:

/* Blink without Delay

Turns on and off a light emitting diode (LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.

The circuit:

  • LED attached from pin 13 to ground.
  • Note: on most Arduinos, there is already an LED on the board
    that's attached to pin 13, so no hardware is needed for this example.

created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
modified 11 Nov 2013
by Scott Fitzgerald

This example code is in the public domain.

*/

// constants won't change. Used here to set a pin number :
const int ledPin = 13; // the number of the LED pin

// Variables will change :
int ledState = LOW; // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated

// constants won't change :
const long interval = 1000; // interval at which to blink (milliseconds)

void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}

void loop() {
// here is where you'd put code that needs to be running all the time.

// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}

// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}

If you feel inclined to help then thank you in advance,
Chris

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

The bootloader code that runs every time you press the reset button or power your Arduino board on toggles pin 13. It doesn't affect any other pins.

If you don't like this behavior you have two choices:

  • Upload to your board using an ISP programmer (Sketch > Upload using Programmer), which could be an Arduino used as "Arduino as ISP" or a dedicated programmer such as USBasp. The bootloader is not needed for Upload Using Programmer and it is erased the first time you do this type of upload.
  • Recompile the bootloader with the blink code disabled and flash the new bootloader to your Arduino board using an ISP programmer.

Pert,

You are awesome! Thank you.

I did read 2 rule postings before I posted my question, but I must have missed the code part. I was reading a different rule post when you were replying to my post and I knew I was caught like a cat that ate the canary. I apologize, that is my bad.

I will read about the boot loader solution when I need PIN 13. I hope I will never need to use that PIN, but it is nice to know that the rest of the PINs are not affected. After, thinking about it for a minute, I understand why it is toggling. The developers wanted some form of feedback during the initialization stage to verify it is doing something (nice touch).

Again thanks,

Chris

Just looking for a "solved" button.

Scratch that. I tried to post the above and got the most retarded message "You have exceeded the number of posts you can make in a 5 minute period."

So apparently I cannot post two messages in a 5 minute time frame. What kind of bullsh!t forum is this. Hey, perhaps we can use carriage pigeons, just do not try and have a conversation. A$$holeS.

Sorry Pert, but I do not care if this is in the wrong section I am pissed. But apparently YOU can message two times in a 5 minute time frame. WTF!!

Hey Hey, keep it nice! It's an anti spam measure for new accounts. Make a couple of posts (forgot the threshold) and the limit is removed.

About the solved, just edit the first post and place something like [SOLVED] in front of the title.

Constant_Confusion:
I tried to post the above and got the most retarded message "You have exceeded the number of posts you can make in a 5 minute period."

That limitation disappears after about 100 posts. It would be nice to have at least one notification (the very first notification, which will not be shown again after the first one) that says 'limitation will be lifted after 100 posts'. This would at least allow new users to understand the system.

The second thing is ..... try holding back on using informal offensive language. Eg. avoid using the word 'retarded'.

Thread split - see "General Discussion"