RTC WatchDog HAT (B)

From Waveshare Wiki
Jump to: navigation, search
RTC WatchDog HAT (B)
RTC WatchDog HAT (B).jpg

RPI
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

This is an RTC WatchDog HAT (B) designed for Raspberry Pi with high-precision RTC and watchdog HAT, which refreshes and counts at a specific time, otherwise the watchdog circuit will reset the system.

Features

  • Onboard auto reset monitoring circuit.
  • Onboard high-precision clock chip (DS3231SN) for providing accurate timing control.
  • Support I2C communication and a programmable 16-bit self-increment counter.
  • Onboard the watchdog status indicator to warn the watchdog timeout.

Parameters

  • Communication interface: I2C
  • RTC chip: DS3231
  • Watchdog chip: CH32V003
  • Power supply: 5V
  • Dimensions: 30.5mm x 65mm
  • Fixed hole diameter: 3.0mm

Working with Raspberry Pi

Enable I2C Interface

  • Open the Raspberry Pi terminal and enter the following command to access the configuration interface:
sudo raspi-config
Select Interfacing Options -> SPI -> Yes to enable the I2C kernel driver

Current Serial.png
And then reboot the Raspberry Pi:

sudo reboot

Install Library

If you use bookworm system, only the lgpio library is available, bcm2835 and wiringPi libarary cannot be installed or used. Please note that the python library does not need to install, you can directly run the demo.

BCM2835

#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz 
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/

WiringPi

#Open the Raspberry Pi terminal and run the following command
cd
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error

# Bullseye branch system using the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
. /build
gpio -v
# Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error

lgpio

wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
sudo make install 
#for more details, you can refer to https://github.com/gpiozero/lg

Python

sudo apt-get update
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install python3-pip
sudo pip3 install spidev
  • Download the sample demo, unzip it to the designated directory, and run the demo code:
wget https://files.waveshare.com/wiki/RTC-WatchDog-HAT-B/RTC_WatchDog_HAT_B_Demo.zip
unzip RTC_WatchDog_HAT_B_Demo.zip
sudo chmod 777 -R RTC_WatchDog_HAT_B_Demo

RTC

C

cd ~
cd RTC_WatchDog_HAT_B_Demo/Raspberrypi/RTC/c/
make clean
make -j8 
sudo ./main

Python

cd ~
cd RTC_WatchDog_HAT_B_Demo/Raspberrypi/RTC/python/examples/
#Set RTC time and display the time, date and temperature in the cycle
sudo python main.py
#synchronize the RTC time to the system without network
sudo python Set_system_time.py
  • Boot the Raspberry Pi and synchronize the RTC time.

Note: The network should be disabled during this process.

sudo nano /etc/rc.local
#Enter the following commands between fi and exit 0, save and exit. The demo for feeding dog will automatically run when it boots the next time
cd /home/pi/RTC_WatchDog_HAT_B_Demo/Raspberrypi/RTC/python/examples/
sudo python Set_system_time.py &
#In the "cd /home/pi/...", pi is the username that you can set by yourself 

Add Kernel Mode Driver

Note that you do not need to use the above demo if you use this method.
Modify the /boot/config.txt by adding the following line at the end:

dtoverlay=i2c-rtc,ds3231

Simple Usage of Hwclock

Synchronize System Clock -> Hardware Clock.

sudo hwclock -w

Synchronize Hardware Clock -> System Clock.

sudo hwclock -s
  #Disable the network or the time synchronization via the network, otherwise, the time can not be set.

Set the hardware clock time:

sudo hwclock --set --date="9/8/2021 16:45:05"

View the hardware clock.

sudo hwclock -r

Display version information.

sudo hwclock --verbose

WatchDog

  • After downloading the above demo, you can configure it now.

