Skip to content
Snippets Groups Projects

Board voltage

Merged suazo2 requested to merge board-voltage into main
1 file
+ 11
0
Compare changes
  • Side-by-side
  • Inline
+ 11
0
@@ -55,6 +55,17 @@ class EnergyMonitor:
f"If you're not sure where or how the other power monitor session is running, you can kill it with the following command: kill -9 {pid}")
self.cleanup()
def get_board_voltage(self):
""" Take 10 sample readings and return the average board voltage from the +3.3V rail. """
samples = []
while len(samples) <= 10:
data = self.read_adc(4) # channel 4 is the 3.3V ref voltage
samples.append(data)
avg_reading = sum(samples) / len(samples)
board_voltage = (avg_reading / 1024) * 3.31 * 2
return board_voltage
def read_adc(self, adc_num):
""" Read SPI data from the MCP3008, 8 channels in total. """
r = self.spi.xfer2([1, 8 + adc_num << 4, 0])
Loading