arduino zero reset through software

hi

Does someone know how I reset the Arduino zero by software as I press the reset button.

I would like to do it with a launch file through rosserial. So at first before I launch everything else, get a reset, so that the arduino code start in the "setup".

Thanks

If you want the Arduino to restart in the code in setup() then put the required code in its own separate function and call it from setup() when the Arduino starts and at any other time that you want to put the Arduino back into its initial start state.

No exactly want I want.

But how would this function look like? What are the commands to reset the Arduino?

You said

so that the arduino code start in the "setup".

Calling a function with the commands that would normally be in setup() will have that effect.

The question of resetting the Arduino from code comes up from time to time but it usually a sledgehammer to crack a nut. Why exactly do you want to reset the Arduino ?

as stated in the question at first. I should probally describe it better:

I launch with rosserial my arduino. Then the arduino code starts in setup, the loop. If I now stop rosserial node I have to press reset manually to start the launch file again. Otherwise it doesn’t work correctly. So I would like to put some code in the launch file to reset the arduino zero.

So i would like to get the exact same functionality as I press the hardware reset button.

I have to press reset manually to start the launch file again.

I would like to put some code in the launch file to reset the arduino zero

I can't reconcile these two statements. If you have to press reset in order to start the launch file what good will it do to put code in the launch file to reset the Arduino ?

I start the launch file. Everthing is running. Then I for example want to end the process. So I stop it. If now I want to start everything again I have to first reset the arduino that it will start at the initialization precedure (the beginning of the arduino code) and then launch the launchfile. If I would not reset in between, everything gets screwed up.

If I now could reset the arduino from the launchfile this would be great, because I don’t have to reset the arduino manually.

I agree with the sledge hammer bit - there is also the possible issue that ( if you are running the bootloader) as the Arduino resets it looks to the serial port for a new sketch to be loaded , so you might have an issue there if you are using the port .

Resetting the processor like this is a bit of a bodge IMO - why can’t the Arduino loop looking for new data in the serial Buffer or some such thing . There must be an alternative

1) post your code 2) post a block diagram of what you want to accomplish 3) describe in detail what it does, and how it's different from what you want it to do.

So far I don't understand what your problem even is.

If you want to reset a variable, just set it back to zero.

gab27: I start the launch file. Everything is running. Then I for example want to end the process. So I stop it. If now I want to start everything again I have to first reset the Arduino that it will start at the initialisation procedure (the beginning of the Arduino code) and then launch the launchfile. If I would not reset in between, everything gets screwed up.

You were answered correctly in reply #1.

Actually, it is a little more complex. Essentially you have no actual setup() code - it is empty.

Your loop() now comprises three parts - your old setup() code, and a new "while" loop which contains all your old loop() code and is keyed on the condition for that code to continue. After that in the old loop() comes another "while" loop with the test for a restart which when permitted lets the actual loop() to return to the beginning and perform again the actual "setup" code and start the main process again.

The criteria for the two "whiles" are the "run/ stop" for your main process, and the key for a new reset. Your outer loop now contains the overall "start --> run --> stop --> wait --> reset"cycle.

ok thanks

Paul__B: Your outer loop now contains the overall "start --> run --> stop --> wait --> reset"cycle.

Now that sounds very much like a finite state machine.

wvmarle: Now that sounds very much like a finite state machine.

Does it?

The inner "run" section should always be a sort of finite state machine; most serious applications are, but I don't see it in the outer control loop.

You do list five distinct states of operation. Now in this case it's just moving forward through it, while most state machines move back and forth through the states, but that's just a detail.

OK. :grinning:

There is NVIC_SystemReset() I can't tell whether it will do what the original poster wanted or not, from their description, and I don't know how well it interacts with the Zero bootloader. But it's an ability to do a software-initiated reset that wasn't really available on AVR.