Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Has anyone tried software reset of an Arduino?

Has anyone tried software reset of an Arduino?

Scheduled Pinned Locked Moved Development
21 Posts 8 Posters 10.7k Views 9 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tekkaT tekka

    @TheoL sending an C_INTERNAL/I_REBOOT will do the job, it's a wdt reset.

    TheoLT Offline
    TheoLT Offline
    TheoL
    Contest Winner
    wrote on last edited by TheoL
    #8

    @tekka Thank you. Not yet sure how to do that. If you have an example for that I would be much obliged. Otherwise I'll spend some time on that later on. Either way, thanx again.

    Edited: Found it will update this answer later on with code

    Edit 2. My test didn't work, but I will try again tomorrow

    1 Reply Last reply
    0
    • YveauxY Yveaux

      @TheoL another way to reset is to enable the watchdog, but don't kick it. When it times out, it will reset the avr.
      Have to look up an example if you want.

      KoreshK Offline
      KoreshK Offline
      Koresh
      Contest Winner
      wrote on last edited by Koresh
      #9

      @Yveaux
      Watchdog is used by sleep() function in mysensors, so it is not possible to use it. Also it is not safe to use it on arduino boards with standard bootloader. If I need watchdog on standard arduino boards (without mysensors library) with standard bootloader I use next ISR to handle WDT interrupt

      // Watchdog Timer interrupt service routine. This routine is required
      // to allow automatic WDIF and WDIE bit clearance in hardware.
      ISR (WDT_vect)
      {
      	// WDIE & WDIF is cleared in hardware upon entering this ISR
      	wdt_disable();
      	asm volatile ("  jmp 0");
      }
      

      This ISR prevents bootloop.
      If I need just soft reset arduino I use the technique very similar to TheoL's

      asm volatile ("  jmp 0"); //call anywhere
      
      TheoLT tekkaT 2 Replies Last reply
      1
      • KoreshK Koresh

        @Yveaux
        Watchdog is used by sleep() function in mysensors, so it is not possible to use it. Also it is not safe to use it on arduino boards with standard bootloader. If I need watchdog on standard arduino boards (without mysensors library) with standard bootloader I use next ISR to handle WDT interrupt

        // Watchdog Timer interrupt service routine. This routine is required
        // to allow automatic WDIF and WDIE bit clearance in hardware.
        ISR (WDT_vect)
        {
        	// WDIE & WDIF is cleared in hardware upon entering this ISR
        	wdt_disable();
        	asm volatile ("  jmp 0");
        }
        

        This ISR prevents bootloop.
        If I need just soft reset arduino I use the technique very similar to TheoL's

        asm volatile ("  jmp 0"); //call anywhere
        
        TheoLT Offline
        TheoLT Offline
        TheoL
        Contest Winner
        wrote on last edited by
        #10

        @Koresh I haven't seen assembler for a while. Do you use that on all of your projects?

        KoreshK 1 Reply Last reply
        0
        • TheoLT TheoL

          @Koresh I haven't seen assembler for a while. Do you use that on all of your projects?

          KoreshK Offline
          KoreshK Offline
          Koresh
          Contest Winner
          wrote on last edited by
          #11

          @TheoL
          In general - no. Only for such tricks :) Of course these tricks are not invented by me.

          TheoLT 1 Reply Last reply
          0
          • KoreshK Koresh

            @TheoL
            In general - no. Only for such tricks :) Of course these tricks are not invented by me.

            TheoLT Offline
            TheoLT Offline
            TheoL
            Contest Winner
            wrote on last edited by
            #12

            @Koresh I understand my friend ;-) Although I have deep respect for people who are able to code completely in assembly. For me that was ages ago, almost in another life.

            1 Reply Last reply
            0
            • KoreshK Koresh

              @Yveaux
              Watchdog is used by sleep() function in mysensors, so it is not possible to use it. Also it is not safe to use it on arduino boards with standard bootloader. If I need watchdog on standard arduino boards (without mysensors library) with standard bootloader I use next ISR to handle WDT interrupt

              // Watchdog Timer interrupt service routine. This routine is required
              // to allow automatic WDIF and WDIE bit clearance in hardware.
              ISR (WDT_vect)
              {
              	// WDIE & WDIF is cleared in hardware upon entering this ISR
              	wdt_disable();
              	asm volatile ("  jmp 0");
              }
              

              This ISR prevents bootloop.
              If I need just soft reset arduino I use the technique very similar to TheoL's

              asm volatile ("  jmp 0"); //call anywhere
              
              tekkaT Offline
              tekkaT Offline
              tekka
              Admin
              wrote on last edited by tekka
              #13

              @Koresh said:

              Watchdog is used by sleep() function in mysensors, so it is not possible to use it.

              Not sure what you are referring to, sleep() uses WDIE (wdt interrupt before reset, see here) whereas the reboot functionality is implemented via wdt reset (see here).

              Also it is not safe to use it on arduino boards with standard bootloader.

              Can you elaborate why?

              KoreshK 1 Reply Last reply
              0
              • scalzS Offline
                scalzS Offline
                scalz
                Hardware Contributor
                wrote on last edited by scalz
                #14

                @Koresh @TheoL i use wdt with mysensors..but i cheated a bit :)

                • you can use your own sleep and then handle wdt, but then careful if really need mysensors sleep(x ms) as it resets wdt.
                • or as i do too, i have added a weak empty function in mysensors lib to have isr wdt available from sketch ;), temporarily I will submit a pr for the few features i have added locally..
                1 Reply Last reply
                1
                • tekkaT tekka

                  @Koresh said:

                  Watchdog is used by sleep() function in mysensors, so it is not possible to use it.

                  Not sure what you are referring to, sleep() uses WDIE (wdt interrupt before reset, see here) whereas the reboot functionality is implemented via wdt reset (see here).

                  Also it is not safe to use it on arduino boards with standard bootloader.

                  Can you elaborate why?

                  KoreshK Offline
                  KoreshK Offline
                  Koresh
                  Contest Winner
                  wrote on last edited by
                  #15

                  @tekka
                  Standard bootloader can fail to switch off wdt after reboot (on the boards with most chips) and it will cause bootloop. After rebooting watchog is still working and it is very important to disable it. We can use modified bootloader or bootloader like optiboot.

                  1 Reply Last reply
                  1
                  • scalzS Offline
                    scalzS Offline
                    scalz
                    Hardware Contributor
                    wrote on last edited by scalz
                    #16

                    @tekka I am not sure I will let answer, but if i remember well it was related to a problem that some old bootloader version were not handling properly wdt irq resulting in bootloader loop.

                    ISR (WDT_vect) is used by mysensors lib if using mysensors sleep.

                    but you can do something like:
                    in MyHwATMega328.h

                    void MY_WDT_Callback() __attribute__((weak));
                    

                    in MyHwATMega328.cpp, just add this in the wdt isr function

                    if (MY_WDT_Callback) MY_WDT_Callback();
                    

                    and finally in your sketch you can use MY_WDT_Callback() which will be fired at every wdt irq. Something like

                    void MY_WDT_Callback()   
                    {
                      wdt_reset(); // or do what you want
                      irqWdt = true;
                    }
                    

                    maybe there are better ways. another note, is I don't advice to do too much change locally without pr because then..arrghh :pensive: :scream:

                    1 Reply Last reply
                    0
                    • TheoLT Offline
                      TheoLT Offline
                      TheoL
                      Contest Winner
                      wrote on last edited by
                      #17

                      I when you thought you finally knew a bit about the Arduino, there comes a topic like this ;-) Thanx to you all. I understand to I have still much to learn.

                      1 Reply Last reply
                      0
                      • bjacobseB Offline
                        bjacobseB Offline
                        bjacobse
                        wrote on last edited by bjacobse
                        #18

                        Hi, as I remember about watchdog is to set it to 8S, so there is enough time to upload an sketch (8 seconds) before the Arduino will reboot. WDT0_time_in_seconds. If using WDT08S Always call the wdt_reset() no later than 7 seconds to avoid reset/reboot. This is usually used in case that the Arduino/avr is "hanging" in an infinite loop and stopped responding to actions, then this will automatically reset/reboot

                        Include this in your sketch:
                        #include <avr/wdt.h>

                        setup ();{
                        // WDTO_1S
                        // WDTO_2S
                        // WDTO_4S
                        // WDTO_8S
                        wdt_enable(WDTO_8S);
                        }

                        loop (){
                        wdt_reset(); // You must call this within less seconds set as WDT0_8S
                        }

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          ToniA
                          wrote on last edited by
                          #19

                          For whatever strange reason, the Arduino stock bootloader is broken, so that it will not disable the watchdog on startup, causing just an infinite reset loop. I'd recommend updating the bootloader with something like MYSBootloader or Optiboot.

                          1 Reply Last reply
                          1
                          • D Offline
                            D Offline
                            donnacarter0103
                            Banned
                            wrote on last edited by mfalkvidd
                            #20

                            Hey Buddy,

                            [spam post removed by moderator]

                            bjacobseB 1 Reply Last reply
                            0
                            • D donnacarter0103

                              Hey Buddy,

                              [spam post removed by moderator]

                              bjacobseB Offline
                              bjacobseB Offline
                              bjacobse
                              wrote on last edited by
                              #21

                              @donnacarter0103

                              The third way to reset an Arduino is to use watchdog (Need to flash another bootloader as the default have disabled watchdog), enable watchdog, and remember to reset it often in your code, else it will reste the Arduino

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              10

                              Online

                              11.7k

                              Users

                              11.2k

                              Topics

                              113.1k

                              Posts


                              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • MySensors
                              • OpenHardware.io
                              • Categories
                              • Recent
                              • Tags
                              • Popular