Open main menu

Changes

X708-Software

5,744 bytes added, 20:21, 24 July 2023
no edit summary
{{GD Template Impl}}
<span style="color:blue;"big>'''Although this installation tutorial is still available, but we strongly recommend that you use [[X708 -script is same as X728]] new tutorial, only X708 doesn't support RTC functionand we no longer maintain this page.'''</spanbig>
The following test is base on '2020-02-13-raspbian-buster.img'
Python version: V2==For Raspberry Pi OS==*Test is base on '2022-04-04-raspios-buster-armhf.7img' and x708 v2.0 on Apr. 27th, 2022;*Testing is base on '2022-01-28-raspios-bullseye-armhf.img' on Feb. 28th, 2022;
1. Enable I2C funcion on Raspbian:; sudo raspi-configPlease refer to [[How to enable I2C]]
Select 5 Interfacing Options 2. Updatesoftware and then install necessary software (python and i2c tool library) sudo apt-get update #sudo apt-get install python-smbus P5 I2C sudo apt-get install python3-smbus python3- Enable/Disable automatic loadingrpi. A prompt will appear asking Would you like the ARM I2C interface to be enabled?, select "Yes" gpio sudo apt-get install i2c-tools
[[File:Rpi-config-13.jpg|none]]Check if the i2c of the X708 is connected correctly
[[File:Rpi sudo i2cdetect -config-5.jpg|none]]y 1
[[File 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20:Rpi-config-6.jpg|none]]-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Select "OK"‘36' is the address of the battery fuel gauging chip, and 36 is a hexadecimal number
Select "Finish" to return to If you can't find i2c address 36, it means the X708 is not connected properly, or your raspberry pi board is broken. 3.1. Download x708 setup scripts: cd ~ git clone https://github.com/geekworm-com/x708v2This command line and reboot your will download the script installation file for X708 4. Install the script for power management 4.1 Enters the corresponding operating system scripts folder (raspberry-pi-os) cd ~/x708v2/raspberry -pi-os/ 4.2 Execute the installation script. sudo bash pwr.sh This command will generate 2 power management script files as follows:*/etc/x708pwr.sh*/usr/local/bin/x708softsd.sh 4.3 Create an alias x708off so that we can perform software shutdown from the command line, you can also change x708off to any name you like printf "%s\n" "alias x708off='sudo x708softsd.sh'" >> ~/.bashrc
sudo reboot
Or force press the button of x708 for 8 seconds to shut down and then restart
 
4.4 Test software shutdown from command line after restart.
x708off
 
4.5 Press on-board button or external switch to test hardware safe shutdown
Press the switch for about 3 seconds until the power indicator flashes to execute hardware safe shutdown.
'''[NOTE]''':
* After shutdown, press the onboard switch or external switch to turn on.
* If your test fails, it means that your installation failed, or the software environment is incorrect, please check whether you have installed the corresponding software package.
 
5. How to reading battery voltage and percentage, this is the sample code, you can modify it by your request.
cd ~/x708v2/raspberry-pi-os/
sudo python3 bat.py
<pre>
******************
Voltage: 4.18V
Battery: 100%
Battery FULL
******************
Voltage: 4.17V
Battery: 100%
Battery FULL
******************
Voltage: 4.18V
Battery: 100%
Battery FULL
******************
Voltage: 4.17V
Battery: 100%
Battery FULL
******************
</pre>
 
* In generally, you need to let the X708 fully charge and discharge several times before you can get more accurate voltage and power values.
* This script can also perform safe shutdown at specified voltage threshold (default voltage threshold is 3.00vdc), you can also modify this voltage threshold, '''but the voltage threshold range must be 2.5~4.1vdc'''.
 
6. Testing AC power off/loss or power adapter failure detection (PLD function)
cd ~/x708v2/raspberry-pi-os/
sudo python3 pld.py
 
<pre>
1.Make sure your power adapter is connected
2.Disconnect and then connect the power adapter again to test
3.When power adapter disconnected, you will see: AC Power Loss or Power Adapter Failure
4.When power adapter reconnected, you will see: AC Power OK, Power Adapter OK
Testing Started---AC Power Loss OR Power Adapter Failure---
---AC Power OK,Power Adapter OK---
---AC Power Loss OR Power Adapter Failure---
---AC Power OK,Power Adapter OK---
</pre>
 
7. Test Auto shutdown when AC power loss or power adapter failure
cd ~/x708v2/raspberry-pi-os/
sudo python3 plsd.py
Testing Started---AC Power Loss OR Power Adapter Failure---
Shutdown in 5 seconds
Connection closing...Socket close.
In fact, you can refer to this example code to implement your own shutdown logic. . . This requires you to have some python programming foundation.
 
