Pages: [1]   Go Down
Author Topic: How do I reset the Arduino programmatically?  (Read 3338 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Is it possible to reset the Arduino via software in such a way that the Arduino thinks it's being powered on for the first time?

I Googled before coming to the forums and found this:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235780325/all

But, the thread is a couple years old, and I don't have enough technical knowledge to understand whether doing it this way is safe to use.  Any advice?

Code:
void(* resetFunc) (void) = 0; //declare reset function @ address 0
...
resetFunc();  //call reset

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27099
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Search within the forum instead. This was discussed here within the last few weeks.
I think PaulS, Awol, or Nick Gammon had the solution.
Read the data sheet too - power on reset, hardware reset, software reset, not all do quite the same thing; but may end up doing what you need.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18801
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

But, the thread is a couple years old, and I don't have enough technical knowledge to understand whether doing it this way is safe to use.  Any advice?

What you posted re-enters the program at the point where a hardware reset would. However it doesn't reset the hardware.

I think there was a recent post about using the Watchdog timer to do a (hardware) reset. Try searching for that.
Logged


UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got to ask, but is this to solve a software problem you are having?

If its to effectively run 'setup' again, you can just call 'setup' from anywhere you like.

Logged

--
My New Arduino Book: http://www.arduinobook.com

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

I don't know if it's a software problem per se.  I would just like the ability to reset the Arduino every once in a while, because it seems that after several days of 24/7 operation the program freezes or gets stuck.

My program gets weather & stock market data from the internet via a Wifi shield, and changes the color of an RGB LED setup accordingly.  It works great for days at a time, but sometimes it would just get "stuck" by not changing colors as it should. 

I would like to mess around and see if resetting the Arduino programmatically, while not solving the underlying problem of the freezes, gets rid of the freeze ups to a degree that I can live with.
Logged

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Freezing like that is probably a sign of memory leaks or buffer overflows, and so, a periodic reset may well cure it, so follow some of the links on the Watchdog timer idea. That is for this kind of situation.

I always try and allocate all memory statically and stay away from things like the String class and be very careful with my array indices when writing into buffers. But it could well be something buried deep in a library somewhere, in which case it would take a lot of patience to winkle it out.
Logged

--
My New Arduino Book: http://www.arduinobook.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
in which case it would take a lot of patience to winkle it out.
On the other hand, if you were to find (and fix) a problem in a library, that would benefit everyone that uses that library, and you would learn a lot about debugging in the process.

Resetting is rarely a good idea.
Logged

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Resetting is rarely a good idea.

Thats my instinct too, but why do microcontrollers generally have the facility of a watchdog timer to reset them?

I have an Arduino heating thermostat that has been running for months without any problems.

Is it solely to cope with sloppy programming? Or are there other reasons the microcontroller can freeze? Voltage transients that don't kill it, but do affect the RAM or register state for instance?

I'm curious.
Logged

--
My New Arduino Book: http://www.arduinobook.com

0
Online Online
Shannon Member
****
Karma: 206
Posts: 12186
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Watchdog timers can be used to interrupt code that's got stuck, or to wake up the processor regularly to save battery life, or any other use you care to make.  Typically watchdog timer circuit is micropower (but not very accurate).
Logged

[ I won't respond to messages, use the forum please ]

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sure I remember reading something about engine management units that reset themselves frequently with a watchdog timer.

Any of you proper embedded guys out there know why this is done?
Logged

--
My New Arduino Book: http://www.arduinobook.com

New Jersey
Offline Offline
Faraday Member
**
Karma: 67
Posts: 3694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you're using the Async labs library for your wifi, take a look at this thread: http://arduino.cc/forum/index.php/topic,75915.0.html. There's a fix there for buffer overruns that were causing me similar lockup issues
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1040
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use a reset IC
Logged

Trabajando en ...

    * Control Domotico (En montaje ...)
    http://casitadomotica.blogspot.com/
 

[url=https://bitbucket.org/fmalpartida

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

While having to reset a system is often due to misbehaving software, it does have its uses.
Attached is a watchdog timer sketch that I wrote to demonstrate how to reset the AVR using
a software function.

I will caution you that depending on which bootloader you have, you may not be able to use
the watchdog reset functionality because the bootloader will get stuck in a continuous watchdog reset.
Also, reseting the AVR is not the same as a full hardware reset in that other components
that are attached to the the AVR will not see any sort of RESET nor will they experience a powerup
so they will not be restored to their initial power up state.

If you are using a an older Arduino board, I'd recommend updating the bootloader to the
latest optiboot bootloader as it is smaller, faster, and also supports using the watchdog reset.

--- bill


* wdt.pde (0.39 KB - downloaded 40 times.)
« Last Edit: December 08, 2011, 02:08:46 pm by bperrybap » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18801
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thats my instinct too, but why do microcontrollers generally have the facility of a watchdog timer to reset them?

I helped with a project a little while back where the poster wanted to take temperature (or something) readings every few minutes, but be powered by a battery. Taking a reading, and then going to power-down sleep, let it consume only a handful of microamps until the watchdog woke it up again. Although the maximum watchdog interval is 8 seconds, you can string those together to make a longer time.

Another approach is to "power up" an onboard clock, check the real time, and if not the wanted time (eg. time to feed the fish) go back to sleep.

Finally for things like a burglar alarm, where - who knows why it might fail? - you want to make sure it keeps working, you might reset it if the "dog" isn't "patted" every second or so.

For example, I suspect that satellites sent to Jupiter or wherever have such a timer, so that some coding error that goes undetected for years doesn't mean the loss of the satellite.
Logged


Pages: [1]   Go Up
Jump to: