Puzzling Problem Uploading to Arduino Uno

I have a sketch that uses digital pins 0-7 and the 5v and GND power pins. The sketch compiles correctly but will not upload; it results in "avrdude: stk500_getsync(): not in sync: resp=0x00" and
"avrdude: stk500_recv(): programmer is not responding" errors. If, however, I remove the jumper between my breadboard and the 5v power pin, the sketch will upload. If afterwards I reconnect the 5v pin, the sketch will run correctly.

I've tried many variants, but it boils down to this: if the 5v pin to my breadboard is connected, I can't upload ANY sketch without getting the above errors. I can't even upload a basic LED blinking sketch. I've tried another Arduino Uno, another cable, etc. but nothing works when the 5v pin is connected to my breadboard. I'm an Arduino newbie and as such quite ignorant but anxious to learn. I'd appreciate suggestions as to what wiring problem would prevent uploads and yet execute the sketch correctly.

Thanks for any and all help.

Just out of curiosity-- what type of table top are you working on? I do all my arduino work on a metal table :frowning: and if I forget to put newspaper or cardboard down, the 5V and GND pins short and I get that same error. If your breadboard has open wires on the underside, the power pins may be shorting. Check everything (arduino, breaboard) for possible shorts. Could you possibly also upload a picture?

Good Luck!

baum

The breadboard is insulated. The sketch involves a test of a 7-segment LED. It's a slightly modified version of The Arduino 7 Segment Display Counter from http://shortcircu.it/2011/02/05/arduino-7-segment-display-tutorial/. My modified version of the sketch is:

/* Seven-Segment LED Test
Based on the Arduino 7 Segment Tutorial and Code at
http://shortcircu.it/2011/02/05/arduino-7-segment-display-tutorial */

int i;

void setup() {
for (i = 0; i < 8; i++) pinMode(i, HIGH);
pinMode(8, LOW);
}

void loop() {
unsigned int LEDpins[] =
{ 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x98, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E };

for (i = 0; i < 16; i++) {
delay(1000);
PORTD = LEDpins*;*

  • }*
    }
    The Wiring employed is shown in Fritzing as:

That all looks fine... Can you post an actual picture of the setup?

(deleted)

Yep. That's it. Switch those two pins to 8+9. NEVER use pins 0 and 1.

Thanks folks. I'm sure that's it. I was a bit suspicious of pins 0 and 1 but those pins were used in the tutorial I followed and I thought it was cool because that way the PORTD command could be used to set all eight pins. OK back to the breadboard. Thanks again.

Two things.

  1. In the second for() loop of your code, shouldn't it be
    PORTD = LEDpins[i]; ?

  2. If you want to use PORTD as in the tutorial, use this:

PORTD = PORTD | B11111100

The "|" is a bitwise OR. It will leave pins 0 and 1 unchanged and set pins 2 thru 7 high.

Good Luck!

Thanks folks. I'm sure that's it. I was a bit suspicious of pins 0 and 1 but those pins were used in the tutorial I followed and I thought it was cool because that way the PORTD command could be used to set all eight pins. OK back to the breadboard. Thanks again.

You can still use the tutorial as written. Just disconnect those two wires while you are downloading the program.

Don

baum:
Two things.

  1. In the second for() loop of your code, shouldn't it be
    PORTD = LEDpins[i]; ?

  2. If you want to use PORTD as in the tutorial, use this:

PORTD = PORTD | B11111100

The "|" is a bitwise OR. It will leave pins 0 and 1 unchanged and set pins 2 thru 7 high.

Good Luck!

(1) You're absolutely right. It was correct in my original sketch but somehow I dropped the tail end when I copied it into my forum post.
(2) Thanks for reminding me about bitwise operators. They'll let me keep the revised code compact.

floresta:

Thanks folks. I'm sure that's it. I was a bit suspicious of pins 0 and 1 but those pins were used in the tutorial I followed and I thought it was cool because that way the PORTD command could be used to set all eight pins. OK back to the breadboard. Thanks again.

You can still use the tutorial as written. Just disconnect those two wires while you are downloading the program.

Don

You're right, Don. The tutorial code works well after one manages to load it. I've learned, though, that using pins 0 and 1 for anything but their intended (RX,TX) purpose is not good practice so probably shouldn't be used in a tutorial without a caution for newbies like me. I'll see if I can post a note there.

Problem solved by shifting all pins in my wiring diagram from 0-7 to 2-9. And, as I can't use the PORTD command effectively, I've had to revise the sketch code to:

// Seven-Segment LED Test
//
// Based loosely on the Arduino 7 Segment Tutorial and Code at
// http://shortcircu.it/2011/02/05/arduino-7-segment-display-tutorial
//
// NOTE that
// for an LED segment to be on, its pin must be LOW (0)
// for an LED segment to be off, its pin must be HIGH (1)
//
// In the wiring for this test, pins 2-9 correspond to
// shield segments 0-7, respectively

int i, j, k;

void setup() {
for (i = 2; i < 10; i++) pinMode(i, HIGH);
}

void loop() {
unsigned int LEDpins[] =
{ 0x03, 0x9F, 0x25, 0x0D, 0x99, 0x49, 0x41, 0x1F,
0x01, 0x19, 0x11, 0xC1, 0x63, 0x85, 0x61, 0x71 };
unsigned pinMasks[] =
{ 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
unsigned int LEDpin, pinMask;

for (j = 0; j < 16; j++) { // for all 16 hex numbers
delay(1000);
LEDpin = LEDpins[j];
for (k = 0; k < 8; k++) { // for all 8 pins
pinMask= LEDpins[j] & pinMasks[k];
i = k + 2;
if (pinMask != 0)
pinMode(i, LOW);
else
pinMode(i, HIGH);
}
}
}

Compiles, loads, and works! And besides learning how to use a 7-segment shield, I've learned how to use the PORTD command effectively, I've relearned binary and hex, I've learned about bitwise operators, and I've learned how helpful the Arduino forum can be. Thanks again everyone. And any suggestions for simplifying and/or compacting the code will be welcomed.

Final simplified version of wiring and sketch:

// Seven-Segment LED TestSeven-Segment LED Test
//
// Based loosely on the Arduino 7 Segment Tutorial and Code at
// http://shortcircu.it/2011/02/05/arduino-7-segment-display-tutorial
//
// NOTE that
// for an LED segment to be on, its pin must be LOW (0)
// for an LED segment to be off, its pin must be HIGH (1)
//
// In the wiring for this test, pins 2-9 correspond to
// shield segments 0-7, respectively

#define ON 0
#define OFF 1

int i, j;

void setup() {
for (i = 2; i < 10; i++) pinMode(i, OFF);
}

void loop() {
unsigned int LedPins[] =
{ 0x03, 0x9F, 0x25, 0x0D, 0x99, 0x49, 0x41, 0x1F,
0x01, 0x19, 0x11, 0xC1, 0x63, 0x85, 0x61, 0x71 };

for (j = 0; j < 16; j++) { // for all 16 hex numbers
delay(1000);
for (i = 2; i < 10; i++) { // for all 8 pins
if (bitRead(LedPins[j], 9-i) != 0)
pinMode(i, ON);
else
pinMode(i, OFF);
}
}
}