0

arduino reset
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

arduino reset

by drummerboyx on Wed Apr 14, 2010 5:45 pm

Is it possible to have the arduino reset itself? Because I'm using an Ethernet shield and sometimes you have to reset it a couple of times to get it to connect. And it does that if the power goes out. So can the arduino have a command like this:

if (client.connect()) {
//do stuff here
} else {
//reset it self here
}

So it resets it self if it doesn't connect.

Thanks,
Elijah
drummerboyx
 
Posts: 80
Joined: Wed Feb 10, 2010 7:36 am

Re: arduino reset

by adafruit_support_bill on Wed Apr 14, 2010 8:34 pm

According to Atmel, you can set the internal watchdog and let it time out:
http://support.atmel.no/bin/customer?=&action=viewKbEntry&id=21

adafruit_support_bill
 
Posts: 52880
Joined: Sat Feb 07, 2009 10:11 am

Re: arduino reset

by fat16lib on Wed Apr 14, 2010 8:52 pm

A software reset is not easy on the Arduino. Atmel suggests using a watchdog timeout but this is not possible since the watchdog is not disabled as required by the Arduino bootloader http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260378037. The Arduino will go into a loop of resets in the bootloader.

The watchdog is the only method recommended by Atmel http://support.atmel.no/bin/customer?=&action=viewKbEntry&id=21

Even connecting reset to a digital pin is not reliable according to Atmel because the digital pin goes tristate and releases reset too soon. You need an external circuit that will hold reset low for sufficient time.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: arduino reset

by adafruit on Wed Apr 14, 2010 9:50 pm

if you happen to have an adafruit arduino chip (the upgrade one or in a kit, not in an existing arduino) - our mod disables the WDT on startup so you can use it

adafruit
 
Posts: 12105
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: arduino reset

by johngineer on Wed Apr 14, 2010 9:54 pm

fat16lib wrote:Even connecting reset to a digital pin is not reliable according to Atmel because the digital pin goes tristate and releases reset too soon. You need an external circuit that will hold reset low for sufficient time.


said external circuit could be as simple as a diode-protected RC circuit connected to a 7414, no?
Adafruit Director of Imaging
Member of Technical Staff
Poles up, zeroes down.
User avatar
johngineer
 
Posts: 105
Joined: Fri Aug 14, 2009 6:05 pm
Location: Brooklyn, NY, USA

Re: arduino reset

by drummerboyx on Wed Apr 14, 2010 10:51 pm

Can I use the Atmel reset method with the MEGA?
drummerboyx
 
Posts: 80
Joined: Wed Feb 10, 2010 7:36 am

Re: arduino reset

by fat16lib on Wed Apr 14, 2010 11:17 pm

The mega I have is not WDT friendly but it is old so new ones may work.

You can build a WDT friendly bootloader and burn it. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1255016475/1.

If you load a sketch into an Arduino without the WDT bootloader mod and it goes into the reset loop you need to power cycle the Arduino to load another sketch.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: arduino reset

by drummerboyx on Wed Apr 14, 2010 11:41 pm

What do you mean "power cycle"? So if I try the method that atmel discribes and it doesn't reset properly it will go into a loop? Is it permently damaged?
drummerboyx
 
Posts: 80
Joined: Wed Feb 10, 2010 7:36 am

Re: arduino reset

by fat16lib on Thu Apr 15, 2010 8:32 am

The chip will not be damaged. You just can't download to it while it is an endless loop of WDT resets. cycling power clears the WDT enable bit and you have a few seconds to start a download from the Arduino IDE.

Cycling power seems to be the only reliable way to end the reset loop. The reset button doesn't seem to clear WDE.

This will not happen if you have a bootloader built with WATCHDOG_MODS defined.

Here is info about burning a new bootloader http://www.arduino.cc/en/Hacking/Bootloader.

I use the Adafruit USBtinyISP to burn bootloaders. I do it on an old XP 32-bit system.

I am not sure of the current Windows 7 64-bit driver situation. Driver signing is a big problem for lots of open source software for USB devices.

