geeekpi / upsplus

UPS Plus is a new generation of UPS power management module. It is an improved version of the original UPS prototype. It has been fixed the bug that UPS could not charge and automatically power off during work time. It can not only perform good battery power management, but also provide stable voltage output and RTC functions. At the same time,it support for FCP, AFC, SFCP fast charge protocol, support BC1.2 charging protocol, support battery terminal current/voltage monitoring and support two-way monitoring of charge and discharge. It can provide programmable PVD function. Power Voltage Detector (PVD) can be used to detect if batteries voltage is below or above configured voltage. Once this function has been enabled, it will monitoring your batteries voltage, and you can control whether or not shut down Raspberry Pi via simple bash script or python script. This function will protect your batteries from damage caused by excessive discharge. It can provide Adjustable data sampling Rate. This function allows you to adjust the data sampling rate so that you can get more detailed battery information and also it will consume some power. The data sampling information can communicate with the upper computer device through the I2C protocol. UPS Plus supports the OTA firmware upgrade function. Once there is a new firmware update, it is very convenient for you to upgrade firmware for UPS Plus. The firmware upgrade can be completed only by connecting to the Internet,and execute a python script. Support battery temperature monitoring and power-down memory function. UPS Plus can be set to automatically start the Raspberry Pi after the external power comes on. The programmable shutdown and forced restart function will provide you with a remote power-off restart management method. That means you don’t need to go Unplug the power cable or press the power button to cut off the power again. You can set the program to disconnect the power supply after a few seconds after the Raspberry Pi is shut down properly. And you can also reconnect the power supply after a forced power failure to achieve a remote power-off and restart operation. Once it was setting up, you don't need to press power button to boot up your device which is very suitable for smart home application scenarios.
https://wiki.52pi.com/index.php?title=UPS_Plus_SKU:_EP-0136
MIT License
73 stars 25 forks source link

on debian rpi aarch64 system #39

Closed hellresistor closed 3 years ago

hellresistor commented 3 years ago

Hello I am using this image Debian 10 raspberry

# uname -a
Linux rpi4-20210210 5.10.0-0.bpo.5-arm64 #1 SMP Debian 5.10.24-1~bpo10+1 (2021-03-29) aarch64 GNU/Linux
# sudo i2cdetect -y 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory

I am getting this directory /boot/firmware/config.txt instead the default /boot/config.txt

The file contains:

# Switch the CPU from ARMv7 into ARMv8 (aarch64) mode
arm_64bit=1

enable_uart=1
upstream_kernel=1

### UPSPro Config Added manually ###
dtoverlay=i2c-rtc,ds1307
dtparam=i2c_arm=on
##################

kernel=vmlinuz-5.10.0-0.bpo.5-arm64
# For details on the initramfs directive, see
# https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=10532
initramfs initrd.img-5.10.0-0.bpo.5-arm64

I cannot getting info from UPS .

Executing the script, getting this :|

$ sudo python3 bin/upsPlus_iot.py
[sudo] password for ha:
Traceback (most recent call last):
  File "bin/upsPlus_iot.py", line 16, in <module>
    ina = INA219(0.00725,address=0x40)
  File "/usr/local/lib/python3.7/dist-packages/ina219.py", line 116, in __init__
    self._i2c = I2C.get_i2c_device(address=address, busnum=busnum)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO/I2C.py", line 63, in get_i2c_device
    busnum = get_default_bus()
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO/I2C.py", line 55, in get_default_bus
    raise RuntimeError('Could not determine default I2C bus for platform.')
RuntimeError: Could not determine default I2C bus for platform.

have tried create a link with ln -s /boot/firmware/config.txt /boot/config.txt , but not work.

Maybe a ARM64 imcompatibility ?

PS: The RPI leds are off (both green/red)

yoyojacky commented 3 years ago

yes, you are using 64bit OS, it is a bit different from 32bit OS, and if you can enable I2C on this OS ? because the daughter board is communicate with raspberry pi via I2C protocol via USB-C port , you need to enbale dwc2 function so that it can communicate with each other, and for 32bit, just adding dtoverlay=dwc2,dr_mode=host to /boot/config.txt file and reboot raspberry pi is ok. I am not sure about if 64bit OS also support that dtb file as well.

hellresistor commented 3 years ago

I am getting this output

teste@rpi4-20210718:~$ python3 bin/upsPlus_iot.py
Traceback (most recent call last):
  File "bin/upsPlus_iot.py", line 18, in <module>
    ina_supply = INA219(0.00725,address=0x40)
  File "/home/teste/.local/lib/python3.7/site-packages/ina219.py", line 116, in __init__
    self._i2c = I2C.get_i2c_device(address=address, busnum=busnum)
  File "/home/teste/.local/lib/python3.7/site-packages/Adafruit_GPIO/I2C.py", line 63, in get_i2c_device
    busnum = get_default_bus()
  File "/home/teste/.local/lib/python3.7/site-packages/Adafruit_GPIO/I2C.py", line 55, in get_default_bus
    raise RuntimeError('Could not determine default I2C bus for platform.')
RuntimeError: Could not determine default I2C bus for platform.
teste@rpi4-20210718:~$ i2cdetect -y 1
-bash: i2cdetect: command not found
teste@rpi4-20210718:~$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: -- -- -- -- -- -- -- -- 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77
hellresistor commented 3 years ago

Well a little search and find this !!

teste@rpi4-20210718:~$ sudo i2cdetect -y 0
[sudo] password for teste:
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: -- -- -- -- -- -- -- -- 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77
teste@rpi4-20210718:~$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: -- -- -- -- -- -- -- -- 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77
teste@rpi4-20210718:~$ sudo i2cdetect -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
teste@rpi4-20210718:~$ sudo i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- 17 -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- 45 -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

seems the ic2-3 and not 1

I have 3librarys (i2c-dev , i2c-mux , i2c-smbus) to enable in module.conf (kernel). I am trying 'discover' the right option.

Edit:

teste@rpi4-20210718:~$ sudo i2cdetect -l
[sudo] password for teste:
i2c-3   i2c             bcm2835 (i2c@7e804000)                  I2C adapter
i2c-1   i2c             Broadcom STB :                          I2C adapter
i2c-2   i2c             bcm2835 (i2c@7e205000)                  I2C adapter
i2c-0   i2c             Broadcom STB :                          I2C adapter
hellresistor commented 3 years ago

I can get information using @frtz13 script (setProtectionVoltage.py) Will get info and set with success.

/UPSPlus_mqtt# python3 setProtectionVoltage.py 3000
------------------------------------------------------------
Modify battery protection voltage in UPS Plus
------------------------------------------------------------
Current value:  3600 mV
Successfully set the protection voltage to: 3000 mV

Using your scripts... no .. :| getting this errors

# python3 Full-featured-demo-code.py
Traceback (most recent call last):
  File "Full-featured-demo-code.py", line 20, in <module>
    ina_supply = INA219(0.00725, address=0x40)
  File "/usr/local/lib/python3.7/dist-packages/ina219.py", line 116, in __init__
    self._i2c = I2C.get_i2c_device(address=address, busnum=busnum)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO/I2C.py", line 63, in get_i2c_device
    busnum = get_default_bus()
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO/I2C.py", line 55, in get_default_bus
    raise RuntimeError('Could not determine default I2C bus for platform.')
RuntimeError: Could not determine default I2C bus for platform.

Running ic2 command

root@rpi4-20210718:~# i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- 17 -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- 45 -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Or this when hwclock disabled

teste@rpi4-20210718:~$ /usr/sbin/i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- 17 -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- 45 -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
teste@rpi4-20210718:~$ python3 UPSPlus_mqtt/fanShutDownUps.py
UPS-Plus to MQTT version 20210624 Copyright (C) 2021  https://github.com/frtz13
This program comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under conditions of the GPL (see http://www.gnu.org/licenses for details).

Type ctrl-C to exit
No reply from UPS on i2c bus. Error message: [Errno 121] Remote I/O error
hellresistor commented 3 years ago

Solution: https://github.com/frtz13/UPSPlus_mqtt/issues/14#issuecomment-888541414 Maybe need do update on your code ?!