X728-Software

From Geekworm Wiki
Revision as of 11:44, 24 November 2022 by Harry (talk | contribs)
Jump to navigation Jump to search

The following test is base on 2022-01-28-raspios-bullseye-armhf.zip

Python version is 3;

1. Enable I2C funcion on Raspbian:

reter to How to enable I2C

2. Login via teminal window, then update & upgrade & install necessary software (python and i2c tool library)

sudo apt-get update
sudo apt-get upgrade
sudo apt-get -y install i2c-tools python3-smbus python-smbus

2.1 Once you have logged into your Raspberry Pi from the command line, run the command to see all the connected devices

sudo i2cdetect -y 1
X728x-i2c.png
#36 - the address of the battery fuel gauging chip
#68 - the address of the RTC chip
#Different x728 versions may have different values

3. Download x728 setup scripts:

cd ~
git clone https://github.com/geekworm-com/x728

4. Install script&reboot:

Firstly please select your x728 version, please use x728-v2.1.sh for x728 v2.1 and v2.2

sudo bash x728-v2.1.sh
#New add buzzer support

or

sudo bash x728-v2.0.sh

or

sudo bash x728-v1.0.sh

then

sudo reboot

You can get the following python file in /home/pi/ fold:

x728bat.py # Reading battery voltage
x728pld.py # Testing AC power off/loss or power adapter failure detection, added buzzer function on v2.1
x728plsd.py # Testing Auto shutdown when AC power loss or power adapter failure

5. Set and Read the RTC time

#If you need to set the system time for any reason you can use the following command :  
date -s "5 MAR 2019 13:00:00"
#Write the system date and time to the RTC module after your correct the system date and time :  
sudo hwclock -w
#Read the date and time back from the RTC module:  
sudo hwclock -r

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

sudo python /home/pi/x728bat.py

X728-bat-2.jpg

User Guide: https://github.com/geekworm-com/x728 to know more details;

But we hope that the script can be executed automatically when the Raspberry Pi board boots, we can use crontab system command to achieve it. Refer to How to add crontab job or refer to the following:

sudo crontab -e

Crontab-step1.png

Choose "`1`" then press Enter

Add a line at the end of the file that reads like this:

@reboot python /home/pi/x728bat.py

X728-crontab.png

Save and exit. In nano, you do that by hitting CTRL + X, answering Y and hitting Enter when prompted.

7. Power off command on Raspbian from software

x728off
  • x728off is safe shutdown command
  • press on-board blue button 1-2 seconds to reboot
  • press on-board blue button 3 seconds to safe shutdown,
  • press on-board blue button 7-8 seconds to force shutdown.

8. Testing AC power off/loss or power adapter failure detection (need to short the 'PLD' pin on v1.x), also test the buzzer function on v2.1

cd ~
sudo python3 x728pld.py
or 
sudo python x728pld.py

X728-pld-2.jpg

9. Testing Auto shutdown when AC power loss or power adapter failure

cd ~
sudo python3 x728pld.py
or 
sudo python x728plsd.py

uninstall x728 script

uninsatll x728 shell script, run the following command:

sudo ./uninstall_x728.sh

For the x728 old shell script, you also run this command to remove it, then re-install the x728 script.

FAQ

Q: We want to automatically shut down when the battery voltage is lower than a certain specified value, is it possible?

A: Please run the followng command to achieve this function.(Note: 3V is default shut down voltage value )

python3 /home/pi/x728/x728v2-asd.py &

X728-Chip-Specifications:

References:

Return to X728

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

one month ago
Score 0++

Can the raspberry still be safely restarted with

`sudo reboot`?

Walker

one month ago
Score 0++
Please refer to our new script on the X728:X728-script

Anonymous user #38

one month ago
Score 0++

Why would it randomly stop shutting down fully?

I've tried this firmware and countless others. 2 that use to work. x728off doesnt work.

Walker

one month ago
Score 0++
Please refer to our new script on the X728:X728-script

Anonymous user #37

9 months ago
Score 0++
Hello, is there a way to power off x728 by pulling one of the GPIOs high or low? Thanks.

Anonymous user #36

