Uno R3 Problem with running a loaded sketch

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
MikeJH
 
Posts: 12
Joined: Tue Dec 11, 2012 12:18 am

Uno R3 Problem with running a loaded sketch

Post by MikeJH »

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?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Uno R3 Problem with running a loaded sketch

Post by adafruit_support_bill »

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?

MikeJH
 
Posts: 12
Joined: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

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

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: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

It has to be the chip. I swapped in a new ATMEGA and now I am able to run the sketch without the IDE

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: Uno R3 Problem with running a loaded sketch

Post by tldr »

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

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: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

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.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Uno R3 Problem with running a loaded sketch

Post by adafruit_support_bill »

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.

MikeJH
 
Posts: 12
Joined: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

I am pretty sure I never opened the serial monitor but I will check tonight

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

Re: Uno R3 Problem with running a loaded sketch

Post by harvey »

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

MikeJH
 
Posts: 12
Joined: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

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.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Uno R3 Problem with running a loaded sketch

Post by adafruit_support_bill »

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

MikeJH
 
Posts: 12
Joined: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

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

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Uno R3 Problem with running a loaded sketch

Post by adafruit_support_bill »

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,

MikeJH
 
Posts: 12
Joined: Tue Dec 11, 2012 12:18 am

Re: Uno R3 Problem with running a loaded sketch

Post by MikeJH »

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

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: Uno R3 Problem with running a loaded sketch

Post by adafruit_support_bill »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”