Measuring Raspberry Pi CPU Temperature – IoTbyHVM

Yes, you can know about CPU temperature. This very simple with a python program. Use th os library to access the temperature sensor built into the Broadcom chip. read this post and you can Measuring Raspberry Pi CPU Temperature easily.

Measuring Raspberry Pi CPU Temperature

Open any text editor or IDLE and paste this code and save with cpu_temp.py.


import os, time

while True:
    dev = os.popen('/opt/vc/bin/vcgencmd measure_temp')
    cpu_temp = dev.read()
    print(cpu_temp)
time.sleep(1)

When you run this program, it will report the temperature. Note that the message printed is actually a string with temp=before the temperature and ‘C’ after it.


python cpu_temp.py
temp=35.8'C
temp=35.9'C

If you want the temp as a number rather than a string, you need to chop off the extra text and then number to a float.


import os, time

while True:
    dev = os.popen('/opt/vc/bin/vcgencmd measure_temp')
    cpu_temp_s = dev.read()[5:-3] # top and tail string
    cpu_temp = float(cpu_temp_s)
    print(cpu_temp)
time.sleep(1)

You may like also:


Buy now : Raspberry PI 3 Model B+ Motherboard

%d bloggers like this: