How to reset Arduino UNO without pushing reset button?

Anybody, I would like to reset my Arduino UNO just via sending serial command, is it possible and safe for the chip?
Could it be done without pushing reset button?

Thank you ..

creativen:
Anybody, I would like to reset my Arduino UNO just via sending serial command, is it possible and safe for the chip?
Could it be done without pushing reset button?

Thank you ..

Sure, just learn about using the watch dog timer (WDT), your sketch upon receiving the magic serial command could just activate the WDT which will cause a reset and start you sketch from it's start.

Lefty

Yes and yes. When the command is recognized from the serial interface, set the watchdog timer for a short interval (I think 16ms is the shortest), and enter a spin loop. Search the forum for specifics, this gets discussed with fair regularity.

Just be sure your arduino board is one that has a WDT friendly bootloader such as the current UNO, as older and current mega boards for example will 'brick' with short WDT interrupts, requiring you to reburn the bootloader to recover.

Lefty

creativen:
I would like to reset my Arduino UNO

In most cases you can do it just by closing and reopening the serial port. But why do you want to reset it?

PeterH:

creativen:
I would like to reset my Arduino UNO

In most cases you can do it just by closing and reopening the serial port. But why do you want to reset it?

I just would like to take control my Arduino without touching it, it's cool if I can reset from distant afar.

I just would like to take control my Arduino without touching it, it's cool if I can reset from distant afar.

The question is why? Opening and closing the serial port resets the Arduino, unless you've modified. That seems sufficient to me.

creativen:
it's cool if I can reset from distant afar.

If being 'cool' is your only reason then I don't see any point. It's not as if you will get to see those LEDs flash briefly as it resets. And what other reason would you have for wanting to reset it?

Maybe he's writing a reboot-count sketch ? :stuck_out_tongue:

retrolefty:
Just be sure your arduino board is one that has a WDT friendly bootloader such as the current UNO, as older and current mega boards for example will 'brick' with short WDT interrupts, requiring you to reburn the bootloader to recover.

Lefty

So how to software reboot MEGA then?

liudr:

retrolefty:
Just be sure your arduino board is one that has a WDT friendly bootloader such as the current UNO, as older and current mega boards for example will 'brick' with short WDT interrupts, requiring you to reburn the bootloader to recover.

Lefty

So how to software reboot MEGA then?

Use external hardware components (555 pulse generator for example) to generate a reset pulse wired to the avr reset pin.

Or find a upgraded bootloader hex file that does handle WDT correctly for the mega board and burn that into the chip before using the WDT generated reset method.

Lefty

So how to software reboot MEGA then?

Depending on exactly what you want to do, use a call to location zero as in:

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

Or, if you want something more watchdog 'timerish', use the code I worked out to do this. I wanted to simulate a watchdog and not use up any of the other timers. It's at: Desert Home: The 2560 Board is Not So Stupid Anymore

Lefty,

By upgraded bootloader are you referring to optiboot developed by westfw?

draythomp:

So how to software reboot MEGA then?

Depending on exactly what you want to do, use a call to location zero as in:

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

Or, if you want something more watchdog ‘timerish’, use the code I worked out to do this. I wanted to simulate a watchdog and not use up any of the other timers. It’s at: Desert Home: The 2560 Board is Not So Stupid Anymore

Thanks. I know of the location zero but also vaguely remember people mentioning that just the execution is reset and other things aren’t. Could you give me some hint on what does and doesn’t reset by calling zero?

BTW, your home page temperature scale is in DegF, right? Does it every go near 150F as the max scale is set there? Horrible heat.

liudr:
Lefty,

By upgraded bootloader are you referring to optiboot developed by westfw?

Depends on the type of mega board you are talking about. There is a optiboot avalible for the mega1280 board but westfw already stated the optiboot will never work with a mega2560 board. However there is a upgraded/fixed mega2560 bootloader avalible that works with the WDT correctly, but at the moment I can't steer you to it's location as I don't own a mega2560 board I never bothered to download a fixed bootloader for it.
If you do want or need a mega1280 optiboot.hex file I would be glad to post it here for you?

PS: A simple jump to 0 to restart a sketch doesn't place any of the AVR hardware registers to their true default reset condition, which may or may not to a big deal, so is rarely recommended as a reliable method to use.

Lefty

Thanks Lefty. You and I and maybe a few are probably the only hold-outs with our MEGA1280s. The clone 2560 are so cheap on ebay that everyone that talks about MEGA to me lately have this or that version of MEGA2560. I even noticed the annoying fact that 2560 has moved one screw hole 0.05" from the 1280 footprint (bottom left hole 0.05" to the left from 1280 location). I'll try the jump to zero. I was seeking answer for UNO system and found the jump-to-zero solution and then came to know about the watch dog so went with watch dog. Now I want to explore the jump to zero again. I'll see how this affects the project I'm working on, which has a few serial devices on the serial-serial3, one Sd card on SPI, one RTC on I2C. I am assuming that these hardware registers will be set up by the bootloader once it runs after jump to zero, correct?

Thanks. I know of the location zero but also vaguely remember people mentioning that just the execution is reset and other things aren't. Could you give me some hint on what does and doesn't reset by calling zero?

I spent spent several hours trying to get a definitive answer to that exact question with no success. There are lots of opinions and suppositions out there, but I never found anything definitive, so I tested it. I can't (over thousands of automatic reboots) tell any difference at all. So, if there is a difference, it doesn't seem to matter. Lefty is right that some of the registers don't get defaulted to the power on state, but subsequent initialization in both the bootloader and your code seems to take care of those problems. Just make sure you set the things you use to the state you want them in in setup() and everything works, every time. Been there, done that.....a lot.

BTW, your home page temperature scale is in DegF, right? Does it every go near 150F as the max scale is set there? Horrible heat.

Nope, it doesn't get to 150F, but it I have measured it at 126F a number of times. I use 150 as the top point to leave a little play room.

Yes, there is a bootloader for the 2560 that fixes both the '!!!' bug where three exclamation points will stop the boot loader by kicking it into a little known debug mode, and the WDT problem that has plagued us for years. Far as I can tell, it still isn't in the production boards, but you can get it and load it. I was one of the first to try it out and wrote it up on my page at:

My little trick of turning the WDT into a timer and using it to call location zero was my fallback for hardware for a very long time. It worked every single time it was needed perfectly, so I've been testing the location zero jump long term on many different boards, old arduinos, new UNOs, 2560s of various revisions, etc. Once I found out that I could have a WDT that would span 15 minutes I went a bit nuts.

liudr:
Thanks Lefty. You and I and maybe a few are probably the only hold-outs with our MEGA1280s. The clone 2560 are so cheap on ebay that everyone that talks about MEGA to me lately have this or that version of MEGA2560. I even noticed the annoying fact that 2560 has moved one screw hole 0.05" from the 1280 footprint (bottom left hole 0.05" to the left from 1280 location). I'll try the jump to zero. I was seeking answer for UNO system and found the jump-to-zero solution and then came to know about the watch dog so went with watch dog. Now I want to explore the jump to zero again. I'll see how this affects the project I'm working on, which has a few serial devices on the serial-serial3, one Sd card on SPI, one RTC on I2C. I am assuming that these hardware registers will be set up by the bootloader once it runs after jump to zero, correct?

Cool. But I have no idea what hardware register that are used and/or restored to default values by the bootloader.

So here is the mega1280 optiboot.hex file and the new entry for the boards.txt file if you ever want to upgrade your mega1280 boards bootloaders, faster upload time plus no WDT or !!! problems.

optiboot_atmega1280.hex

:020000000404F6
:020000021000EC
:10FC0000112484B714BE81FFF2D085E08093810077
:10FC100082E08093C00088E18093C10086E08093F9
:10FC2000C20080E18093C4008EE0CBD0279A86E0AA
:10FC300020E33CEF91E0309385002093840096BB55
:10FC4000B09BFECF1F9AA8958150A9F7CC24DD2444
:10FC500099249394A5E0BA2EF1E1AF2EA6D0813479
:10FC600061F4A3D0082FB3D0023811F0013811F499
:10FC700084E001C083E091D08DC0823411F484E12E
:10FC800003C0853419F485E0AAD084C08535A1F479
:10FC90008CD0082F10E089D0E82EFF24FE2CEE2413
:10FCA000E02AF12A8F2D881F8827881F8BBFEE0C32
:10FCB000FF1C8DD067016EC0863521F484E08FD0A3
:10FCC00080E0D9CF843609F042C06FD06ED0082FC3
:10FCD0006CD080E0C81680EED80620F483E0F601F0
:10FCE00087BFE895C0E0D2E060D089930C17E1F7B8
:10FCF000F0E0CF16F0EEDF0620F083E0F60187BFDC
:10FD0000E89565D007B600FCFDCFA601A0E0B2E003
:10FD10002C9130E011968C91119790E0982F8827C4
:10FD2000822B932B1296FA010C0197BEE8951124B1
:10FD30004E5F5F4FF3E0A030BF0751F7F601B7BE4B
:10FD4000E89507B600FCFDCFA7BEE89523C0843731
:10FD5000A1F42BD02AD0E82E28D039D0E6010E2DE0
:10FD6000FE0186911AD021960150D1F70894C11C4A
:10FD7000D11CEA94CE0CD11C0DC0853731F427D0AC
:10FD80008EE10BD087E909D075CF813511F488E079
:10FD900018D01DD080E101D061CF982F8091C00094
:10FDA00085FFFCCF9093C60008958091C00087FF27
:10FDB000FCCF8091C00084FD01C0A8958091C60051
:10FDC0000895E0E6F0E098E1908380830895EDDF08
:10FDD000803219F088E0F5DFFFCF84E1DECF1F939A
:10FDE000182FE3DF1150E9F7F2DF1F91089580E04B
:08FDF000E8DFEE27FF2709946C
:040000031000FC00ED
:00000001FF

New entry to be added at the end of the arduino core boards.txt file

##############################################################

megao.name=Arduino Mega1280 Optiboot
megao.upload.protocol=arduino
megao.upload.maximum_size=130048
megao.upload.speed=115200
megao.bootloader.low_fuses=0xff
megao.bootloader.high_fuses=0xdc
megao.bootloader.extended_fuses=0xf5
megao.bootloader.path=optiboot
megao.bootloader.file=optiboot_atmega1280.hex
megao.bootloader.unlock_bits=0x3F
megao.bootloader.lock_bits=0x0F
megao.build.mcu=atmega1280
megao.build.f_cpu=16000000L
megao.build.core=arduino
megao.build.variant=mega

Tested on both a Seeeduino mega1280 and an arduino mega1280 board.

Lefty