Last active
November 5, 2020 11:29
-
-
Save aallan/6cbc1ace5fe142d2fcec926e917d3a67 to your computer and use it in GitHub Desktop.
Measuring the CPU temperature and clock speed of the Raspberry Pi once a second and logging it to a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import os | |
import time | |
import vcgencmd as vc | |
def main(): | |
start_time = time.time() | |
fb = open("/home/pi/readings.txt","a+") | |
fb.write("Elapsed Time (s),Temperature (°C),Clock Speed (MHz),Voltage Core (V)") | |
while True: | |
clock = int(vc.measure_clock('arm')/1000000) | |
string = '%.0f,%s,%s,%s\n' % ((time.time() - start_time),vc.measure_temp(),clock,vc.measure_volts('core')) | |
print(string, end='') | |
fb.write(string) | |
time.sleep(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment