element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Watchdog Timer for the Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi requires membership for participation - click to join
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mistertee
  • Date Created: 19 Jul 2016 10:15 AM Date Created
  • Views 5916 views
  • Likes 1 like
  • Comments 19 comments
Related
Recommended
  • autostart
  • watchdog timer

Watchdog Timer for the Raspberry Pi

mistertee
mistertee
19 Jul 2016

Like all PCs the Raspberry Pi is likley to hang up during operation due to unexpected events not being catered for in the code. In an unattended application where the program automatically starts this can be a problem as there is no one around to restart the RPi. If there is no keyboard or HDMI monitor this is by power cycling. The Raspberry Pis internal watchdog timer has a poor reputaion - there are many comments about it being unreliable. This post presents a simple external watchdog timer.

 

Although there are dedicated power supply monitoring chips this solution uses components that are likley to be in most electronic hobbyists kit - based around the popular 555 timer.

 

image

 

The programme has to supply a Hi going pulse every few seconds. If there is no pulse for more than about 60 seconds the 555 output on Pin 3 will go low. This is coupled through to the on-board reset pin of the Raspberry Pi through a capacitor to issue a low going pulse which resets the Pi.

 

A capcitor is used here so that only a pulse going from Hi to Low will reset the raspberry Pi. A constant Lo voltage which is present while the raspberry Pi is starting up will have no effect.

 

If a shorter time is required then either reduce the value of R1 (1Mohm) or reduce the value of C1 (100 uF).

 

The LED pulses every time a Hi Pulse is issued to provide a visual indication to the user that everything is fine. The 555 timer does not easily provide a retriggerable monostable function that is required for a watchdog timer. Diode D1 is used to discharge the capacitor every time a pulse is received.

 

The reason the delay before a reset is set at more than 60 seconds is that the Raspberry Pi takes more than 30 seconds to start up.

 

Click here for a guide to setting the Raspberry Pi to autostart.

 

image

 

The image above shows the connection to the Reset pin of the Raspberry Pi.

 

Summary

 

Althogh the Raspberry Pi has an in-built watchdog timer, this has a poor reputaion. This watchdog timer is a reliable way of resetting the Raspberry Pi in remote applications where there is a risk of it hanging up due to the code not handling unexpected events correctly.

  • Sign in to reply