10 months ago
Score 0++
Is there a addon for Home assistant?

Walker

10 months ago
Score 0++
Hello, sorry, we don't have this

Anonymous user #33

22 months ago
Score 0++
Hi. I have a x728 v1.2 in a raspberry 4, i am trying to get the voltage values but the raspberry is not recognizing the address of the i2c. This version needs something else to read the voltages values?

Lisa

22 months ago
Score 0++

Hello,

What operating system are you using, are there any errors?

Harry

16 months ago
Score 0++
or run the i2cdetect -y 1 to get the I2C address, then check the accroding python code

Anonymous user #31

22 months ago
Score 0++

On step 4, when I run any of the x-728 commands, I get this

x728-v2.1.sh: line 78: /home/pi/.bashrc: No such file or directory x728-v2.1.sh: line 140: /home/pi/x728bat.py: No such file or directory x728-v2.1.sh: line 169: /home/pi/x728pld.py: No such file or directory x728-v2.1.sh: line 198: /home/pi/x728plsd.py: No such file or directory

This is running on a pi 4 with Raspbian.

Anonymous user #32

22 months ago
Score 0++

Hi, Thanks In the last Raspberry Pi OS, the OS no longer provides the default username pi, and users need to create their own username, so you should have created your own username, please open the x728-v21.sh file, and then Replace all '/home/pi/' with '/home/pi/your username/'; save and exit and reinstall it;

Regards.

Anonymous user #34

18 months ago
Score 0++
I to do not understand how to get the x728 file to work and how to rename to my rpi, Please help The x728v2- say no such file or directory

Lisa

18 months ago
Score 0++

Anonymous user #34 :Hello,

Please use your own username after '/home/pi/'.

That is, the username created by the initial user of the Raspberry Pi OS system

Anonymous user #35

10 months ago
Score 0++
You "should" also be able to replace the /home/pi with the $HOME variable.

Anonymous user #28

23 months ago
Score 0++

I have a PI 4B with an x728 V2.1. With my application I really want the x728 to shutdown a short period of time after A/C power loss. I figure I can accomplish this by setting the shutdown voltage higher.

When when I run python3 /home/pi/x728/x728v2-asd.py & I only get the battery voltage and percent charge repeating constantly. I see no way to change the shutdown voltage running this command.

I edited the shutdown voltage in x728v2-asd.py and run it and the x728 shutdown at my desired voltage. However after reboot the x728 didn't shutdown until it got down to 3 volts.

My question is how do I change to shutdown voltage in the script that get run by crontab, so it is permanent?

TIA,

Larry

Anonymous user #28

23 months ago
Score 0++

I was able to get the results I wanted by modifying x728bat.py.

I changed the 3.00 in the readVoltage line:

  1. Set battery low voltage to shut down, you can modify the 3.00 to other value
if readVoltage(bus) < 3.00:

Anonymous user #30

23 months ago
Score 0++

Hello, I want to use the X728 v2.1 device with the Libreelec/Kodi distribution. Is there a way or a guide to install the software? The device works flawlessly on Raspian OS.

Thanks

Lisa

23 months ago
Score 0++

Hello,

SORRY, libreElec is the readonly image, so don't install our python script.

Anonymous user #30

23 months ago
Score 0++
is there an addon for this?

Lisa

23 months ago
Score 0++
sorry,Currently unable to resolve

Anonymous user #27

25 months ago
Score 0++

- The installation process should create a systemctl service to start/stop the process instead of using crontab.

I did the following:

Copied /home/pi/x728/x728v2-asd.py to /usr/local/bin: sudo cp /home/pi/x728/x728v2-asd.py /usr/local/bin

Then created a systemctl service file to start the script:

sudo vi /lib/systemd/system/x728-shutdown.service

Contents of the file:

[Unit] Description=Geekworm x728 Shutdown Service After=network.target

[Service] Type=simple StandardOutput=null WorkingDirectory=/usr/local/bin User=root Restart=always RestartSec=3 ExecStart=/usr/bin/python3 /usr/local/bin/x728v2-asd.py ExecReload=/bin/kill -2 $MAINPID KillMode=process

[Install] WantedBy=multi-user.target

