4,014 bytes added,
14:48, 19 November 2022 {{GD Template Impl}}
The following test is base on [https://downloads.raspberrypi.org/raspios_armhf/images/raspios_armhf-2022-09-26/2022-09-22-raspios-bullseye-armhf.img.xz]
Python version is 3;
1. Enable I2C funcion on Raspbian:
reter to [[How to enable I2C]]
2. Login via teminal window, then update & upgrade & install necessary software (python and i2c tool library)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get -y install i2c-tools python3-smbus python-smbus
2.1 Once you have logged into your Raspberry Pi from the command line, run the command to see all the connected devices
sudo i2cdetect -y 1
[[File:X728x-i2c.png]]
#36 - the address of the battery fuel gauging chip
#68 - the address of the RTC chip
#Different x728 versions may have different values
3. Download x728 setup scripts:
cd ~
git clone https://github.com/geekworm-com/x728
4. Install script&reboot:
Firstly please select your x728 version, please use x728-v2.1.sh for x728 v2.1 and v2.2
sudo bash x728-v2.1.sh
#New add buzzer support
or
sudo bash x728-v2.0.sh
or
sudo bash x728-v1.0.sh
then
sudo reboot
You can get the following python file in /home/pi/ fold:
x728bat.py # Reading battery voltage
x728pld.py # Testing AC power off/loss or power adapter failure detection, added buzzer function on v2.1
x728plsd.py # Testing Auto shutdown when AC power loss or power adapter failure
5. Set and Read the RTC time
#If you need to set the system time for any reason you can use the following command :
date -s "5 MAR 2019 13:00:00"
#Write the system date and time to the RTC module after your correct the system date and time :
sudo hwclock -w
#Read the date and time back from the RTC module:
sudo hwclock -r
6. How to reading battery voltage and percentage, this is the sample code, you can modify it by your request.
sudo python /home/pi/x728bat.py
[[File:X728-bat-2.jpg]]
User Guide: https://github.com/geekworm-com/x728 to know more details;
But we hope that the script can be executed automatically when the Raspberry Pi board boots, we can use crontab system command to achieve it. Refer to [[How to add crontab job]] or refer to the following:
pi@raspberrypi ~ $ `sudo crontab -e`
Choose "`1`" then press Enter
Add a line at the end of the file that reads like this:
`@reboot python /home/pi/x728bat.py`
7. Power off command on Raspbian from software
x728off
* x728off is safe shutdown command
* press on-board blue button 1-2 seconds to reboot
* press on-board blue button 3 seconds to safe shutdown,
* press on-board blue button 7-8 seconds to force shutdown.
8. Testing AC power off/loss or power adapter failure detection (need to short the 'PLD' pin on v1.x), also test the buzzer function on v2.1
cd ~
sudo python3 x728pld.py
or
sudo python x728pld.py
[[File:X728-pld-2.jpg]]
9. '''Testing Auto shutdown when AC power loss''' or power adapter failure
cd ~
sudo python3 x728pld.py
or
sudo python x728plsd.py
==uninstall x728 script==
uninsatll x728 shell script, run the following command:
sudo ./uninstall_x728.sh
For the x728 old shell script, you also run this command to remove it, then re-install the x728 script.
==FAQ==
Q: We want to automatically shut down when the battery voltage is lower than a certain specified value, is it possible?
A: Please run the followng command to achieve this function.(Note: 3V is default shut down voltage value )
python3 /home/pi/x728/x728v2-asd.py &
X728-Chip-Specifications:
* [[File:MAX17040-MAX17041.pdf]]
*[https://www.sparkfun.com/datasheets/Components/DS1307.pdf I2C address: 0x36 for battery fuel gauging, 0x68 for RTC]
References:
*[https://www.instructables.com/Raspberry-Pi-Tutorial-How-to-Use-a-Buzzer/ Raspberry Pi Tutorial: How to Use a Buzzer]
Return to [[X728]]
<!--Add review function! -->
<comments />
<!--Please choose the -->
<!--Remove other categories, just keep the appropriate categories -->
[[Category:Product Manual]]
[[Category:Raspberry pi]]
[[Category:Knowledge]]