This commit is contained in:
snedmore 2025-12-12 19:10:27 +00:00
parent 5a98b51849
commit 47db59640b
5 changed files with 11 additions and 6 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__/

5
demo.py Normal file → Executable file
View file

@ -8,10 +8,11 @@ sensors = [
]
solarmon = pm.PowerMon(sensors)
powerData = None
powerData = []
while True:
data = solarmon.getData()
powerData = solarmon.getData()
print("\033c", end="")
print("Raspberry Pi Power Consumption:")
print(f"Vbus:\t\t{powerData[0].voltage} V")
print(f"Current:\t{powerData[0].current} A")

View file

@ -43,6 +43,8 @@ class INA226:
self.data.voltage = float(self.__readRegWord(VOLTAGE_REG_ADDR)) * VOLTAGE_LSB
self.data.power = float(self.__readRegWord(POWER_REG_ADDR)) * CURRENT_LSB * 25.0
self.data.current = float(self.__readRegWord(CURRENT_REG_ADDR)) * CURRENT_LSB
if (self.data.current > 20.96):
self.data.current = 0.0
return self.data

View file

@ -17,7 +17,8 @@ class PowerMon:
ina = INA226(self.bus, sensors[i][0], sensors[i][1])
self.chipObjs.append(ina)
except Exception as e:
raise Exception("Initiating sensors failed: " + e)
e.add_note("Initiating sensors failed")
raise
def getData(self) -> list[PowerData]:
results = []

2
powertest.py Normal file → Executable file
View file

@ -49,7 +49,7 @@ with SMBus(1) as bus:
print(f"Current:\t{powerData.current} A")
print(f"Power:\t\t{powerData.power} W")
#print(f"PowerC:\t\t{powerData.powerCorrected} W")
#print(bus.read_word_data(ADDRESS, 0x00))
#print(hex(readReg(bus, 0x05)))
print()
sleep(1)