How to read the battery capacity via I2C on X750&725

From Geekworm Wiki
Jump to navigation Jump to search

This is the guide of how to read the battery capacity via I2C on X750&725:

We test it base Raspbian Stretch system.

1. Enable I2C function on the Raspbian

sudo raspi-config

Select '5 Interfacing Options' and then 'I2C - Enable/Disable automatic loading'. A prompt will appear asking 'Would you like the ARM I2C interface to be enabled?', select "Yes"

Geekworm-i2c-1.png
Geekworm-raspi-config.png

2. Once you have logged into your Raspberry Pi from the command line, run the following command to install i2c-tools

sudo apt-get install python-smbus
sudo apt-get install i2c-tools

3. Download the required script

git clone https://github.com/geekworm-com/x750.git
cd x750
chmod +x x750.sh

4. Install the script

sudo bash x750.sh

5. Setting up the command to turn off X750 from software

printf "%s\n" "alias x750off='sudo x750shutdown.sh'" >> ~/.bashrc

6. Reboot the Raspberry Pi

sudo reboot

7. Powering off the Raspberry Pi from software

x750off

8. Reading battery voltage and percentage

sudo python x750ups.py

Customers often ask if we support automatic and safe shutdown at low battery capacity? Our suggestion is: You can refer to the A file and the B file to program this idea yourself: The idea is to read the current voltage or battery capacity cyclically, and then judge the program to execute the automatic shutdown command when it is low or low voltage, of course This low battery or low voltage value is an empirical value, and you can specify it yourself in the program.

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 #8

13 days ago
Score 0++

having issues on rpi5: ``` > sudo bash x750.sh sed: can't read /etc/rc.local: No such file or directory sed: can't read /etc/rc.local: No such file or directory sed: can't read /etc/rc.local: No such file or directory sed: can't read /etc/rc.local: No such file or directory x750.sh: line 123: /home/pi/x750ups.py: No such file or directory chmod: cannot access '/home/ozelen/x750ups.py': No such file or directory ```

in the first place I had problem with running `sudo apt-get install python-smbus`, so I used `sudo apt install python3-smbus`, and I guess here might be a problem with backward compatibility. So I'm lost a bit.

Lisa

12 days ago
Score 0++
Hi,The x725 & X750 are no longer in production and we have not tested them with the RPi5. Which UPS HAT are you using?

Anonymous user #8

11 days ago
Score 0++
@Lisa, Geekworm Raspberry Pi 5 UPS (X1202), 4-Cell 18650 UPS (MAX 5.1V 5A Output) with Wide 6-18V Input | Auto Power On | Safe Shutdown | Power Loss Detection

Lisa

11 days ago
Score 0++
please refer to X1202 Software----3.0 Reading UPS status

Anonymous user #7

55 months ago
Score 0++

Any discription on the ph2.0 4-pin external power switch?

I want to connect to an external switch, but do not know the pin out.

Thanks.

Anonymous user #6

56 months ago
Score 0++
What is the micro USB on the end of the board for? Is that for the Wake on Lan and second ethernet functionality?

Cindy

56 months ago
Score 0++

Hi friend,

Do you mean X750? Please refer to X750-Interface-schematic-w1000.jpg.

Anonymous user #5

59 months ago
Score 0++

I got this error while executing the script on my x725:

IOError: [Errno 121] Remote I/O error

am i the only one ?

Anonymous user #4

61 months ago
Score 0++
sed -e "s/\r//g" file > newfile

Anonymous user #1

61 months ago
Score 0++

See Anonymous User #2's comment. That was the problem. When the extra character is stripped from the lines, the script executes as advertised and the two functions, software shutdown and print battery capacity work.

Many thanks.

Anonymous user #3

61 months ago
Score 0++

Anyone have problem with : ./x720pwr.sh: linia 6: echo: błąd zapisu: Urządzenie lub zasoby zajęte ./x720pwr.sh: linia 7: /sys/class/gpio/gpio4/direction: Nie ma takiego pliku ani katalogu ./x720pwr.sh: linia 9: echo: błąd zapisu: Urządzenie lub zasoby zajęte X720 Shutting down... cat: /sys/class/gpio/gpio4/value: Nie ma takiego pliku ani katalogu ./x720pwr.sh: linia 17: [: =: oczekiwano operatora jednoargumentowego

./x720pwr.sh: linia 21: [: =: oczekiwano operatora jednoargumentowego

Anonymous user #1

61 months ago
Score 0++

Has anyone else tried this with a Raspberry Pi 4? When I tried to install the script (sudo bash X750.sh) bash threw errors:

xxxx@Z97A-i64:~$ sudo bash x750.sh [sudo] password for xxxx: x750.sh: line 3: $'\r': command not found

No such file or directoryal

x750.sh: line 5: $'\r': command not found

No such file or directory

x750.sh: line 44: $'\r': command not found x750.sh: line 45: $'\r': command not found x750.sh: line 48: $'\r': command not found

No such file or directoryal

x750.sh: line 50: $'\r': command not found x750.sh: line 73: $'\r': command not found x750.sh: line 76: $'\r': command not found

No such file or directoryal

x750.sh: line 78: $'\r': command not found

No such file or directory/x750ups.py

chmod: cannot access ‘/home/pi/x750ups.py\r’: No such file or directory x750.sh: line 125: $'\r': command not found

For what it is worth, I ran as "pi" on the RP-4 and again on an Ubuntu linux system. Both gave the same errors.

Suggestions?

Anonymous user #2

61 months ago
Score 0++
For some reason the x750.sh script has been saved with DOS/Windows encoding, so there are extra \r (^M) characters at the end of each line. Open the script in editor like kwrite and save using Unix line convention (\n only).