Uno R3 Problem with running a loaded sketch

by MikeJH on Mon Dec 10, 2012 11:20 pm

I can load and run a sketch when attached to the Arduino IDE but if I close the IDE and try to run the sketch either powered from the PC or a battery it seems that the Uno just runs the blink sketch. Is this a bootloader issue?
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by adafruit_support_bill on Tue Dec 11, 2012 6:40 am

When you reset the UNO, it should run the last sketch you uploaded. That sketch would have overwritten the blink sketch, so it is unlikely that it would be running blink.

What is the sketch you uploaded?
User avatar
adafruit_support_bill
 
Posts: 28836
Joined: Sat Feb 07, 2009 9:11 am

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Tue Dec 11, 2012 7:45 am

Well, it may not be running blink, it's hard to tell what it's running since I have my circuit still set up but four or more of the LEDs light up and the one on pin 13 blinks rapidly. The sketch works fine while the IDE is up. It seems like the sketch is not being retained in the flash. Strange

[Edit - moderator - Please use the 'code' button when submitting code.]
Code: Select all | TOGGLE FULL SIZE
int leds[] = {2,3,4,5,6,7,8,9,10};

void setup(){
   for(int i = 0; i<9; i++){
       pinMode(leds[i], OUTPUT);
   }
}

void loop(){
   inorder();
   randomly();
}

// Turns each LED off one at a time
void inorder(){
    for(int j = 0; j < 10; j++) {
        for(int i = 0; i< 9; i++) {
            digitalWrite(leds[i], HIGH);
            delay(100);
           digitalWrite(leds[i], LOW);
        }
    } return;   
}

// random
 void randomly(){
   for (i = 0; i < 75; i++) {
       int randomLed = random(0, 9);
       digitalWrite(leds[randomLed],HIGH);
       delay(50);
 
       randomLed = random(0, 9);
       digitalWrite(leds[randomLed],LOW);
   }return;
}

 
}
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Tue Dec 11, 2012 8:04 am

It has to be the chip. I swapped in a new ATMEGA and now I am able to run the sketch without the IDE
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by tldr on Tue Dec 11, 2012 8:06 am

please have mercy on people trying to read your code and enclose it in code tags when you post.

you have only 9 leds defined in your array, but your code is set up for ten. the number of the tenth led will be whatever happens to be stored in sram just beyond the end of your leds array.

there appears to be an extraneous } at the end of your code.

return in c is generally only used to return a specific value from a function or to exit a function at a place other than at its end.

none of this explains the behaviour your describe, though, but that bracket ought to keep your code from compiling at all.

Code: Select all | TOGGLE FULL SIZE
int leds[] = {2,3,4,5,6,7,8,9,10};

void setup(){
   for(int i = 0; i<9; i++){
       pinMode(leds[i], OUTPUT);
   }
}

void loop(){
   inorder();
   randomly();
}

// Turns each LED off one at a time
void inorder(){
    for(int j = 0; j < 10; j++) {
        for(int i = 0; i< 9; i++) {
            digitalWrite(leds[i], HIGH);
            delay(100);
           digitalWrite(leds[i], LOW);
        }
    } return;   
}

// random
 void randomly(){
   for (i = 0; i < 75; i++) {
       int randomLed = random(0, 9);
       digitalWrite(leds[randomLed],HIGH);
       delay(50);
 
       randomLed = random(0, 9);
       digitalWrite(leds[randomLed],LOW);
   }return;
}

 
}
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Tue Dec 11, 2012 9:19 am

mea culpa, I was wondering about that. Will do so next time. My thanks to the Mod for fixing it.

I don't have access to my PC right now so my code might be off. There may be an extra "}" I will check. There are nine LEDs in the array. the array processing is correct (I think). My intention was that the outer FOR loop runs the inner FOR loop 10 times and then returns to the loop function.

When powered by USB and running with the IDE open, the circuit behaves like expected. When I close the IDE, behavior becomes odd.
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by adafruit_support_bill on Tue Dec 11, 2012 11:28 am

When I close the IDE, behavior becomes odd.

Are you closing just the IDE? Or did you have the Serial Monitor open too?

Closing the serial monitor will reset the Arduino, but closing the IDE should have no effect at all.
User avatar
adafruit_support_bill
 
Posts: 28836
Joined: Sat Feb 07, 2009 9:11 am

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Tue Dec 11, 2012 12:14 pm

I am pretty sure I never opened the serial monitor but I will check tonight
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by harvey on Tue Dec 11, 2012 1:36 pm

I have a similar problem. I loaded a verified sketch which I have seen work via another user. When I hook up my wave shield and plug in the adrino, I get nothing.

HELP! This is a Christmas gift that I want to give away on Friday.

Harv
harvey
 
Posts: 2
Joined: Tue Dec 11, 2012 12:59 pm

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Tue Dec 11, 2012 8:33 pm

Well, it is not the serial monitor.

Again, the sketch loads and runs. If i shut the Arduino software the program continues to run. If I pull out the USB and then reconnect it the Uno starts but does not run the program. LEDs on pins 2 through 10 are set to HIGH for no reason I can discern.
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by adafruit_support_bill on Wed Dec 12, 2012 5:59 am

@Harvy - Please start a new thread. You issue sounds not quite the same as the OP. Post photos of the front & back of your shield.

@mikeJH - Post photos or a wiring diagram of what you have connected. When you remove the USB, how are you powering it? What happens when you press reset?
User avatar
adafruit_support_bill
 
Posts: 28836
Joined: Sat Feb 07, 2009 9:11 am

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Wed Dec 12, 2012 9:28 am

I shut the Uno down by unpluging the USB cable and then re-power it by plugging the USB back in without running the Arduino software. The LEDs on pins 6, 7. 8, 9 and 10 light up. Sometimes the LED on pin 7 seems to be blinking VERY fast sometimes it is steady. Pressing reset does not change the behavior.

I have swapped out the ATMEGA with a new one and the new one works fine under all conditions. With the new ATMEGA, the sketch runs when the Arduino software is running, when it is not running and connected via USB to another PC without Arduino software. I wonder if I damaged the original ATMEGA when I used the Uno as an ISP to program another ATMEGA. It just seems like the flash memory is not retaining the sketch. I am really getting ready to give up on this since the Uno seems to work OK with the new ATMEGA

Image
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by adafruit_support_bill on Wed Dec 12, 2012 9:41 am

Given that it works with a fresh Atmega chip, I suspect your diagnosis is correct. The original chip is not working properly and is possibly damaged,
User avatar
adafruit_support_bill
 
Posts: 28836
Joined: Sat Feb 07, 2009 9:11 am

Re: Uno R3 Problem with running a loaded sketch

by MikeJH on Thu Dec 13, 2012 8:33 am

Thanks for your help.

Is this circuit too much for a 9v battery? When I try to run using a 9v trough Vin and Gnd, a couple of the LEDs light up but that's all
MikeJH
 
Posts: 12
Joined: Mon Dec 10, 2012 11:18 pm

Re: Uno R3 Problem with running a loaded sketch

by adafruit_support_bill on Thu Dec 13, 2012 8:53 am

A fresh 9v should be able to handle more than a few leds. Check the battery voltage & verify that you have a good 5v on the 5v pin.
What resistor values are you using? 5.6K (as in the diagram) is a pretty high value.
User avatar
adafruit_support_bill
 
Posts: 28836
Joined: Sat Feb 07, 2009 9:11 am