8. Advanced use of speed regulation for non-pwm fans
 
The X708 hardware supports two fan speeds: low speed (default) and high speed; if you want the fan to run at high speed, you need to run the fan.py script.
cd ~/x708v2/raspberry-pi-os/
python3 fan.py
 
fan.py provides a method that can switch the fan speed.
 
It should be noted that the x708 does not use a PWM fan, it only supports two speed modes (low speed and high speed). In the fan.py file, the speed mode of the fan is controlled by reading the temperature of the CPU in real time. You need to read the fan.py code to understand more logic.
 
You can control the fan running at high speed or low speed via modify the CPU temperature threshold in fan.py script file (yellow highlight line)
‎<syntaxhighlight lang="python" line highlight="9-11">
#!/usr/bin/env python3
 
import subprocess
import time
 
from gpiozero import OutputDevice
 
 
ON_THRESHOLD = 55 # (degrees Celsius) Fan running at high speed at this temperature.
OFF_THRESHOLD = 50 # (degress Celsius) Fan running at low speed at this temperature.
SLEEP_INTERVAL = 5 # (seconds) How often we check the core temperature.
GPIO_PIN = 16 # Which GPIO pin you're using to control the fan. DON'T change it!
 
 
def get_temp():
"""Get the core temperature.
Run a shell script to get the core temp and parse the output.
</syntaxhighlight>
 
'''[PS]'''
* If you can't understand, please ignore this step. Because the X708 fan will run at low speed by default, this cooling capacity is sufficient.
* If you have full control over the runing of the fan, you need to run 'python3 /home/pi/x708v2/raspberry-pi-os/fan.py', and you need to create a crontab job also, and then put this run command ('@reboot python3 /home/XX/x708v2/raspberry-pi-os/fan.py 'XX' is your username, you need replace it with your username.') into the job, so that the command will run automatically when the device restarts. refer to [[X708-Software#FAQ]]
 
9. Uninstall
cd ~/x708v2/raspberry-pi-os/
sudo bash uninstall.sh
 
10. About '''AUTO ON'''
After shutting down, you need to wait about 60 seconds until the battery capacity indicator of X708 goes out, otherwise the AUTO ON function may be invalid. Because the charge remaining in the power adapter may affect the AUTO ON function. == For Ubuntu==Base ubuntu-mate-20.04.1-desktop-armhf+raspi.img 1. Enable I2C  2. Install necessary software (python and i2c tool library)update & upgrade sudo apt-get install python-smbus update sudo apt-get install i2c-tools upgrade
3. Download x728 setup scripts:Install necessary software sudo apt install git clone https://github.com/geekwormpython python3 python3-smbus python3-com/x728rpi.git cd x728 sudo nano x728.sh #because X708 doesn't support RTC function, so we need to remove or comment out (add # at the beginning of the line) the following 4 lines #X728 RTC setting up #sudo sed -i '$ i rtc-ds1307' /etc/modules sudo sed gpio python-i '$ i echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' /etc/rcrpi.local sudo sed gpio wiringpi -i '$ i hwclock -s' /etc/rc.local y
4. Install script&rebootDownload x708 setup scripts: sudo bash x728git clone https://github.com/geekworm-com/x708.git cd x708 chmod +x *.sh printf "%s\n" "alias x728off='sudo x728softsdbash install-ubuntu.sh'" >> ~/.bashrc
sudo reboot
5. Set How to reading battery voltage and Read percentage, this is the RTC time. X708 does't support RTCsample code, so comment out the following scriptyou can modify it by your request. #If you need sudo python3 x708bat.py 6. How to set the system time for any reason you can use the following power off command : on ubuntu from software x708off #date * press button 1-s "5 MAR 2019 13:00:00"2 seconds to reboot #Write the system date and time * press button 3 seconds to the RTC module after your correct the system date and time : safe shutdown, #sudo hwclock * press 7-w8 seconds to force shutdown.  #Read 7. Testing AC power off/loss or power adapter failure detection (need to shor the date and time back from the RTC module: 'PLD' pin)  # sudo hwclock -rpython3 x708pld.py
68. How to reading battery voltage and Uninstall percentage, this is the sample code, you can modify it by your request. sudo python x728bat/uninstall-ubuntu.pysh
7. Power off command on Raspbian from software==FAQ== x728offQ1: How to make a script run automatically after boot?
8. Testing AC power off/loss or power adapter failure detection (need A: Refer to shor the 'PLD' pin) sudo python x728pld.py[[How to add crontab job]]
Return to [[X708]]
Return to [[X728]]
<!--Add review function! -->