Software Command a Reset

Is it possible to command an Arduino to RESET via a command in the Arduino code? No such command is obvious as far as I can see.

One possibility that occurs to me is to put a setup(); statement in the code.

Why do you want to know?

Why didn't you search before you asked?

One possibility that occurs to me is to put a setup(); statement in the code

Your "setup" already comes after "init" in "main", so a lot has already gone on, even before "main" starts.

As has been hinted, this question comes up regularly.
I think the best way is to enable the watchdog, and wait for the inevitable, but there is rarely a good reason for your software to commit suicide like this.

check http://support.atmel.no/bin/customer?=&action=viewKbEntry&id=21

Gee. Such hostility.

Why do you want to know?
Why didn't you search before you asked?

I am a hobbyist who is experimenting with the Arduino; not a professional hardware developer or C coder.

I am trying to build a Reverse Geocache puzzle box, described generally on the Arduiniana site, but am also adding other features to it. Since the puzzle box is described only in general terms, at every step I have had to learn how to make the hardware work together and figure how to write the needed code. I am not complaining about this because I have learned things at each step.

The project I am building has a normal path for the logic (when the Arduino is not attached to the PC via its USB cable), which I am making good progress on. One thing the project does is turn itself off after it runs normally, waiting to be awakened by a push of a button. I am using a Pololu low power switch to do this.

I am also building a way for the Arduino to be awakened by connecting its USB cable to a PC to allow the user to run a Windows program, which I will write, on the PC (which will communicate via the USB link to the Arduino) to download different parameters to the Arduino board. I am assuming that I will then have to RESET the Arduino to start up again just as if it had had its new parameters downloaded by the Arduino development program. Of course I may be wrong.

Just to get to this point took me five weeks purchasing the hardware plus another three weeks working on the Arduino code. Each time I made a hardware purchase I'd learn that I needed something else to make the project. In the end I made as many as four different purchases at a single web store to get all the parts to make the project.

Now, I am working on solving such issues as getting a GPS and servo to work with each other without the servo getting all twitchy each time the GPS is accessed.

I am trying to get this project finished in time to be a Christmas present. I already have two full months of intense work to get to this point and asked about RESET on this forum to try to get an answer for the next phase of my development of the project.

While working on the Arduino code, I have tried to find examples of how to do what I wanted. In the end, I had to learn for myself such things as how to enter and exit the LOOP processing from two completely different parts of the code and perform two completely different functions while in the LOOP.

I did search for an answer about RESET but did not understand technically what I had found.

I am not proficient with C code. I normally use Delphi for my hobbyist programs I write for a PC. That environment has much better support for basic functions like string manipulation, which I have had to write for myself for the Arduino environment.

With the Arduino coding environment, I can not decide what I want done and then just write code to do it. Every time I try to do something in the code, I try to figure how I think it would work and then when I actually attempt some code, I have to modify my "design" based on how the code seems to work.

I had looked through all the software commands available for the Arduino and the libraries to see if such a function was available and didn't find any commands that seemed to do what I wanted.

I thought I could find a helpful person to point me in the right direction. I didn't mean to insult anyone with a silly question or waste your time.

I want to emphasize that this is not directed at everyone. I appreciate the help from some of you.

No hostility intended, but this question pops up about once a month.
A simple call via a null pointer will restart the whole show, but it is not exactly a processor reset.
If you think you need a reset, it may simply be that your code is structured wrong.

I did search for an answer about RESET but did not understand technically what I had found.

Could you explain what you found and what you don't understand in more detail? Sharing (problem) code gives us something to work with.

Rob

A simple call via a null pointer will restart the whole show, but it is not exactly a processor reset.

This may be simple to you and it sounds just like what I need but what exactly is a "simple call to a null pointer"; more specifically, what would the code look like to do this?

This may be simple to you and it sounds just like what I need but what exactly is a "simple call to a null pointer"; more specifically, what would the code look like to do this?

Not until you explain why you want to reset the Arduino.

void (*pseudoReset)(void)=0;

pseudoReset ():

Oops. i done a bad thing.

Really, you need to rethink the structure of your code.
This is a nasty sticking-plaster fix.

void (*pseudoReset)(void)=0;

pseudoReset ():

Thank you. As you can see, this is not exactly obvious to a person new to C programming. I've used Pascal and Delphi for my hobby programming projects since 1983, starting with using Turbo Pascal on a Kaypro II CP/M microcomputer with two 5.25" floppy drives for storage. Long ago I looked at using C but decided to stick with Delphi because it seems like C programmers always try to make their code as obscure as possible and try to jam as much functionality as possible into a single line of code. It is not always easy to follow what a C programmer is trying to do with their code.

I know that some of you still want to know why I want to reset the Arduino. As I described in my long post above, each step forward I make with my project I learn more about how the Arduino hardware and software works. Some things don't exactly work the way I thought they would. I may or may not need to restart or reset the Arduino. I think I may have to. I don't yet know.