C

  • The C demo of the WatchDog is for enabling the WatchDog function and configuring the timeout with the unit of second and up to 65535s and 1s at least. When setting the timeout, the booting time of the Raspberry Pi should be considered, otherwise, the system will reset in the cycle as the Raspberry Pi fails to boot.
  • You can set the timeout at the 8th line of the main.c file: WATCH_TIME_Restart = * (*: 1-65535).
  • The watchdog cycles:
cd ~
cd RTC_WatchDog_HAT_B_Demo/Raspberrypi/WatchDog/c
make clean
make -j8
sudo ./main

Python

  • The Python demo of WatchDog is named WatchDog_Demo.py, primarily focused on configuring and feeding a watchdog. When the D4 pin transitions once, it is considered as feeding the watchdog.
  • If it doesn't feed in the T time, it will power off and the Raspberry Pi will reboot.
  • T can be set in the WatchDog_Configure.py: WATCH_TIME_Restart = * (*: 1-65535).
cd ~
cd RTC_WatchDog_HAT_B_Demo/Raspberrypi/WatchDog/python
sudo python WatchDog_Demo.py

Working with Jetson Nano

Install Python Library

sudo apt update
sudo apt install nano -y
sudo apt install python3-pip
pip3 install Jetson.GPIO
pip3 install smbus
  • Download the sample demo, unzip it to the specified directory and execute it:
wget https://files.waveshare.com/wiki/RTC-WatchDog-HAT-B/RTC_WatchDog_HAT_B_Demo.zip 
unzip RTC_WatchDog_HAT_B_Demo.zip
sudo chmod 777 -R RTC_WatchDog_HAT_B_Demo

RTC

C

cd ~
cd RTC_WatchDog_HAT_B_Demo/Jetson_nano/RTC/c/
make clean
make -j8
sudo ./main

Python

cd ~
cd RTC_WatchDog_HAT_B_Demo/Jetson_nano/RTC/python/examples/
#Set the RTC time and cyclically display the time, date and temperature
sudo python3 main.py
#Synchronize the RTC time with the system without internet connectivity
sudo python3 Set_system_time.py
  • Synchronize RTC time during Jetson Nano startup:

Note: Do not connect to the network during this process.

cd /home/User/RTC_WatchDog_HAT_B/Jetson_nano/
#User is the host username, set it to your username, for example: if your username is "jetson", then input the command: cd /home/jetson/RTC_WatchDog_HAT_B/Jetson_nano/
#The content in the following two files is the same, and you need to replace "User" with your username
sudo chmod 777 start.sh
sudo chmod 777 start.service
sudo cp start.service /etc/systemd/system
systemctl daemon-reload
systemctl enable start.service
sudo reboot

WatchDog

  • After downloading and unzipping the above demo, you can configure it now.

C

  • The C demo of the WatchDog is for enabling the WatchDog function and configuring the timeout with the unit of second and up to 65535s and 1s at least. When setting the timeout, the booting time of the Raspberry Pi should be considered, otherwise, the system will reset in the cycle as the Raspberry Pi fails to boot.
  • You can set the timeout at the 8th line of the main.c file: WATCH_TIME_Restart = * (*: 1-65535).

The watchdog cycles:

cd ~
cd RTC_WatchDog_HAT_B_Demo/Raspberrypi/WatchDog/c
make clean
make -j8 
sudo ./main

Python

  • The Python demo of WatchDog is named WatchDog_Demo.py, primarily focused on configuring and feeding the watchdog. When the D4 pin transitions once, it is considered as feeding the watchdog.
  • If it doesn't feed in the T time, it will power off and the Raspberry Pi will reboot.
  • T can be set in the WatchDog_Configure.py: WATCH_TIME_Restart = * (*: 1-65535).
cd ~
cd RTC_WatchDog_HAT_B_Demo/Raspberrypi/WatchDog/python
sudo python WatchDog_Demo.py

Working with Sunrise X3 Pi

Install Wiringpi Library

