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

From All for Raspberry Pi, Arduino, Lattepanda, Orange Pi, Pine64 | by Geekworm
Jump to: navigation, 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

wget https://raw.githubusercontent.com/suptronics/x750_x725-script/master/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. Reading battery voltage and percentage

sudo python x750ups.py

8. Powering off the Raspberry Pi from software

x750off
Add your comment
All for Raspberry Pi, Arduino, Lattepanda, Orange Pi, Pine64 | by Geekworm welcomes all comments. If you do not want to be anonymous, register or log in. It is free.


Anonymous user #1

one day 17 hours 42 minutes 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

4 days 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

9 days 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

7 days 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).