Pages: [1]   Go Down
Author Topic: reset code  (Read 463 times)
0 Members and 1 Guest are viewing this topic.
Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is there a comand that will reset the arduino


thanks
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could set the watchdog timer for a short timeout, or insert a line of assembly "jmp 0", which will restart the code but not reset the IO pins and that sort of thing.

However, in nearly every instance, you should redesign your code rather than require a reset.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could wire a digital pin to the reset pin and reset it that way.
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could wire a digital pin to the reset pin and reset it that way.

The datasheet specifically advises against that, actually. The IO pins get set back to high impedance  before a "full" reset happens.
Logged

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2739
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a sample sketch that resets the AVR using the watchdog reset.
I don't know what Arduino board or bootloader you have so
I will caution you that unless you have an updated bootloader or the optiboot bootloader,
the avr will get stuck infinitely reseting itself as the older bootloaders do not properly handle
the watchdog reset.

The symptom of this infinite reset is that you will not see the setup message nor the countdown
more than once. If it is working, then you will see these repeat.

--- bill
Code:
#include <avr/wdt.h>

void setup()
{
Serial.begin(9600);
Serial.println("setup()");
}

void loop()
{
Serial.println("Top of loop()");
for(int x = 3; x ; x--)
{
Serial.println(x);
delay(1000);
}
Serial.println("Reseting Arduino");
resetArduino();
}

void resetArduino()
{
wdt_enable(WDTO_15MS);
noInterrupts();
while(1); // wait to die and be reborn....
}
Logged

Pages: [1]   Go Up
Jump to: