• sales

    +86-0755-88291180

Raspberry Pi RTC WatchDog HAT (B) User Guide

Resource

Sample Demo

Document

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 limited time and the watchdog circuit can 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 16-bit 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

  • Install BCM2835 libraries:
#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/
  • Install WiringPi libraries:
#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

Python

#Python2
sudo apt-get update
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install python-pip 
sudo pip install RPi.GPIO
sudo pip install spidev
#Python3
sudo apt-get update
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install python3-pip
sudo pip3 install RPi.GPIO
sudo pip3 install spidev
  • Download the sample demo, unzip 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 watchdog demo 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 &
#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 8 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 the WatchDog is WatchDog_Demo.py mainly for the watchdog cycle demo. As the D4 pin
  • 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 designated 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
  • Boot the Jetson Nano and synchronize the RTC time.
  • Note: the network should be disabled during this process.
cd /home/User/RTC_WatchDog_HAT_B/Jetson_nano/
#User is the host's username, set it to your own username, for example, my username is: jetson
#Input the command: cd /home/jetson/RTC_WatchDog_HAT_B/Jetson_nano/
#You need to change User to your own username in the following two files
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