sudo apt update
sudo apt install git-core
git clone https://gitee.com/study-dp/WiringPi.git
cd WiringPi
./build
#If the software version is shown after inputting the following commands, the installation is successful. 
gpio -v

Install Python Library

sudo apt update
sudo apt install nano
sudo apt install python3-pip
sudo pip3 install Hobot.GPIO
sudo pip3 install smbus
  • Download the sample demo, unzip it to the specified directory and run:
wget https://files.waveshare.com/wiki/RTC-WatchDog-HAT-B/RTC_WatchDog_HAT_B_Demo.zip 
unzip RTC_WatchDog_HAT_B_Demo.zip
sudo chmod 777 -R RTC_WatchDog_HAT_B_Demo

RTC

C

cd ~
cd RTC_WatchDog_HAT_B_Demo/Horizon_Sunrise_X3_PI/RTC/c
make clean
make -j8
sudo ./main

Python

cd ~
cd RTC_WatchDog_HAT_B_Demo/Horizon_Sunrise_X3_PI/RTC/python/examples/
#Set RTC time and display the time, date and temperature in the cycle
sudo python3 main.py
#Synchronize the RTC time to the system without network
sudo python3 Set_system_time.py
  • Boot the Raspberry Pi and synchronize the RTC time.
  • Note: the network should be disabled during this process.
sudo cp -r /home/sunrise/RTC_WatchDog_HAT_B_Demo/Horizon_Sunrise_X3_PI /root/X3/
sudo chmod 777 -R /root/X3/Horizon_Sunrise_X3_PI/RTC/python/examples/Set_system_time.py
sudo nano /etc/rc.local 
#Add the following command at the front line of exit 0
python3 /root/X3/Horizon_Sunrise_X3_PI/RTC/python/examples/Set_system_time.py
#Save and exit

Input "date" to view the date.

WatchDog

  • After downloading and unzipping the above demo, you can configure it now.

C

  • The C demo of the WatchDog is for enabling the WatchDog function and configuring the timeout with the unit of second and up to 65535s and 1s at least. When setting the timeout, the booting time of the Raspberry Pi should be considered, otherwise, the system will reset in the cycle as the Raspberry Pi fails to boot.
  • You can set the timeout at the 8th line of the main.c file: WATCH_TIME_Restart = * (*: 1-65535).
  • The watchdog cycles:
cd ~
cd RTC_WatchDog_HAT_B_Demo/Horizon_Sunrise_X3_PI/WatchDog/c
make clean
make -j8 
sudo ./main

Python

  • The Python demo of WatchDog is named WatchDog_Demo.py, primarily focused on configuring and feeding the watchdog. When the D4 pin transitions once, it is considered as feeding the watchdog.
  • If it doesn't feed in the T time, it will power off and the Raspberry Pi will reboot.
  • T can be set in the WatchDog_Configure.py: WATCH_TIME_Restart = * (*: 1-65535).
cd ~
cd RTC_WatchDog_HAT_B_Demo/Horizon_Sunrise_X3_PI/WatchDog/python
sudo python WatchDog_Demo.py

Sample Demo

  • Run the RTC C example:

RTC WatchDog HAT (B)-09.jpg

  • Run the RTC Python example:

RTC WatchDog HAT (B)-10.jpg
RTC WatchDog HAT (B)-11.jpg

  • Run the WatchDog C example:

RTC WatchDog HAT (B)-12.jpg

  • Run the WatchDog Python example:

RTC WatchDog HAT (B)-13.jpg

Indicator Status Introduction

  • Keeps on when the watchdog function is turned on.
  • Keeps off when the watchdog function is turned off.
  • Blinking rapidly at a frequency of 100ms when the watchdog reaches a timeout.
  • After the watchdog reaches a timeout and runs the reboot command, if the host is detected as not having powered off, it cannot reboot but blinks at a frequency of 500MS. It reboots only when the host power is off in this case.

Resource

Sample Demo

Document

Datasheet

Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)