updates
This commit is contained in:
parent
5a98b51849
commit
47db59640b
5 changed files with 11 additions and 6 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
__pycache__/
|
||||||
5
demo.py
Normal file → Executable file
5
demo.py
Normal file → Executable file
|
|
@ -8,10 +8,11 @@ sensors = [
|
||||||
]
|
]
|
||||||
|
|
||||||
solarmon = pm.PowerMon(sensors)
|
solarmon = pm.PowerMon(sensors)
|
||||||
powerData = None
|
powerData = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = solarmon.getData()
|
powerData = solarmon.getData()
|
||||||
|
print("\033c", end="")
|
||||||
print("Raspberry Pi Power Consumption:")
|
print("Raspberry Pi Power Consumption:")
|
||||||
print(f"Vbus:\t\t{powerData[0].voltage} V")
|
print(f"Vbus:\t\t{powerData[0].voltage} V")
|
||||||
print(f"Current:\t{powerData[0].current} A")
|
print(f"Current:\t{powerData[0].current} A")
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ class INA226:
|
||||||
self.data.voltage = float(self.__readRegWord(VOLTAGE_REG_ADDR)) * VOLTAGE_LSB
|
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.power = float(self.__readRegWord(POWER_REG_ADDR)) * CURRENT_LSB * 25.0
|
||||||
self.data.current = float(self.__readRegWord(CURRENT_REG_ADDR)) * CURRENT_LSB
|
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
|
return self.data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +17,8 @@ class PowerMon:
|
||||||
ina = INA226(self.bus, sensors[i][0], sensors[i][1])
|
ina = INA226(self.bus, sensors[i][0], sensors[i][1])
|
||||||
self.chipObjs.append(ina)
|
self.chipObjs.append(ina)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception("Initiating sensors failed: " + e)
|
e.add_note("Initiating sensors failed")
|
||||||
|
raise
|
||||||
|
|
||||||
def getData(self) -> list[PowerData]:
|
def getData(self) -> list[PowerData]:
|
||||||
results = []
|
results = []
|
||||||
|
|
|
||||||
2
powertest.py
Normal file → Executable file
2
powertest.py
Normal file → Executable file
|
|
@ -49,7 +49,7 @@ with SMBus(1) as bus:
|
||||||
print(f"Current:\t{powerData.current} A")
|
print(f"Current:\t{powerData.current} A")
|
||||||
print(f"Power:\t\t{powerData.power} W")
|
print(f"Power:\t\t{powerData.power} W")
|
||||||
#print(f"PowerC:\t\t{powerData.powerCorrected} W")
|
#print(f"PowerC:\t\t{powerData.powerCorrected} W")
|
||||||
#print(bus.read_word_data(ADDRESS, 0x00))
|
#print(hex(readReg(bus, 0x05)))
|
||||||
print()
|
print()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue