Raspberry Pi: Monitoring the Temperature in Fahrenheit, Using Python

I was interested in monitoring the temperature of the CPU, and there’s an easy command for that:
/opt/vc/bin/vcgencmd measure_temp
Go ahead and try it sometime, it will give the following type of output:

Every tutorial I looked up used this command, so the solutions they came up with always had the temperature in Celsius. I use Celsius for monitoring temperatures on my PC, and with my 3D printer, so I’m familiar with it, but as a little challenge I decided to try to adapt a simple temperature monitoring Python script This was complicated by the fact I don’t know Python, but I managed it, with the help of the Internet.

Keval Patel wrote a really nice tutorial all about monitoring the temperature of the Raspberry Pi, and it was his short “temperature monitor” Python script I used as a template. His excellent article can be found at:
https://medium.com/@kevalpatel2106/monitor-the-core-temperature-of-your-raspberry-pi-3ddfdf82989f and I recommend reading it, it explains all the ins and outs.

Without further ado, here is my python script to continuously (once per second) sample and display the temperature of the CPU, with the temperature in Fahrenheit.

import os
import time

def measure_temp():
        temp = os.popen("vcgencmd measure_temp").readline()
        temp = temp.replace("temp=","")
        temp = (temp.split(".",1))[0]
        return (temp)

while True:
        print int(measure_temp())*9/5+32,"F"

Just save it in a file with a .py extension ("name".py), and run from the command line with
python "name".py (Of course, replace “name” with the actual name, like tempmon.py.

And there you have your CPU temperature in Fahrenheit, updated once a second.

31 Replies to “Raspberry Pi: Monitoring the Temperature in Fahrenheit, Using Python”

  1. Just want to say your article is as astonishing. The clearness in your post is simply cool and i can assume you’re an expert on this subject. Well with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please carry on the rewarding work.

  2. Hello! I’ve been following your site for a while now and finally got the courage to go ahead and give you a shout out from Huffman Tx! Just wanted to tell you keep up the good job!

  3. Hi, I think your blog might be having browser compatibility issues.
    When I look at your blog inn Opera, iit looks fine but when opening in Internet Explorer, it has some overlapping.

    I just wanted to give you a quick heads up! Other then that, great

Leave a Reply

Your email address will not be published. Required fields are marked *