How to Soft Reset [code snippet]

If for some reason you need to start code execution from the very beginning, here is a couple of ways you can do it:

Pure C++. Cast 0x00 memory address into a function and execute it:

static_cast<void(*)(void)>(0)();

C++ & ASM. Use Assembler to jump to the beginning

asm("jmp 0");

The user has to be aware of the limits of that particular type of "reset". For a more complete reset, including most registers etc. you can also use the watchdog timer. See: Arduino Reset via Software including post #2 which refers to a StackExchange contribution by @Juraj

The various types of resets retain different categories of status information. A power fail restart is the most clean.

I’m using it for debugging my set up currently and for convenience, don’t know if you would ever need this as a feature

You can try these simple steps!
Arduino Leonardo board: Unplug the USB cable . Connect the RX Pin to ground. Plug in the USB cable.

  1. Prepare the basic empty program (empty setup, loop, etc.)
  2. Compile it.
  3. Reset the Arduino using the hardware button on the chip.
  4. Press Ctrl + U to upload your code.

Hope it helps!

setup();

wouldn't do?

Hit the reset button with a digital output or your finger

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.