X708-Software

From Geekworm Wiki
Jump to navigation Jump to search


For Raspberry Pi OS

  • Test is base on '2022-04-04-raspios-buster-armhf.img' 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;

Please refer to How to enable I2C

2. Updatesoftware and install necessary software (python and i2c tool library)

sudo apt-get update
#sudo apt-get install python-smbus
sudo apt-get install python3-smbus python3-rpi.gpio
sudo apt-get install i2c-tools 

3. Check if the i2c of the X708 is connected correctly

pi@raspberrypi: ~/x708v2 $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   

36 - 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. Download x708 setup scripts:

pi@raspberrypi:~ $ cd ~
pi@raspberrypi:~ $ git clone https://github.com/geekworm-com/x708v2

This command 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)

pi@raspberrypi:~ $ cd ~/x708v2/raspberry-pi-os/

4.2 Execute the installation script.

pi@raspberrypi:~/x708v2/raspberry-pi-os $ 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

pi@raspberrypi:~/x708v2/raspberry-pi-os $ printf "%s\n" "alias x708off='sudo x708softsd.sh'" >> ~/.bashrc
pi@raspberrypi:~/x708v2/raspberry-pi-os $ 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.

pi@raspberrypi:~/x708v2/raspberry-pi-os $ 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.

pi@raspberrypi:~ $ cd ~/x708v2/raspberry-pi-os/
pi@raspberrypi:~/x708v2/raspberry-pi-os $ sudo python3 bat.py 
******************
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
******************
  • 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)

pi@raspberrypi:~ $ cd ~/x708v2/raspberry-pi-os/
pi@raspberrypi:~/x708v2/raspberry-pi-os $ sudo python3 pld.py 
 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---

7. Test Auto shutdown when AC power loss or power adapter failure

pi@raspberrypi:~ $ cd ~/x708v2/raspberry-pi-os/
pi@raspberrypi:~/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. Automatically control the cooling Fan

pi@raspberrypi:~ $ cd ~/x708v2/raspberry-pi-os/

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)

 1 #!/usr/bin/env python3
 2 
 3 import subprocess
 4 import time
 5 
 6 from gpiozero import OutputDevice
 7 
 8 
 9 ON_THRESHOLD = 55  # (degrees Celsius) Fan running at high speed at this temperature.
10 OFF_THRESHOLD = 50  # (degress Celsius) Fan running at low speed  at this temperature.
11 SLEEP_INTERVAL = 5  # (seconds) How often we check the core temperature.
12 GPIO_PIN = 16  # Which GPIO pin you're using to control the fan. DON'T change it!
13 
14 
15 def get_temp():
16     """Get the core temperature.
17     Run a shell script to get the core temp and parse the output.

9. Uninstall

pi@raspberrypi:~ $ cd ~/x708v2/raspberry-pi-os/
pi@raspberrypi:~/x708v2/raspberry-pi-os $ sudo bash uninstall.sh

For Ubuntu

Base ubuntu-mate-20.04.1-desktop-armhf+raspi.img

1. Enable I2C


2. update & upgrade

sudo apt update
sudo apt upgrade

3. Install necessary software

sudo apt install git python python3 python3-smbus python3-rpi.gpio python-rpi.gpio wiringpi -y

4.Download x708 setup scripts:

git clone https://github.com/geekworm-com/x708.git
cd x708
chmod +x *.sh
sudo bash install-ubuntu.sh
sudo reboot

5. How to reading battery voltage and percentage, this is the sample code, you can modify it by your request.

sudo python3 x708bat.py

6. How to power off command on ubuntu from software

x708off
* press button 1-2 seconds to reboot
* press button 3 seconds to safe shutdown,
* press 7-8 seconds to force shutdown.

7. Testing AC power off/loss or power adapter failure detection (need to shor the 'PLD' pin)

sudo python3 x708pld.py

8. Uninstall

./uninstall-ubuntu.sh

Return to X708

FAQ

Q1: How to make a script run automatically after boot?

A: Refer to How to add crontab job

Add your comment
Geekworm Wiki welcomes all comments. If you do not want to be anonymous, register or log in. It is free.


Anonymous user #23

3 months ago
Score 0++
Could you explain what does enabling high state on GPIO13 does on v1.2 board? There is no schematic of the board.

Lisa

3 months ago
Score 0++

Hi,

GPIO13 for power management;please referX708-Hardware

Anonymous user #24

3 months ago
Score 0++

Lisa,

I know it's for power management. The x708softsd.sh script uses GPIO13 to perform a software shutdown. The question is: how? Does it just turn off the power on the board or does it somehow emulate the pressing of the button (GPIO5) and the proper shutdown is then performed by the x708pwr.sh script?

Anonymous user #22

3 months ago
Score 0++

When I enable I2C in raspi-config I get this: modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.10.92-v8+

This command: sudo apt-get install python-smbus

throws this: Package python-smbus is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package 'python-smbus' has no installation candidate

Lisa

3 months ago
Score 0++

Hi,

you can refer 【Anonymous user #17】

please try to [sudo apt-get install python3-smbus] to test.

Anonymous user #20

4 months ago
Score 0++

It is said that if you press the button for 3 seconds using the button, it will be safe shutdown.

I'm curious about the Python file or sh file that executes this.

Anonymous user #20

4 months ago
Score 0++

now. press the button 3 second => safe shutdown => power down

I want to know how to executes this on rasp from software code

like software x708off.

Anonymous user #20

4 months ago
Score 0++

6. How to power off command on ubuntu from software

x708off

  • press button 1-2 seconds to reboot
  • press button 3 seconds to safe shutdown,
  • press 7-8 seconds to force shutdown.
where can i set the code described above?

Anonymous user #21

4 months ago
Score 0++
Hi, I don't understand your questions, and requires you to have some basic knowledge of computers

Anonymous user #19

5 months ago
Score 0++
Just wanted to say that forcing things to /home/pi/ might not be the best idea in the world, especially if folks us something other than the Pi user account on the device. Might not hurt to put them somewhere else, then add wherever you put it to the path. I'm specifically talking about the x708bat.py and x708pid.py commands.

Anonymous user #18

5 months ago
Score 0++

Do I have to run python3 /home/pi/x708/x708asd.py & always at startup manually or does this happen automatically in the background to get ASD? I have no desktop environment - how to make this script run in the background via SSH? I have the X807 v.1.2 - as far as I can see there are no PLD pins to shorten. Can I run the AC power off/loss script anyway? Gives me currently an error: Traceback (most recent call last): File "/home/pi/x708pld.py", line 20, in <module> raw_input("Testing Started")

NameError: name 'raw_input' is not defined

Lisa

4 months ago
Score 0++

Hello,

please refer to X708-Software#FAQ.

Anonymous user #17

5 months ago
Score 0++

On Raspberry Pi OS Lite Kernel version: 5.10, Release date: October 30th 2021 the following command didn't work:

sudo apt-get install python-smbus

Package python-smbus is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'python-smbus' has no installation candidate

It's probably because I use Python 3.x - so it worked with:

sudo apt-get install python3-smbus

Anonymous user #16

5 months ago
Score 0++
I want a safe shutdown on button press but your code commands 'poweroff' - could you advise on the changes to replace this with 'shutdown now' so everything has time to shutdown correctly?

Lisa

5 months ago
Score 0++

Hi,

The script command we provide is 'x708off'----editable;

'poweroff' is a kernel command.

Anonymous user #15

7 months ago
Score 0++

Hello, I installed the x708 software as indicated, on a Raspberry Pi 4. I got the following error, after the following command. Is there any way to fix this? Thanks

pi@rachel:~ $ python x708bat.py

Traceback (most recent call last): File "x708bat.py", line 25, in <module> print ("Voltage:%5.2fV" % readVoltage(bus)) File "x708bat.py", line 9, in readVoltage read = bus.read_word_data(address, 2)

IOError: [Errno 121] Remote I/O error

Lisa

7 months ago
Score 0++
Hello, Please try to 【python3 x708bat.py】 and test it

Anonymous user #14

7 months ago
Score 0++

There are some problems in the python code with the actully raspberry pi os (raspbian).

If i want to use ``` sudo python3 x708bat.py ``` The system calls: ``` File "/home/pi/x708bat.py", line 24 print "******************" ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print("******************")? ```

If I change it to print(*******) i had the follow error:

``` File "/home/pi/x708bat.py", line 25 print "Voltage:%5.2fV" % readVoltage(bus) ^ SyntaxError: invalid syntax

```

Any idea how I can fix that?

Thx!

Harry

7 months ago
Score 0++

The syntax of print in python2 and python3 is different, so there will be this error, you can run the following command: python2 x708bat.py or

python x708bat.py

Harry

7 months ago
Score 0++

I have just modify the install.sh for the python 3 because of print function.

You can update the install.sh, run the command 'git pull', then run './uninstall.sh' to uninstall, then reinstall it.

Anonymous user #11

9 months ago
Score 0++

python3 x708pld.py 1.Make sure your power adapter is connected 2.Disconnect and connect the power adapter 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 Traceback (most recent call last): File "/root/x708pld.py", line 20, in <module> raw_input("Testing Started")

NameError: name 'raw_input' is not defined

Anonymous user #12

7 months ago
Score 0++
just replace to input() for python3

Anonymous user #11

9 months ago
Score 0++

python3 x728bat.py File "/root/x728bat.py", line 20 print "******************" ^

SyntaxError: Missing parentheses in call to 'print'. Did you mean print("******************")?

Anonymous user #10

9 months ago
Score 0++

Dear Geekworm team, I just set up successfully the X708 board and installedt he software. However, I get the following error at step 6 (on Raspbian) when I try to read the battery level. Any idea?

pi@raspberrypi:~ $ sudo python x708bat.py Traceback (most recent call last): File "x708bat.py", line 21, in <module> bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)

IOError: [Errno 2] No such file or directory

Anonymous user #13

7 months ago
Score 0++

I have the same issue. Geekworm team, please help us

" $ sudo python x708bat.py Traceback (most recent call last): File "x708bat.py", line 21, in <module> bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1) IOError: [Errno 2] No such file or directory

"

Anonymous user #13

7 months ago
Score 0++

sudo raspi-config

select "3 Interface Options" and hit enter select "P5 I2C" and hit enter then go to finish

and reboot.

Anonymous user #9

11 months ago
Score 0++
how to use SSD1306 OLED Displays (batter volt & capacity)

Lisa

11 months ago
Score 0++
Hello,sorry that we haven't tested x708 + OLED Displays;

Anonymous user #9

11 months ago
Score 0++
"bash: x708.sh: No such file or directory" <---how to do???

Harry

11 months ago
Score 0++
sorry, should be install.sh

Anonymous user #8

11 months ago
Score 0++

Hi, I keep getting this : pi@raspberrypi:~/x708 $ chmod +x install.shchmod +x install.sh chmod: cannot access 'install.shchmod': No such file or directory

chmod: cannot access '+x': No such file or directory

Lisa

11 months ago
Score 0++
Hello,Please email to us【support@geekworm.com】 and provide some pictures or videos so that we can find the problem. And tell us your order number.Best regards

Anonymous user #7

12 months ago
Score 0++

Hi can this be used on twister to monitor battery state..

Thanks

Lisa

12 months ago
Score 0++
Hi, Sorry we haven't tested on twister yet.

Anonymous user #6

13 months ago
Score 0++
How to enable Auto Power ON feature?

Lisa

12 months ago
Score 0++
Hi,please refer here:X708-Hardware

Anonymous user #5

16 months ago
Score 0++

Guten Tag,

Ist es möglich den Lüfter per Termeratur zu steuern wie beim board X730 ??

Lisa

12 months ago
Score 0++
Hi, The fan of X708 does not support temperature control.

Anonymous user #4

19 months ago
Score 0++
Hi. Is there a way to increase the delay between when "poweroff" of the RPI starts and the X708 drops power? This would allow to add a longer delay so that the OS is completely shutdown?

Xiali

18 months ago
Score 0++
Hi dear ,X708 will cut off the power after the system is shut down, you need to install the script first,By the way ,There are many Raspberry Pi fans exchange experiences on our official website, you are welcome to join us https://geek...munity/forum

Anonymous user #3

19 months ago
Score 0++

Hi,

I can't shutdown the pi using the command x708off. It says: "command not found".

Anonymous user #3

19 months ago
Score 0++
I could solve the problem myself. Had do modify the ~/.bashrc file. There was written "alias x728off = 'sudo x728softsd.sh'. But I got under /usr/local/bin/x708softsd.sh ...

Xiali

19 months ago
Score 0++
Hi dear ,So you have solve the problem That is a good news ,by the way there are many Raspberry Pi fans exchange experiences on our official website, you are welcome to join us: http://www.g...munity/forum

Harry

20 months ago
Score 0++
Sorry, we updated the script for X708.

Georgefeichter

21 months ago
Score 0++
Is there anyone who can help with this?

Georgefeichter

22 months ago
Score 0++

I can't get the pi to shut down through a command at the command line.

I type this: x728off

and I get this: /usr/local/bin/x728softsd.sh: line 5: echo: write error: Device or resource busy X728 Shutting down...

But nothing happens.

Any ideas anyone?

Anonymous user #1

22 months ago
Score 0++

Hi

Just got your x708 and installed it.

Step 3 of the software instructions is not very clear. Which lines need to be commented out?

Like this:

==================
  1. 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
  2. X728 RTC setting up
  3. sudo sed -i '$ i rtc-ds1307' /etc/modules

sudo sed -i '$ i echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' /etc/rc.local sudo sed -i '$ i hwclock -s' /etc/rc.local

===================

Like this:

==================
  1. 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
  2. X728 RTC setting up
  3. sudo sed -i '$ i rtc-ds1307' /etc/modules
  4. sudo sed -i '$ i echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' /etc/rc.local

sudo sed -i '$ i hwclock -s' /etc/rc.local

===================

or like this:

==================
  1. 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
  2. X728 RTC setting up
  3. sudo sed -i '$ i rtc-ds1307' /etc/modules
  4. sudo sed -i '$ i echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' /etc/rc.local
  5. sudo sed -i '$ i hwclock -s' /etc/rc.local
===================
Thank you very much.

Anonymous user #2

22 months ago
Score 0++

I read it as

  1. X728 RTC setting up
  2. sudo sed -i '$ i rtc-ds1307' /etc/modules
  3. sudo sed -i '$ i echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' /etc/rc.local
  4. sudo sed -i '$ i hwclock -s' /etc/rc.local