Changes

Jump to navigation Jump to search

X708-Software

626 bytes removed, 20:21, 24 July 2023
no edit summary
{{GD Template Impl}}
==For Raspberry Pi OS==The following test <big>Although this installation tutorial is base on '2020still available, but we strongly recommend that you use [[X708-02-13-raspbian-busterscript]] new tutorial, and we no longer maintain this page.img'</big>
Testing is base on '2022-01-28-raspios-bullseye-armhf.img' on Feb. 28th, 2022;
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 apt-get update
#sudo apt-get install python-smbus
sudo apt-get install python3-smbuspython3-rpi.gpio
sudo apt-get install i2c-tools
3. Check if the i2c of the X708 is connected correctly
<span style="color:#23AC38">pi@raspberrypi</span>: <span style="color:#50BEDB">~/x708v2 $</span> sudo i2cdetect -y 1 
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
36 - ‘36' is the address of the battery fuel gauging chip, and 36 is a hexadecimal number
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/x708.gitx708v2
This command will download the script installation file for X708
4.1 Enters the corresponding operating system scripts folder (raspberry-pi-os)
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~ $</span> cd ~/x708v2/raspberry-pi-os/
4.2 Execute the installation script.
 <span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span> sudo bash pwr.sh
This command will generate 2 power management script files as follows:
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
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>printf "%s\n" "alias x708off='sudo x708softsd.sh'" >> ~/.bashrc <span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>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.
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>x708off
4.5 Press on-board button or external switch to test hardware safe shutdown
5. How to reading battery voltage and percentage, this is the sample code, you can modify it by your request.
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~ $</span> cd ~/x708v2/raspberry-pi-os/ <span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>sudo python3 bat.py
<pre>
******************
6. Testing AC power off/loss or power adapter failure detection (PLD function)
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~ $</span> cd ~/x708v2/raspberry-pi-os/ <span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>sudo python3 pld.py
<pre>
7. Test Auto shutdown when AC power loss or power adapter failure
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~ $</span> cd ~/x708v2/raspberry-pi-os/ <span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>sudo python3 plsd.py
Testing Started---AC Power Loss OR Power Adapter Failure---
Shutdown in 5 seconds
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. Automatically 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 cooling Fan fan running at high speed or low speed via modify the CPU temperature threshold in fan.py script file (yellow highlight line) <span stylesyntaxhighlight lang="color:#23AC38python">pi@raspberrypi</span>:<span styleline highlight="color:#50BEDB9-11">~ $<#!/span> cd ~usr/x708v2/raspberry-pi-osbin/env python3 import subprocessimport 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! 
You can control def get_temp(): """Get the fan running at high speed or low speed via modify the CPU core temperature threshold in fan.py Run a shell script fileto get the core temp and parse the output.</syntaxhighlight>
'''[[File:PS]''' * If you can't understand, please ignore this step. Because the X708fan 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-v2pi-os/fan.pngpy', 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
<span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">cd ~ $</span> cd x708v2/raspberry-pi-os/ <span style="color:#23AC38">pi@raspberrypi</span>:<span style="color:#50BEDB">~/x708v2/raspberry-pi-os $ </span>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==
8. Uninstall
./uninstall-ubuntu.sh
 
Return to [[X708]]
==FAQ==
Q1: Can't connect How to pigpio at localhost(8888)<pre>Can't connect to pigpio at localhost(8888)Did you start the pigpio daemonmake a script run automatically after boot? E.g. sudo pigpiod
Did you specify the correct Pi host/port in the environmentvariables PIGPIO_ADDR/PIGPIO_PORT?E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888A: Refer to [[How to add crontab job]]
Did you specify the correct Pi host/port in thepigpio.pi() function? E.g. pigpio.pi('soft', 8888)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Traceback (most recent call last): File "/home/volumio/x-c1/fan.py", line 8, in <module> pwm.set_mode(servo, pigpio.OUTPUT) File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1376, in set_mode return _u2i(_pigpio_command(self.sl, _PI_CMD_MODES, gpio, mode)) File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1025, in _pigpio_command sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))AttributeError: 'NoneType' object has no attribute 'send'</pre>A: If you find an error similar Return to the above, it is because pigpiod library is not started, we need to run pigpiod first, sudo pigpiod python 'your directory'/x-c1/fan.py &If 'sudo' command request a password, you can use the following command: echo 'your password' | sudo -S pigpiod python 'your directory'/x-c1/fan.py &You can put these two lines in the /etc/rc.local file so that it will run automatically after booting. [[File:Volumio-rc-local.jpg|800pxX708]]

Navigation menu