Top Comments

  • mistertee
    mistertee over 8 years ago in reply to mcb1 +1
    True - I am sure there is a much better chip out there. 555 timers are like Marmite - you either love it or hate it. I had some in stock (doesn't one always) and couldnt be bothered to order a new IC and…
Parents
  • shabaz
    shabaz over 8 years ago
    Like all PCs the Raspberry Pi is likley to hang up during operation.

    Hi Seggy,

     

    Just to flesh out things a bit, perhaps an application could be likely to hang, generally the Linux kernel is not likely to hang unless there is a very severe issue like a build issue, hardware fault or power related issue.

    It is worth mentioning that if the board ever does lock up, this should be investigated; because for the hardware watchdog to have to ever take action on a Linux platform is "severe".

    Possible reasons could be a poor power supply perhaps, or bad cooling strategy, and for these the hardware watchdog action is like a sticking plaster and does not fix the underlying issue(s).

    The underlying issues should therefore be resolved if the watchdog timer actually has to ever take action.

    Finally, if users are experiencing application hangs then these do not require a hardware watchdog timer.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mistertee
    mistertee over 8 years ago in reply to shabaz

    The need for this watchdog circuit came out of a recent application the bare bones of which are rpesented below.

    Remote RF linked temperature monitors (upto 8 possible)

    RF receiver with serial link to RPi

    Ethernet connection to upload data to cloud and e-mail alerts

    Remote set-up with autostart (no keypad or monitor)

     

    Even after plenty of testing the possibility of software (written in Python) crash is there. eg data collision resulting in corrupted data, e-mail failure due to server issues ........

     

    I know the theoretical response is going to be "Test the system and iron out all bugs". However in practice this is a "safety net" while we do this and allows us to trial the system.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to mistertee

    Hi Seggy,

     

    The possibility of Python code crashing is a good example of a situation that does not require a hardware watchdog. You can have the application be killed and restarted. In other words, a process monitor i.e. a software watchdog.

    A hardware restart due to a hardware watchdog kicking off because of a Python app not responding could make the situation worse (for example file system corruption).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mistertee
    mistertee over 8 years ago in reply to shabaz

    Sounds good. Any guidance on how to do this? All my experience is with hardware - hence the use of Python and gut instincts leading me to a watchdog.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to mistertee

    Actually the best answer would be to not do this, until the Python code is fully baked and hardened. Otherwise you're at risk of code restarting under your feet, making life very difficult in debugging.

    A restart such as this needs to be an extremely rare thing, in my opinion to the point that you have sufficient time to investigate each single restart even if you have hundreds of customers using your software non-stop.

     

    Your process monitor can be as simple or as sophisticated as required, there might be examples via google, ranging from scripts to complete applications (I've not checked). The only time I've written one was for a commercial app so I can't share it, but it was in C++ (the language doesn't matter). It is at heart a state machine that needs the ability to detect actual application status, desired status (running or stopped, etc - since sometimes you may wish the application not to run), be able to kill and restart the application (e.g. using a kill or pkill command).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 8 years ago in reply to shabaz

    Shabaz

    In theory the python part should be the only part stopped.

    Is it possible to write to a log to show that a forced restart was triggered, and then execute a graceful shutdown via the serial port.

    This avoids the corruption roblem, which could definately cause more issues.

     

    While I agree that software should really handle all the unexpected, and run off to a error handler to stop it locking up, as the Op has pointed out it is during testing that this 'supervisory' device and software could be employed.

    The log should allow it to be run and then checked for restarts.

     

    I'm thinking that this would be a useful add-on for the Pi.

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to mcb1

    Hi Mark,

     

    Unfortunately I've more experience on other platforms, not Pi, and on those platforms I've never managed to make the Linux kernel die through user space apps (which is what Seggy would be doing, provided he's not writing his own drivers), and I wouldn't say I'm a super-careful programmer, just a "normal" programmer. A good system will generate logs as you say, capture any debug needed and then send alarms, and then do a graceful shutdown, and all this can be done as a process running on Linux (i.e. doesn't need external hardware, regardless of how hung/frozen the user app is). The apps I worked on were mainly sold to run on Solaris, which is famed for rock-solidness, but we had customers who ran it on Linux too and today I've no doubt about the reliability of Linux (which can be further enhanced through system-level redundancy, or load-sharing, etc).

     

    An add-on watchdog isn't useless, it would be useful if the kernel is hanging (which could happen if there were brown-outs or hardware failure issues) but this is different to dealing with buggy Python application code. The watchdog won't perform the steps mentioned above, so it is like a extremely last resort, and if there were such issues I'd want to get to the bottom of each one again, i.e. resolve power issues, replace memory, etc. A hardware watchdog that kicks in for a user application failure (while the kernel is still running) could cause more harm than good, because (a) if the kernel is still running then a software process is more useful because it can capture logs as mentioned and (b) there is a risk of data corruption if other processes are busy writing to storage.

     

    But a software solution too shouldn't kick in regularly either, if it is, then the application code needs a lot more effort..

    In practice, even if it is not life-threatening and there is no agreed up-time, it still at most should only occur infrequently enough that there is plenty of time to debug each restart (across all your customers) caused in this manner, i.e. to minimise customer loss and bad sentiment, and still have time to develop the next great feature/project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • shabaz
    shabaz over 8 years ago in reply to mcb1

    Hi Mark,

     

    Unfortunately I've more experience on other platforms, not Pi, and on those platforms I've never managed to make the Linux kernel die through user space apps (which is what Seggy would be doing, provided he's not writing his own drivers), and I wouldn't say I'm a super-careful programmer, just a "normal" programmer. A good system will generate logs as you say, capture any debug needed and then send alarms, and then do a graceful shutdown, and all this can be done as a process running on Linux (i.e. doesn't need external hardware, regardless of how hung/frozen the user app is). The apps I worked on were mainly sold to run on Solaris, which is famed for rock-solidness, but we had customers who ran it on Linux too and today I've no doubt about the reliability of Linux (which can be further enhanced through system-level redundancy, or load-sharing, etc).

     

    An add-on watchdog isn't useless, it would be useful if the kernel is hanging (which could happen if there were brown-outs or hardware failure issues) but this is different to dealing with buggy Python application code. The watchdog won't perform the steps mentioned above, so it is like a extremely last resort, and if there were such issues I'd want to get to the bottom of each one again, i.e. resolve power issues, replace memory, etc. A hardware watchdog that kicks in for a user application failure (while the kernel is still running) could cause more harm than good, because (a) if the kernel is still running then a software process is more useful because it can capture logs as mentioned and (b) there is a risk of data corruption if other processes are busy writing to storage.

     

    But a software solution too shouldn't kick in regularly either, if it is, then the application code needs a lot more effort..

    In practice, even if it is not life-threatening and there is no agreed up-time, it still at most should only occur infrequently enough that there is plenty of time to debug each restart (across all your customers) caused in this manner, i.e. to minimise customer loss and bad sentiment, and still have time to develop the next great feature/project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube