Go Down

Topic: sketch won't start after power on (Read 1 time) previous topic - next topic

lmalves

Hi all, I'm very new at this and I've got a problem. I've searched the forum and couldn't find the answer.
I upload some simple code and everything works fine, but when I power off and on again (USB) it won't start running the code. The power light works fine but a very simple code won't start.
This is probably a newbie question but I could use some help.

Thanks is advance

Coding Badly


I think the bootloader waits three seconds before starting the Sketch.  Wait a few seconds after applying power.  Does your Sketch start?

James C4S

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

lmalves

I've waited several minutes and nothing. The code is the DigitalReadSerial with a tiny modification. The third example in andruino tutorial. A program to send to the serial port the status of a digital input.

I know that the program is not working because the TX led don't light up when I click the push button, like when I upload the sketch.

James C4S

Open (or re-open) the serial monitor after you apply power.

Yoiu might also include a heartbeat like flashing pin13 to prove if the sketch is running or not.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

lmalves

Here is my code.
Code: [Select]
void setup() {
 Serial.begin(9600);
 pinMode(2, INPUT);
}
void loop() {  
int in2 = digitalRead(2);
 if (in2 != 0){
   Serial.println(2, DEC);
   delay(1000);
 }
}

When it works, the TX led flash every time I click the pushbutton, when I turn off and on it does nothing.
Opening or reopening the serial monitor don't change anything.
Is there any known problem with the USB/Serial in Win7?
When I upload the code it goes to the flash memory right? To the non-volatile memory?

retrolefty

#6
Nov 10, 2010, 11:10 pm Last Edit: Nov 10, 2010, 11:11 pm by retrolefty Reason: 1
How is your switch wired, could you be fighting a 'floating input' problem? Typically one needs a pull-up (internal or external) or pull-down resistor (external only) to interface with a switch correctly.

Lefty


lmalves

Quote
How is your switch wired, could you be fighting a 'floating input' problem? Typically one needs a pull-up (internal or external) or pull-down resistor (external only) to interface with a switch correctly.

I have a pull-down resistor and everything works good when I upload the code, but after plug off and on... Nothing!
Should it be a hardware problem or am I making anything wrong?

Coding Badly


James C4S

#9
Nov 11, 2010, 04:49 pm Last Edit: Nov 11, 2010, 04:51 pm by cmiyc Reason: 1
Quote
Should it be a hardware problem or am I making anything wrong?

It is a lack of troubleshooting steps.  Which is why I suggested doing something with the built-in LED on Pin 13.  

I just tried this sketch on my Uno and Duemilanove:

Code: [Select]

void setup() {
 Serial.begin(9600);
 pinMode(2, INPUT);
 pinMod(13, OUTPUT);
 digitalWrite(13, HIGH);
}

void loop() {
 delay(1000);
 Serial.println(1, DEC);
 digitalWrite(13, !digitalRead(13));
}

Once per second I send some data over serial and toggle the LED on Pin 13.  I did the LED on Pin 13 because I want to know the sketch is running.  Immediately after upload I see Pin 13 Toggle and the TX LED flicker once per second.  All as expected.

When I remove power and re-attach power, just like you, I don't see anything on the TX LED.  But, the Pin 13 LED continues to toggle once per second, just like before.   At this point if I open the Serial Monitor, everything works as expected.  

It appears the Uno needs an active connection before sending data over USB.  (This behavior is not the same as the Duemilanove which isn't a huge surprise since it has a different USB to Serial interface.)
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

lmalves

[SOLVED]
Ok thanks a lot.
Today I've already notice that, I've inserted a heartbeat on pin13 and even after unplug and plug it's works..
Like you said, for it to send it needs some sort of initialization on the PC side, and that's not a problem for me.
I'm currently developing an application in vb.net to receive inputs on arduino so I just initialize the serial connection every time I start the program, also I can make the PC application to close and reopen the serial if it can't connect.
Everything works great now.

Thanks a lot

Go Up