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

From Geekworm Wiki
Revision as of 13:07, 18 March 2020 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 #7

46 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

47 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

47 months ago
Score 0++

Hi friend,

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

Anonymous user #5

50 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

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

Anonymous user #1

52 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

52 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

52 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

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