Pages: [1]   Go Down
Author Topic: sketch won't start after power on  (Read 1498 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6133
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is your very simple code?
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6133
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my code.
Code:
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?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

« Last Edit: November 10, 2010, 05:11:50 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Try a simple Blink Sketch.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6133
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.)
« Last Edit: November 11, 2010, 10:51:17 am by cmiyc » Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[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
Logged

Pages: [1]   Go Up
Jump to: