Skip to content

Instantly share code, notes, and snippets.

@aallan
Last active November 5, 2020 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aallan/6cbc1ace5fe142d2fcec926e917d3a67 to your computer and use it in GitHub Desktop.
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.
#!/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