Did I just break my Arduino? (SOLVED!)

I have a project where I would like to manipulate ports to control an old sound chip. Anyways, since I'm pretty new to the more nitty gritty details of port addressing and such, and wanted to get more familiar with manipulating ports, I wired up a circuit with 8 LEDs connected to Port D on my arduino uno. I wrote a piece of code to make a simple "loading" effect on the LEDs, and uploaded it. It worked fine, but now I can't seem to upload anything to the arduino. I did read the arduino page on port manipulating, and it's warnings about the serial port, and made something in my program that I though would take care of it.

Here's my code:

void setup() {
  pinMode(13, INPUT);

}

void loop() {
  while(digitalRead(13) == HIGH){
    DDRD = B11111111;
    while(digitalRead(13) == HIGH){
      PORTD = B10000001;
      delay(50);
      PORTD = B11000011;
      delay(50);
      PORTD = B11100111;
      delay(50);
      PORTD = B11111111;
      delay(50);
      PORTD = B01111110;
      delay(50);
      PORTD = B00111100;
      delay(50);
      PORTD = B00011000;
      delay(50);
      PORTD = B00000000;
      delay(50);
    }
  }
  
  if(digitalRead(13) == LOW){
    DDRD = DDRD | B1111100;
  }
  

}

And here's the error message it gives when I try to upload anything to it:

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2009 Joerg Wunsch



         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"



         Using Port                    : COM3

         Using Programmer              : arduino

         Overriding Baud Rate          : 115200

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x2d

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x2d



avrdude done.  Thank you.



Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Did I just basically disable my arduino's serial port forever, or is there a way to fix it?

Also, sorry for any mistakes I made in where I placed this thread or the format I used, constructive criticism welcome.

Disconnect the LEDs from pins 0 and 1 while uploading code. Those pins are used for serial communication, which is how you upload sketches. The LEDs are dragging down (or up) the serial lines, preventing proper communication.

Do not hard code pin numbers in the code.

In this example you should use

int switch1 = 13;

Then refer to switch1 in the code. This makes the program easier to follow and allows the input to be changed on one place rather than in lots of places.

Weedpharma

Thanks for the quick replies!

DrAzzy, I did disconnect the LEDs, I'd found they stopped me from uploading in the first place.

Weedpharma, thanks for the suggestion, I will do that.

However, this still doesn't solve my problem, as I still can't upload to my arduino.

I'm wondering, however, on the Arduino page where I read about port manipulation, it said that this piece of code:

DDRD = DDRD | B1111100;

would just set pins 3-8 as outputs without changing the value of pins 1-2. So, my "failsafe" code does nothing, in effect, once I've pushed the button.

(Here's the page on port manipulation, if anyone wants: Arduino Reference - Arduino Reference)

Therefore, both the RX and TX pins are set as outputs. Does this basically mean I can't upload any code to it, or is there a way around that?

I think in the first case, I could just get another ATMEGA328P and replace the chip on my board (It's the DIP version), but I hate to have just wasted an otherwise perfectly good arduino chip.

When the chip is reset, which happens when you start uploading (the serial converter had a DTR pun that goes low, and it's capacitively coupled to the reset pin, thus resetting the chip when the serial connection is opened to upload.), at the pins are set back to default state. Then the bootloader runs, and only if it doesn't get anything over serial right after this test, will it run your code.

So that could not possibly be causing the problem. Usually using pins 0 and 1 causes the problem because of the hardware connected to those pins.

Hell, this is avr. The values of port, ddr etc registers are ignored if you have the serial port enabled.

Is it an Arduino board, or something on a breadboard? In the later I'd suspect a problem with the autoreset circuit.

It’s an Arduino board. I’m pretty sure it’s genuine, since I got it from a brand new official Arduino starter kit. I will try some things, but that’s nice to know I haven’t permanently disabled my chip. :wink:

Well!

I disconnected everything from my arduino and uploaded the Blink example successfully! I've no idea what was stopping it before, but I'm happy to know my arduino is working!

Thanks everyone for your helpful replies, at least I learned a few things. :wink: