bricked boards by code - how to fix them?

Hi there,

Recently I bought three copy of arduino boards, one arduino nano and two arduino pro mini.

I wanted to create several auto switches with them using rtc.

The problem occurred when I uploaded the code, and after that my boards are unusable, I cannot flash new code to them.
I tried several approaches, to use arduino uno to flesh them, to use ftdi board but all that ended with the same result - on board led (13) is rapidly flashing.

So my question is, did I burn the boards and is there a “cure” for this problem?

Here is the code that I uploaded to the boards:

#include <DS3231.h>
#include <avr/wdt.h>

#define LED 13 //LED_BUILTIN
DS3231  rtc(SDA, SCL);

void setup() { 
  pinMode(LED, OUTPUT);
  wdt_enable(WDTO_4S);
  Serial.begin(9600);  
  Serial.println("SETUP");
 rtc.begin(); // Initialize the rtc object
// rtc.setTi rme(21, 52, 0);
 }

void loop() {
  Serial.print("Time: ");
  Serial.println(rtc.getTimeStr());
  int shouldTurnOn = checkTime();
  turnOn(shouldTurnOn);
  delay(1000);
  wdt_reset();
}

int checkTime(){
  Time currentTime = rtc.getTime();
  if(currentTime.hour>=0 && currentTime.hour<8){
    return HIGH;
  }else{
    return LOW;
}
}

void turnOn(int turnOn){
  if(turnOn == 1){
    Serial.println("Heater ON");
    digitalWrite(LED,LOW);
  } else {
    Serial.println("Heater OFF");
    digitalWrite(LED,HIGH);
  }
}

And the console output of Arduino IDE is:

Sketch uses 930 bytes (3%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

EDIT:

Also, it is interesting that board is working just fine(when it comes to executing the code) when I connect RTC to arduino.

And I managed to flash the board(arduino nano) in this state. Does anybody know what is going on?

thanks,
Lazar

This is a known bug with the ATmegaBOOT bootloader used by the Pro Mini and the old official and derivative Nano boards: https://github.com/arduino/Arduino/issues/4492 After a watchdog reset, the board goes into an endless reset loop.

The solution is to connect an ISP programmer to the boards and then do a Tools > Burn Bootloader. This is also a perfect opportunity to install a modern bootloader that does not have the bug. If you have the ATmega328P Nano and the Pro Mini (5V, 16 MHz) w/ ATmega328P, the easiest way to do this is to simply select Tools > Board > Arduino/Genuino Uno before you do the Burn Bootloader process and then always use the boards with Arduino/Genuino Uno selected from then on. The Uno has the same hardware configuration as those Nano and Pro Minis, but it uses the modern Optiboot bootloader. Not only does Optiboot have the watchdog bug fixed, it also fits in a smaller boot section, which frees up 1.5 kB of precious flash memory!

If you have another variant of the Nano or Pro Mini, you can still use optiboot but the process is different. I can give you instructions for that if you need them.

If you don't own an ISP programmer, you can use a spare Arduino board as an "Arduino as ISP". There are instructions for that here: https://www.arduino.cc/en/tutorial/arduinoISP

Thanks buddy, you saved my day. I was about to throw away these boards. :D

I have arduino uno and will use it to burn new bootloader.

Once again, Thank you!

You're welcome. I'm glad if I was able to be of assistance. Enjoy! Per

Hi, it's me again,

I have installed new bootloader on arduino pro mini, but the same bug is happening.

I think that the problem is related to a library for RTC.

Solution for this is connect rtc to the board, power up board and then flash new code.

Anyway, thanks for the help, now I can flash arduino nano without holding reset button.

Cheers!

:sunglasses: