geeekpi / upsv3

It is demo code for 52Pi UPS (With RTC & Coulometer) For Raspberry Pi SKU: EP-0118
30 stars 3 forks source link

demo.py error on RPI4 with Bullseye #11

Closed cdwilliams1 closed 7 months ago

cdwilliams1 commented 2 years ago

I could not get the demo.py to run on my Raspberry Pi 4 running the new/latest Bullseye distribution of Raspbian. I was receiving the error "RuntimeError: Could not determine default I2C bus for platform.".

I traced it down to some code in /usr/local/lib/python3.9/dist-packages/Adafruit_GPIO/I2C.py

I commented out line 63:

raise RuntimeError('Could not determine default I2C bus for platform.')

and instead put in new code under the final "else" condition: return 1

This fixed the issue and I was able to retrieve stats using demo.py

19leva89 commented 2 years ago

Установка необходимого софта на Debian

sudo apt-get update sudo apt-get -y install python3-pip python3-smbus python3-dev i2c-tools pip3 --version sudo pip3 install pi-ina219

Создаем и сохраняем файл readvol.py со скриптом sudo nano readvol.py

# IMPORT THE LIBERARY.
from ina219 import INA219
from ina219 import DeviceRangeError
SHUNT_OHMS = 0.05

def read():
    """Define method to read information from coulometer."""
    ina = INA219(SHUNT_OHMS)
    ina.configure()
    print("Bus Voltage: %.3f V" % ina.voltage())
    try:
        print("Bus Current: %.3f mA" % ina.current())
        print("Power: %.3f mW" % ina.power())
        print("Shunt voltage: %.3f mV" % ina.shunt_voltage())
    except DeviceRangeError as e:
        print(e)

if __name__ == "__main__":
    read()

sudo raspi-config -> 3 Interfacing Options -> I5 I2C - > Enable

Добавить вконце файла sudo nano /boot/config.txt dtparam=i2c1=on

sudo reboot

grep i2c /boot/config.txt sudo i2cdetect -y 1 sudo python3 readvol.py