You may be able to burn the bootloader in you mega using another Arduino http://arduino.cc/en/Tutorial/ArduinoISP. I have not tried it but it may be a solution to the Windows 7 64-bit driver problem. You will need to use the correct SPI pins for the mega, not the ones shown for a 168/328.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: arduino reset

by drummerboyx on Fri Apr 16, 2010 12:04 am

Ok...I'll definitely try out the Atmel solution without the bootloader first and if that doesn't work I'll install the new bootloader.

I'm still sort of confused; what do you mean by power cycling? I want to try all these ideas out, but I need to know how to get it out of the reset loop...

Thanks guys!

Elijah
drummerboyx
 
Posts: 80
Joined: Wed Feb 10, 2010 7:36 am

Re: arduino reset

by drummerboyx on Fri Apr 16, 2010 12:28 am

Also, I just found this on another forum:

Code: Select all | TOGGLE FULL SIZE
void (*softReset) (void) = 0; //declare reset function @ address 0
softReset();


On the forum it said that this will reset the Ethernet shield just fine even though it's not a "full" reset. Is this true?
drummerboyx
 
Posts: 80
Joined: Wed Feb 10, 2010 7:36 am

Re: arduino reset

by westfw on Fri Apr 16, 2010 1:06 am

Being able to reset possibly-flakey hardware devices (like the ethernet chip. (Like MANY ethernet chips over the history of ethernet!)) is a good thing, but does not mean you need to reset the Arduino-side as well. I think there was another post somewhere on rewiring the Wiznet reset signal to one of the Arduino's digital output pins, so that it could be reset easily without disturbing the sketch...
User avatar
westfw
 
Posts: 1377
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: arduino reset

by fat16lib on Fri Apr 16, 2010 9:41 am

I think westfw has the best solution. You should try to deal with flaky hardware in the context of the problem. If you do a software reset your program will not know that it was restarted due to a hardware problem. The bootloader will clear the registers that indicate you did a software reset using WDT.

The
Code: Select all | TOGGLE FULL SIZE
void (*softReset) (void) = 0;
idea is not too useful here. It just restarts your program without initializing the state of the ATmega chip like a true reset.

Sorry, I got carried away with how WDT works and not how you should solve your problem. Using WDT here is kind of a Hail Mary play.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: arduino reset

by drummerboyx on Fri Apr 16, 2010 9:59 am

Ok so I will try to find a reset pin on the ethernetsheild from Nutronics(sp?). Can someone give me an idea on where I can find it?
drummerboyx
 
Posts: 80
Joined: Wed Feb 10, 2010 7:36 am

Re: arduino reset -- working hack!

by jmsaavedra on Tue Mar 08, 2011 5:08 pm

Hi all - we figured out a hack recently be reset an Arduino through controlling a digital pin. It's definitely a hack, but it works on a MEGA 2560 and also on a duemilanove328. Haven't tried on any other boards. Interestingly, I also needed this for an ethernet project... Hope this helps someone!
Code: Select all | TOGGLE FULL SIZE
//digitalPin 7 is connected to the RESET pin on Arduino
//NOTE: you CANNOT program the board while they are connected
//by default digitalPin 13 will blink upon reset, so stick an LED in there

int interval = 5000;
long int time = 0;

void setup(){
  digitalWrite(7, HIGH); //We need to set it HIGH immediately on boot
  pinMode(7,OUTPUT);     //We can declare it an output ONLY AFTER it's HIGH
                         // (( HACKHACKHACKHACK ))
  Serial.begin(9600);    //So you can watch the time printed
}


void loop(){

  time = millis();
 
  Serial.println(time);
 
  if(time > interval){
    Serial.println("RESET!");
    digitalWrite(7, LOW); //Pulling the RESET pin LOW triggers the reset.
  }
}

jmsaavedra
 
Posts: 12
Joined: Sat Nov 28, 2009 10:05 pm
Location: NYC

Please be positive and constructive with your questions and comments.