Then I reloaded systemctl to read the new service file:

sudo systemctl daemon-reload

Enable the service:

sudo systemctl enable x728-shutdown.service

Started the service:

sudo systemctl start x728-shutdown.service

Display the status:

sudo systemctl status x728-shutdown.service

● x728-shutdown.service - Geekworm x728 Shutdown Service Loaded: loaded (/lib/systemd/system/x728-shutdown.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-02-24 18:30:59 EST; 3min 55s ago Main PID: 1632 (python3) Tasks: 1 (limit: 1597) CPU: 113ms CGroup: /system.slice/x728-shutdown.service └─1632 /usr/bin/python3 /usr/local/bin/x728v2-asd.py

Feb 24 18:30:59 raspberrypi systemd[1]: Started Geekworm x728 Shutdown Service.

MUCH better than adding to crontab!

Anonymous user #28

24 months ago
Score 0++

Has anybody else tried this? I new to Linux and Raspberry PI, although not new to computers or programming.

TIA

Anonymous user #29

24 months ago
Score 0++

@Anonymous user #27,

Thanks for your detailed and informative comment about an alternative to using crontab... But for those of us who are not *nix experts, would you please explain *why/how* your script is much better?

Thanks!

Anonymous user #28

24 months ago
Score 0++

When I try sudo systemctl enable x728-shutdown.service I get the following error

Failed to enable unit: File x728-shutdown.service: Bad message

Anonymous user #35

10 months ago
Score 0++
You should put this into a github the rest of us could install from ;-)

Anonymous user #27

25 months ago
Score 0++

This documentation is terrible! And with everyone's questions/comments, along with the poor responses that were provided, it makes the documentation very difficult to follow.

There are steps listed without any explanation on why they're needed.

If you really want customers to be successful with your product, you need to write better documentation! And it needs to be written up near the top of this page - not buried down in the comments!


Provide answers to the following questions:


1. Why is setting the hardware clock important? Raspberry Pi OS uses NTP to synchronize time.

There is little to no explanation for the following files:

  • x728bat.py to /home/pi

- Explain what this script does

- Is this only used for displaying the battery level?


  • x728pld.py to /home/pi

- Explain what this script does

- Is this only used for testing the buzzer?


  • /etc/x728pwr.sh

- Explain what this script does

- Why are you running a script from "/etc"? This should go under "/usr/local/bin"


  • /usr/local/bin/x728softsd.sh

- What is different about this script compared to /etc/x728pwr.sh?


  • /home/pi/x728/x728v2-asd.py
- Running this Python script (even with adding &) makes the script output display on the console constantly. That is very distracting and unnecessary for something that should run in the background.

Anonymous user #26

25 months ago
Score 0++
hello, is it possible to change gpio input 26 to another gpio input?

Lisa

25 months ago
Score 0++

Hello,

Sorry,not support change it.

Anonymous user #25

25 months ago
Score 0++
Thank you very much! That (the information you just provided below on the X-728-Chip-Specification...) is exactly what I needed. I think I am still missing some information though (like how to detect whether or not AC power is on or not, and controlling the beeper). I will look through more of your documentation, hopefully I can find this. Thanks again.

Lisa

25 months ago
Score 0++

Hello,

①Please refer to FAQ information:[Raspberry Pi Tutorial: How to Use a Buzzer]

②AC FALL(AC Power Loss LED)----When AC power supply is not connected or power supply fails, the red indicator light is always on. If connected to AC power, the red indicator will not light up.

Anonymous user #24

25 months ago
Score 0++

Hi, Where can I find information on the I2C protocol you use for your board. I know I am not the only one wanting to write my own software to interface to the UPS. I am currently developing some software (not related to the DC UP at all) and I would really like to integrate UPS monitoring into this software as it would be very useful indeed.

Your documentation states that you use a particular chip for power management, but that's it. Please can you provide details such as which I2C addresses hold which information, how many bits/bytes/words of data etc.

I need access to the RTC and the power management. I could reverse engineer the board, but that's a lot of effort and it would be easier if you simply provided these details, thank you. I am sure I am not the only hobbyist or professional that is interested in this information either.

Lisa

25 months ago
Score 0++

Hi,

please refer to X728-Software#FAQ

X728-Chip-Specifications and I2C address

Anonymous user #23

26 months ago
Score 0++

I am running BullsEye on RPI4B X728 V2.1 When I run the setup sudo apt-get -y install python-smbus i2c-tools I get the error: 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

Is there a replacement for python-smbus

Lisa

26 months ago
Score 0++

Hi,

please try to use 【sudo apt-get -y install python3-smbus i2c-tools】and test it.

Anonymous user #22

26 months ago
Score 0++
Hi, running bullseye on RPI3B+ x728, "sudo bash x728-v1.0.sh" returns error "line 123: [: line: integer expression expected". Same with v2.0 and V2.1. By the way how do I know which version to use? I guess my x728 is an old version, before numbering? Any clues? Thx

Lisa

26 months ago
Score 0++

Hi,

The version code is marked on the front of the x728 UPS board, please check your X728 board. Thanks.

Anonymous user #21

27 months ago
Score 0++

How I can reduce charging current? I have an original USB-C power supply from the RaspberryPi 5V / 3A and it doesn't seem to be able to supply power to charge the batteries and the RaspberryPi 4 at the same time.

When the batteries are charged, everything works. When I unplug the power supply from the X728 RaspberryPi runs out of batteries. This drains the battery a bit and when I reconnect the power supply, the RaspberryPi still runs, but the X728 keeps restarting and I hear a click. This is probably due to resource overload. Although I ordered the X728 in November, I received version V1.3, which does not have a charge current reduction of 2A.

What manual adjustment can I use to reduce the charging current? I looked at the IP5310 datasheet, but without knowing the schematic, the modification would be risky.

Lisa

27 months ago
Score 0++

Hello,

The x728 keeps restarting, which may be caused by low voltage. In addition to the Raspberry Pi, does it load other devices?

Could you please tell us where you bought X728 V1.3, and let us know the order number?

Anonymous user #20

27 months ago
Score 0++

My 728 was working fine for a long time. After a Raspian update a while back it stopped responding to the shutdown script only a long press of the power button on the 728 forcing shutdown works. Finally getting around to troubleshooting it. When I run the 728off.py I get the following:

/usr/local/bin/x728softsd.sh: line 5: echo: write error: Device or resource busy /usr/local/bin/x728softsd.sh: line 6: /sys/class/gpio/gpio13/direction: No such file or directory /usr/local/bin/x728softsd.sh: line 7: /sys/class/gpio/gpio13/value: No such file or directory X728 Shutting down... /usr/local/bin/x728softsd.sh: line 20: /sys/class/gpio/gpio13/value: No such file or directory

I've tried uninstalling and reinstalling the software package but am still getting the same errors. Anyone got a clue what to try?

Lisa

27 months ago
Score 0++

Hello,

Please reinstall the firmware and test it.

Anonymous user #19

28 months ago
Score 0++
How to force a shutdown after power disconnect for example after 5 minutes?

Lisa

28 months ago
Score 0++
Hi,You can realize the automatic shutdown function by setting the voltage value

Anonymous user #18

33 months ago
Score 0++

Hello My Raspberry 3B is powered by a X728 board model 1.2 This is why I used the script x728-v1.0.sh to install the scripts I tested both python scripts in my home folder (x728bat.py and x728pld.py) and they work OK Also the command x728off works OK

My question is about CRON! I added the line '@reboot python /home/pi/x728bat.py' (without the single quotes) but nothing happens, i.e. if I disconnect the power and my battery goes low, nothing happens! Checking the CRON status shows I have two jobs running (456 and 458).

● cron.service - Regular background program processing daemon Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2021-06-26 21:49:50 CEST; 12h ago Docs: man:cron(8) Main PID: 396 (cron) Tasks: 4 (limit: 2063) CGroup: /system.slice/cron.service ├─396 /usr/sbin/cron -f ├─428 /usr/sbin/CRON -f ├─456 /bin/sh -c python /home/pi/x728bat.py └─458 python /home/pi/x728bat.py

Having 2 jobs running is this as expected? When using the x728bat.py script in CRON where are the logs going? Any idea why this is not working within CRON?

Thanks in advance for any help

Lisa

33 months ago
Score 0++
Hello, Please check the file if exit in/home/pi? or /home/pi/x728?

Anonymous user #18

33 months ago
Score 0++

Hello I have modified the CRONTAB entry as follows:

@reboot python /home/pi/x728bat.py >> /home/pi/x728.log

The x728.log file has been created at reboot and contains the logs of x728bat.py

I will retest and revert back

Anonymous user #18

33 months ago
Score 0++

It seems to work OK I will test a bit more because what I need is at power failure my two disks attached on my Raspberry are shutdown safely.

Thanks again.

Anonymous user #17

33 months ago
Score 0++
I have installed the scripts and the test works as I think it is intended, when I remove power it says the power was removed and when I plug it in it says its plugged in, now how do I make it shut down the RPI when the power is removed and boot up when the power it plugged in?

Lisa

33 months ago
Score 0++

Hello, It supports safe shutdown and full poweroff through software;and you need to install the script.

For Auto Power-on function, please refer to the instructions of jumper cap:https://wiki...E6%98%8E.jpg

Anonymous user #16

34 months ago
Score 0++

I get this error when using x728off

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

This is after I ran it once before. I am not sure what you mean regarding root permissions. I2C is enabled.

Anonymous user #16

34 months ago
Score 0++

The instrutions say to add "@reboot python3 /home/pi/x728bat_v1.3.py" to crontab -e. But I am testing this line "python3 /home/pi/x728bat_v1.3.py" to see if it will work but it won't work in command line.

I can get this line to work "sudo python /home/pi/x728/x728bat_v1.3.py" in command prompt. So I am entering this in the crontab instead. will this be adequate.

I tried "sudo python3 /home/pi/x728/x728bat_v1.3.py" but got syntax error. All other instructions use python instead of python3.

Anonymous user #16

33 months ago
Score 0++

is it necessary to put "@reboot python3 /home/pi/x728bat_v1.3.py" to crontab -e? Using ps axg it looks like the file ran three times. See below. so it seems like I should remove for Crontab -e. Is that correct?

491 ? Ss 0:00 /bin/sh -c sudo python /home/pi/x728/x728bat_v1.3.py 492 ? S< 0:00 [kworker/2:1H] 494 ? S 0:00 sudo python /home/pi/x728/x728bat_v1.3.py

526 ? S 0:00 python /home/pi/x728/x728bat_v1.3.py

Anonymous user #15

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

Lisa

33 months ago
Score 0++
Hi,please refer here: https://wiki...E6%98%8E.jpg

Anonymous user #13

34 months ago
Score 0++

why do you put v1.3 in sudo contrab -e when I can't find v1.3

the 1.3 script creates the v1.2 file still.

Anonymous user #14

34 months ago
Score 0++
1.3 has been in the git clone destination for me, check that again! -lyn1337

Anonymous user #16

34 months ago
Score 0++
the 1.3 is in the x728 folder. so the command line in instructions should probably be "sudo python /home/pi/x728/x728bat_v1.3.py" python3 did not work for me without syntax error.

Anonymous user #13

34 months ago
Score 0++

sudo hwclock -w -v

returns: hwclock from util-linux 2.33.1 System Time: 1621621184.305205 Trying to open: /dev/rtc0 Trying to open: /dev/rtc Trying to open: /dev/misc/rtc No usable clock interface found. hwclock: Cannot access the Hardware Clock via any known method.

what am I missing... I just did:sudo apt-get update && sudo apt-get -yf full-upgrade

with the same results.

Anonymous user #14

34 months ago
Score 0++
try running hwclock with sudo. -lyn1337

Anonymous user #12

35 months ago
Score 0++
when I attached X735 v1.3 the system hangs in a loop. the power led of x728 v2.5 and 735 are on. pi starts. after a few sec it willstop and the power led of 735 is off. then it will restart. any idea?

Harry

35 months ago
Score 0++

CAN'T use x728 with X735, please use the X728-A1 if you want heatsink.

Thanks.

Anonymous user #9

35 months ago
Score 0++
"x728off" (and "sudo /usr/local/bin/x728softsd.sh") say "X728 Shutting down..." but then never shut down. Do you know why this is? Using a fresh install of the latest Raspbian OS and followed the instructions fully.

Anonymous user #14

34 months ago
Score 0++
you have to run it with root permissions to actually shut it down, and the I2C has to be enabled via raspi-config (and rebooted once to take this to effect). The script will say it's shutting down whether it actually will or not. -lyn1337

Anonymous user #11

36 months ago
Score 0++

These can be converted to Python3 with :

Apt-get install 2to3

Changing the Python env at the top of the files etc.

Anonymous user #10

36 months ago
Score 0++
I want to use this UPS to power a Freenove 3 wheeled smart car, is this possible? as both have an I2C?

Anonymous user #9

36 months ago
Score 0++

If you are getting the error: "IOError: [Errno 110] Connection timed out"

for x728bat.py, check and see no other programs are using GPIO3. I had a power button shutdown script that ran on startup to turn the pi off and it was preventing the HAT from reading that pin. I simply uninstalled and used the supported shutdown button feature for this board.

Anonymous user #7

37 months ago
Score 0++

The shutdown script doesn't work for me. I get an error on line 5 which is the line: echo "$BUTTON" > /sys/class/gpio/export I get: "echo: write error: Device or resource busy" Of course lines 6 and 7 give errors also.

Any idea what this is (BTW, I'm running this on a Raspi 4 4GB with 7" Raspi display)

Anonymous user #9

35 months ago
Score 0++
It appears that this will only happen if you run the command multiple times after a fresh reboot. The real problem is that the first time you run it, it won't work for some reason.

Anonymous user #5

38 months ago
Score 0++

Adding the below to my config turns the x728 off after shutdown

dtoverlay=gpio-poweroff,gpiopin=13

Anonymous user #6

37 months ago
Score 0++

I did not see an answer to this question: How do you turn the UPS off after an hour with no power?

also, How do you turn on the x728 and boot the PI with power applied to the x728 and then soft-shutdown the PI and then turn off the x728 after the power is removed?

Anonymous user #5

38 months ago
Score 0++

How do you turn the UPS off after an hour with no power?

I've set up my PI to shutdown after an hour with no power reading GPIO6 but I cant get it to turn the UPS off. This means when I apply power again nothing happens as the UPS or PI never actually shutdown.

Anonymous user #4

38 months ago
Score 0++
I need to be able to shutdown the whole rig (RPi4 and x728) from a script. Is that possible?

Lisa

33 months ago
Score 0++

Hello,

Yes,It supports safe shutdown and full poweroff through software

Anonymous user #2

44 months ago
Score 0++

I am getting an error when trying run the x728bat.py script. Below is the information I am getting on the Raspberry Pi 4.

sudo python x728bat.py Traceback (most recent call last): File "x728bat.py", line 3, in <module> import smbus

ImportError: No module named smbus

Anonymous user #8

36 months ago
Score 0++
Use python3, not python.

Anonymous user #11

36 months ago
Score 0++

if you are using python3 make sure that you install:

pip3 install smbus smbus2

for GPIO, you may have to set the following: export CFLAGS=-fcommon

pip3 install RPi.gpio

Anonymous user #1

44 months ago
Score 0++
Where are the additional files. The git only has the setup script. But the script calls for the files, which are absent. Any help?

Pmsr

44 months ago
Score 0++
The setup script creates all files on the fly. If you edit it you will see them.

Pmsr

44 months ago
Score 0++

Managed to get my new x728 going. Solid hardware. But am getting the following output from x728bat.py.

What does the Voltage at 4.21V mean? It's far from the 3.7V nominal from the batteries, and from the 5V required for the Raspberry Pi.

And 103% for the capacity? The script expects 100 to print "Battery FULL", so there is a fix in need here.

Voltage: 4.21V Battery: 103%

Anonymous user #3

38 months ago
Score 0++

Hi Pmsr, the Voltage you see is coming from the batteries. It is a very usefull indication of the quality of them.

4.2V is the fully charged value. 3.7V is the steady value over a relative long periode without charging.