Once I get to the point where my Arduino code accepts download of new parameters (Lats and Longs for a different GPS destination and/or a command to force the servo to move plus a few more possible parameters) from the PC application, I will know whether a reset; pseudo or otherwise will be necessary.

I only yesterday got the comms logic in the Arduino to begin to work (using the serial monitor to send data to the Arduino rather than the Delphi program I still need to finish writing). Even this "simple" function for which I found several examples of possible code to use wasn't that easy to get working. The first couple examples of code I tried gave me compiler errors which I was not able to resolve. So, with my usual approach, I kept trying other examples until I found one that I could get working.

Whether I need a RESET or not won't be known to me until I get to the point where I think I may need one. I will then see what the Arduino project design/code I have at that point demands one.

I am now working on extracting the data from the PC link so it can revise the parameters in the Arduino. Once I get to that point I will be able to know what steps I need to "restart" the Arduino with the new parameters. I will take your advice and try to avoid doing this reset if I can.

Gee. Such hostility.
Why do you want to know?

Let me get this straight. I take the time to ask you for details about your application so that the folks on this forum can provide you with a better response and you accuse me of being hostile. Repeating your accusation while standing in front of a mirror would be more accurate.

Why do you want to know?
I take the time to ask you for details about your application so that the folks on this forum can provide you with a better response and you accuse me of being hostile.

Since I don't want to engage in a flame war I will make this comment and no other.

You didn't really ask for details. You made it sound like I was asking about a classified secret.

If you didn't have enough information from my original post to give any help then how was I supposed to answer your response? My answer obviously would have been "because I need to reset the Arduino via software in my project".

Neither your response or one that I would given to it would have moved the discussion forward.

Maybe your response was less than artfully worded and maybe I read into it something that wasn't there.

Beginners like me who come to this board for help do not do it to antagonize others who try to help. Keep in mind that we may not be able to succinctly describe the relevant part of our projects or why we ask our questions.

"because I need to reset the Arduino via software in my project".

You know what?
I've been programming these things for about four years now.
Never once needed a software reset.
(or wanted one for that matter)

Never once needed a software reset.
(or wanted one for that matter)

Lots of people trying to figure out how to prevent them. Maybe OP and those people ought to arrange a swap.

You didn't really ask for details.

Didn't I? What exactly do you think "Why do you want to know?" means?

You made it sound like I was asking about a classified secret.

Did I? Amazing. All that hidden meaning in those six words.

Maybe your response was less than artfully worded

Is there a way to phrase "Why do you want to know?" so that it's "artfully worded"? Should I have used a different font?

and maybe I read into it something that wasn't there.

Ya think?

Beginners like me who come to this board for help do not do it to antagonize others who try to help.

And yet, there it is. "Gee. Such hostility."

Keep in mind that we may not be able to succinctly describe the relevant part of our projects or why we ask our questions.

You did fine.

A simple call via a null pointer will restart the whole show, but it is not exactly a processor reset.

This may be simple to you and it sounds just like what I need but what exactly is a "simple call to a null pointer"; more specifically, what would the code look like to do this?

// definition
void(* resetFunc) (void) = 0; //declare reset function @ address 0

...
// call reset if needed
if (thingsAreReallyBad == true) resetFunc();
...

I used this function definition in the code of a sketch to restart my ethernetshield when it could not connect anymore to a webserver. (different story).
In plain text the function definition says if you call the function, it will start executing the code at address 0. This seems to be / is the entry-point where the Arduino normally starts, and it worked perfectly for my sketch.
However, it is not a 100% reset of the Arduino. In PC terms it is similar to the difference between a warm and cold reboot. A cold reboot (= power off, wait, power on) resets every part of every chip in the PC, maybe except for the RTC and EEPROMS. The URL to ATMEL I mentioned earlier, points to code how to do a cold reset according to the producer of the Arduino Chip. (never used it, no experience)
Calling the resetFunc() as defined above, is more like a warm reboot of the PC. Don't know the details myself but timers in the Arduino and registers etc are not (all/completely) reset by this call. For example, if you have a timer programmed to produce an 38.5Khz square wave on some pin it may keep doing so. Or if a timer counts down to zero and calls some IRQ-routine every time the timer reaches zero, it still might doing so after the warm resetFunc(). This might interfere unexpectedly with your code after the reset.

But as said earlier I do not know all the details, I just try to summerize what I have learned sofar about reset().

Hopes this helps.

I guess some of the emotional and/or heated response to your reset question might be because it comes up so often and the general agreement that there is almost no reason to use such a function in all but the most obscure applications. A software reset is almost always a 'cop out' to cover up basic software problems or bugs and best be handled by proper program structure and debugging.

It's kind of like using the dreaded GOTO statement in C/C++, the language allows it's use but you will get lots of push-back from most if you actually use it for all but the most rare situations. :wink:

Let me ask all this. If such a function was really useful or recommended wouldn't the Arduino IDE have such a function already defined as it is such a simple function? Why might they have not included it?

Lefty

GOTO

He said the 'G' word