Go Down

Topic: Sketch after Arduino Uno power off (Read 2699 times) previous topic - next topic

lowkill

I hope someone can explain to me the bold part:

Quote
Why doesn't my sketch start when I power up or reset the Arduino board?
Most likely because you are sending serial data to the board when it firsts turns on. During the first few seconds, the bootloader (a program pre-burned onto the chip on the board) listens for the computer to send it a new sketch to be uploaded to the board. After a few seconds without communication, the bootloader will time out and start the sketch that's already on the board. If you continue to send data to the bootloader, it will never time out and your sketch will never start. You'll either need to find a way to stop serial data from arriving for the first few seconds when the board powers (e.g. by enabling the chip that sends the data from within your setup() function) or burn your sketch onto the board with an external programmer, replacing the bootloader.


What does it mean? I've tried to "freeze" my sketch by using delay and millis functions, but sketch still won't load after power off.

pluggy

I don't think it means anything, a brain fart ?.  Since it is the arduino that is receiving, you either need to stop or disconnect whatever is sending the data whilst it starts up or remove the bootloader and burn the sketch directly with a programmer.  Since the sketch never starts if the serial is receiving, nothing you put in the sketch can make any difference. 
http://pluggy.is-a-geek.com/index.html

lowkill

I have tried to unplug all the connected wires from Arduino after power down, power up the Arduino and connect wires again, but it still won't load the sketch. This is highly annoying.

Senso

That seems like one of the bugs of the UNO bootloader.
In fact, after you put a sketch inside the Atmega it will be there for ever and ever, and you can receive all the serial data that you want, because the bootloader as a pretty specific command set to avoid that kind of problems.

lowkill


James C4S

I'm not sure you stated the actual problem you are having.  However, it sounds like your sketch is not running after you power cycle.  Do you have a Uno with a SMD chip (instead of a DIP)?

If so, you might want to see this page:
http://arduino.cc/blog/2011/01/20/issues-with-the-new-arduino-uno-smd-edition/
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

lowkill

#6
May 06, 2011, 02:44 am Last Edit: May 06, 2011, 02:56 am by lowkill Reason: 1

I'm not sure you stated the actual problem you are having.  However, it sounds like your sketch is not running after you power cycle.  Do you have a Uno with a SMD chip (instead of a DIP)?

If so, you might want to see this page:
http://arduino.cc/blog/2011/01/20/issues-with-the-new-arduino-uno-smd-edition/


No, I've got DIP edition. Problem is when I turn off the board, remove all the cables, turn board ON again and re-connect my wires, the sketch won't start unless I upload it again. Is there any way to load up a sketch after power off without using external programmer (by editing bootloader or something)?

Edit: What I would actually like the most is to "convert" the UNO to look like a MIDI device in Win7 with the permanent code inside the board, but I should probably start another topic for that.

Coding Badly


Is this the problem you're having...
http://code.google.com/p/optiboot/issues/detail?id=7

lowkill

Actually the Blink sketch runs after powering down my board and powering again.

Coding Badly

The Blink Sketch runs or the bootloader runs?

lowkill

I'm not sure what are you trying to ask me, when I upload the Blink sketch, it works as expected, I turn off the board, power it again, and the LED blinks again.

James C4S

Post the sketch that doesn't work.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Coding Badly

I'm not sure what are you trying to ask me, when I upload the Blink sketch, it works as expected, I turn off the board, power it again, and the LED blinks again.


When the bootloader runs, it blinks the LED.  If there is no Sketch loaded (Flash was erased), the bootloader blinks the LED forever.  After a power cycle, Is the LED blinking because the Sketch is blinking the LED or because the bootloader is blinking the LED?  An easy way to tell is to upload an empty Sketch, observe the board's behaviour after pressing the reset button, cycle the power, and observe the board's behaviour after pressing the reset button.

fuh

It's advisable to update the MEGA8U2 usb-to-serial firmware and the m328p bootloader on a UNO board; the first release came with bugs on both chips.
http://creativecommons.org/licenses/by-nc-sa/3.0/

lowkill

#14
May 07, 2011, 09:36 pm Last Edit: May 07, 2011, 09:41 pm by lowkill Reason: 1

Post the sketch that doesn't work.


Code: [Select]


// Turntable Pins
int turntableOne = 0;
int turntableTwo = 1;

float x=0;
float y=0;


char databyte1=0x00;
char databyte2=0x40;

int a=0;

int currpos[3] = { 0xE0, 0x00, 0x40 };

// Stores the digital values
int digA = 0;
int digB = 0;

// Stores the last four 'patterns'
int prevPatterns[4] = {0, 0, 0, 0};

// Stores the current 'pattern'
int currPattern = 0;

void setup() {
 
 
 pinMode(2, INPUT);
 pinMode(3, INPUT);
 pinMode(11, OUTPUT);    
 pinMode(10, OUTPUT);


 Serial.begin(115200);
}

void loop() {
 
 digA = digitalRead(2);
 digB = digitalRead(3);
 
 
 
 if (digA && !digB) {
   // Only A is on
   currPattern = 1;
 } else if (!digA && digB) {
   // Only B is on
   currPattern = 3;
 } else if (digA && digB) {
   // Both A and B are on
   currPattern = 2;
 } else if (!digA && !digB) {
   // Neither A nor B are on
   currPattern = 4;
 }
 
 if (currPattern != prevPatterns[0]) {
   // The current pattern is different to the last one, and is not just a repetition.
 
   // Shift patterns up, where prevPatterns[0] is the newest
   for (int i = 3; i > 0; i--) {
     prevPatterns[i] = prevPatterns[i - 1];
   }
   prevPatterns[0] = currPattern;

   if (arrayMatches(prevPatterns, 1, 2, 3, 4) || arrayMatches(prevPatterns, 2, 3, 4, 1) || arrayMatches(prevPatterns, 3, 4, 1, 2) || arrayMatches(prevPatterns, 4, 1, 2, 3))
   
   {
     // Direction A (clockwise)
     //Serial.print(">");
     
     
     x+=0.5;
     
      if (x==1)  { x=0;
     
   
     
      if (a==0) { currpos[1] = 0x00; currpos[2] = 0x40; a=1; }
     
     
      digitalWrite(11, LOW);
      digitalWrite(10, HIGH);
     
     
      if (currpos[2]==127)
     
        {
           if (currpos[1]!=127)  { currpos[2]=0x7F; midiCC(0xE0, currpos[1]+=1, currpos[2]); }
             
           else { currpos[1]=0x00; currpos[2]=0x40; }
       

       }  
 
     else if (currpos[2]!=127)  midiCC(0xE0, currpos[1], currpos[2]+=1); }
       
     
       
       
   }
       
     



else if (arrayMatches(prevPatterns, 3, 2, 1, 4) || arrayMatches(prevPatterns, 2, 1, 4, 3) || arrayMatches(prevPatterns, 1, 4, 3, 2) || arrayMatches(prevPatterns, 4, 3, 2, 1))


{
     // Direction B (anticlockwise)
     //Serial.print("<");
     
     
     y+=0.5;
     
      if (y==1)  { y=0;
     
     
     
     digitalWrite(11, HIGH);
     digitalWrite(10, LOW);
     
     
     
     
     if (a==1) { a=0; currpos[1] = 0x00; currpos[2] = 0x40; }

     if (currpos[2]!=0)  { currpos[1]=0x7F; midiCC (0xE0, currpos[1], currpos[2]-=1); }
     
     else {
         
         if (currpos[1]!=0)  { currpos[2]=0; midiCC (0xE0, currpos[1]-=1, 0x00); }
         
         else                { currpos[1]=0x00; currpos[2]=0x40;                 }
         
          }
} }
 }

 
}

int arrayMatches(int array[], int a, int b, int c, int d) {
 // If a, b, c & d match array items 0 to 3, then return true.
 return (array[0] == a && array[1] == b && array[2] == c && array[3] == d);
}



void midiCC(char CC_data, char c_num, char c_val){
Serial.print(CC_data, BYTE);
Serial.print(c_num, BYTE);
Serial.print(c_val, BYTE);

}



I'm not sure what are you trying to ask me, when I upload the Blink sketch, it works as expected, I turn off the board, power it again, and the LED blinks again.


When the bootloader runs, it blinks the LED.  If there is no Sketch loaded (Flash was erased), the bootloader blinks the LED forever.  After a power cycle, Is the LED blinking because the Sketch is blinking the LED or because the bootloader is blinking the LED?  An easy way to tell is to upload an empty Sketch, observe the board's behaviour after pressing the reset button, cycle the power, and observe the board's behaviour after pressing the reset button.



When I upload empty sketch, the board blinks 3 times. Same thing after I press reset and same thing after power cyle and reset. With the Blink sketch, it blinks infinitely.


It's advisable to update the MEGA8U2 usb-to-serial firmware and the m328p bootloader on a UNO board; the first release came with bugs on both chips.


How do I do that?

Go Up