(1) Configuring the Raspberry
Pi for I2C |
(1.1) |
From the command line or Terminal
window start by running the following command : |
|
pi@raspberrypi ~
$
sudo raspi-config |
|
This will launch the raspi-config
utility. Select "Interfacing Options" |
|
 |
|
|
(1.2) |
Highlight the “I2C” option and
activate "<Select>" |
|
 |
|
|
(1.3) |
Select and activate “<Yes>”
|
|
 |
|
|
(1.4) |
Highlight and activate “<Ok>” |
|
 |
|
|
(1.5) |
Activate "<Finish>", this will exist the raspi-config
utility. |
|
 |
|
|
(1.6) |
Run the commands to install the i2c-tools utility |
|
pi@raspberrypi ~
$
sudo
apt-get update
|
|
pi@raspberrypi ~
$ sudo
apt-get install -y python-smbus i2c-tools |
|
|
(1.7) |
Reboot
the Raspberry Pi |
|
pi@raspberrypi ~
$
sudo reboot |
|
The Raspberry Pi will reboot and the interface will be
enabled. |
|
|
(1.8) |
Once you have logged into your Raspberry Pi from the command
line, run the command to see all the connected devices
|
|
pi@raspberrypi ~
$
sudo i2cdetect -y 1 |
|

#36 - the address of the battery fuel
gauging chip |
|
|
(2) Setting up the
power management |
(2.1) |
Download the required script
for power management |
|
pi@raspberrypi ~
$
wget
https://raw.githubusercontent.com/suptronics/x708v2.0/main/pwr.sh |
|
|
(2.2) |
Install the script for power
management |
|
pi@raspberrypi ~
$
sudo bash pwr.sh |
|
|
(2.3) |
Setting up the command to turn
off X728 from software |
|
pi@raspberrypi ~
$
printf "%s\n" "alias x708off='sudo
x708softsd.sh'" >> ~/.bashrc |
|
|
(2.4) |
Reboot
the Raspberry Pi |
|
pi@raspberrypi ~
$
sudo reboot |
|
|
(2.5) |
Powering off the
Raspberry Pi from software |
|
pi@raspberrypi ~
$
x708off |
|
|
(3) Reading battery
voltage & percentage |
(3.1) |
Download the script
for reading battery voltage and percentage |
|
pi@raspberrypi ~
$
wget
https://raw.githubusercontent.com/suptronics/x708v2.0/main/bat.py |
|
|
(3.2) |
Run the command to
read battery voltage and precentage |
|
pi@raspberrypi ~
$
sudo python
bat.py |
|
|
(3.3) |
Change the battery
low voltage to implement safe shutdown. default is less than
3.00Vdc. |
|
pi@raspberrypi ~
$
sudo nano
bat.py |
|
 |
|
Note: the voltage
range must be 2.5~4.1vdc. |
|
|
(3.4) |
Optional
- if you want to run Python Script automatically on Bootup then run
the command |
|
pi@raspberrypi ~
$
sudo crontab -e |
|
|
|
Choose "1" then press Enter |
|
|
(3.5) |
Add a
line at the end of the file that reads like this: |
|
@reboot
python /home/pi/bat.py |
|
 |
|
|
(3.6) |
Save and exit. In nano, you do
that by hitting CTRL + X, answering Y and hitting Enter when
prompted. |
|
|
(4) AC Power loss OR
power adapter failure detection (PLD) |
(4.1) |
Download the
python script for power loss detection (PLD) |
|
pi@raspberrypi ~
$
wget
https://raw.githubusercontent.com/suptronics/x708v2.0/main/pld.py |
|
|
(4.2) |
Run the script
test the PLD function |
|
pi@raspberrypi ~
$
sudo
python pld.py |
|
 |
|
|
|
Test Auto shutdown when AC power loss or power adapter
failure |
(4.3) |
Download the python script |
|
pi@raspberrypi ~
$
wget
https://raw.githubusercontent.com/suptronics/x708v2.0/main/plsd.py |
|
|
(4.4) |
Run the script and
then remove your power adapter |
|
pi@raspberrypi ~
$
sudo
python plsd.py |
|
Safe shutdown will be implemented in 5 seconds. |
|
|
(5) Automatically control the cooling Fan
|
(5.1) |
Download the python script |
|
pi@raspberrypi ~
$
wget
https://raw.githubusercontent.com/suptronics/x708v2.0/main/fan.py |
|
|
(5.2) |
Control the fan running at high speed
or low speed when the temperature reaches a certain
threshold |
|
pi@raspberrypi ~
$
sudo nano fan.py |
|
 |
|
Save and exit. In nano, you do
that by hitting CTRL + X, answering Y and hitting Enter when
prompted. |
|
|
(5.3) |
Execute the fan controller
code on boot (optional) |
|
pi@raspberrypi ~
$
sudo crontab -e |
|
|
|
Choose "1" then press Enter |
|
|
(5.4) |
Add a
line at the end of the file that reads like this: |
|
@reboot
python /home/pi/fan.py |
|
|
|
|
(5.5) |
Save and exit. In nano, you do
that by hitting CTRL + X, answering Y and hitting Enter when
prompted. |