arduino reset

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

arduino reset

Postby drummerboyx » Wed Apr 14, 2010 4: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 6:36 am


Re: arduino reset

Postby fat16lib » Wed Apr 14, 2010 7: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: 586
Joined: Wed Dec 24, 2008 12:54 pm

Re: arduino reset

Postby adafruit » Wed Apr 14, 2010 8: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
User avatar
adafruit
 
Posts: 10491
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: arduino reset

Postby johngineer » Wed Apr 14, 2010 8: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?
Poles up, zeroes down.
User avatar
johngineer
 
Posts: 103
Joined: Fri Aug 14, 2009 5:05 pm
Location: New Jersey, USA

Re: arduino reset

Postby drummerboyx » Wed Apr 14, 2010 9:51 pm

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

Re: arduino reset

Postby fat16lib » Wed Apr 14, 2010 10: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: 586
Joined: Wed Dec 24, 2008 12:54 pm

Re: arduino reset

Postby drummerboyx » Wed Apr 14, 2010 10: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 6:36 am

Re: arduino reset

Postby fat16lib » Thu Apr 15, 2010 7: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: 586
Joined: Wed Dec 24, 2008 12:54 pm

Re: arduino reset

Postby drummerboyx » Thu Apr 15, 2010 11:04 pm

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 6:36 am

Re: arduino reset

Postby drummerboyx » Thu Apr 15, 2010 11:28 pm

Also, I just found this on another forum:

Code: Select all
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 6:36 am

Re: arduino reset

Postby westfw » Fri Apr 16, 2010 12: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: 1321
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: arduino reset

Postby fat16lib » Fri Apr 16, 2010 8: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
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: 586
Joined: Wed Dec 24, 2008 12:54 pm

Re: arduino reset

Postby drummerboyx » Fri Apr 16, 2010 8: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 6:36 am

Re: arduino reset -- working hack!

Postby jmsaavedra » Tue Mar 08, 2011 4: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
//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: 10
Joined: Sat Nov 28, 2009 9:05 pm
Location: NYC

Next

Return to General Project help

Who is online

Users browsing this forum: No registered users and 10 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]