raspberry pi 4 cpu temperature external display

In this project I take a BBC micro:bit and a Pimoroni scroll:bit and use them, along with some Python code, to display the Raspberry Pi 4’s CPU temperature.

Here’s a taste of how it looks in operation.

Basically, the micro:bit is plugged into the scroll:bit, and then the micro:bit is attached to the Raspberry Pi 4 with a micro USB cable.

NOTE: You will need the Python psutil module for this to work. If it’s not installed already then execute at the command line: sudo apt install python-psutil -y

The following bit of Python is what provides the data to, and control of, the scroll:bit.

#! /usr/bin/env python3import serial, psutil, time, signal, sysdef sigint_handler(signum, frame):print()sys.exit(0)signal.signal(signal.SIGINT, sigint_handler)ser = serial.Serial("/dev/ttyACM0", 115200, timeout=1)ser.close()ser.open()print("Started monitoring system temperature for scroll:bit display on micro:bit")ser.write("import scrollbit \r".encode())time.sleep(0.1)while True:sysTemp = "%d C" % int(psutil.sensors_temperatures()['cpu-thermal'][0].current)ser.write("scrollbit.scroll(\"%s\") \r".encode() % sysTemp.encode())time.sleep(5.0)

Only 21 lines total to display the RPi’s CPU temperature on the scroll:bit.

The real work is done on lines 19 and 20. Line 19 reads the temperature and formats it into a string, and then line 20 uses that string to create the REPL command that will be sent to the micro:bit to scroll the temperature. I used scrolling because it’s so simple to use, it automatically shows the complete string which is longer than the display can show, and it automatically cleans up after itself. It would take three separate scroll:bit commands (write, show, then clear) to do what the scroll command does. The five second sleep allows the string to scroll all the way across before the next one is sent. This keeps memory usage on the micro:bit to a minimum.

Note that when you set this up, you need to have dropped scrollbit.py onto the micro:bit. You can follow the directions for how to do that here: https://github.com/pimoroni/micropython-scrollbit

I wrote this to see if I could learn how to use these three separate devices. This project allowed me to tie them all together and learned not just how they work individually, but how to integrate them into something interesting, and possibly useful. I also wanted to create a reminder that the processor temperature is very high, perhaps too high.

Update 28 July

I updated the original Python script. I added a Control C handler to make exiting via Control C clean, and moved the script from Python 2 to Python 3. Finally the script has a she-bang at the top; change the script to executable (chmod +x [scriptname.py]) and you can start it at the command line without prefacing it with python3.

getting raspberry pi 4 to work better

I finally got my display to settle down. Yesterday I received a new Nanosecond Extreme Slim 2.6′ MICRO HDMI Cable (micro HDMI to HDMI), plugged the micro end into the Raspberry Pi 4 and the other into my LG 34UM61-P 34″ ultrawide monitor, and it came up without any issues. I picked this cable because it’s used to connect a Sony a7 camera’s video out to an external HDMI video recorder. Before this I’d picked up a cheap-ass adapter (it cost all of $16) at a local Walmart that had a T-connection (micro and mini HDMI male) to HDMI female and had tried to use that, but every time it was in the circuit to the LG monitor, the monitor kept displaying an “Out of Range” message and never displaying anything else. But this new cable fixes that issue and allows the Raspberry Pi 4 video subsystem to negotiate the proper screen resolution with the LG monitor, which in the screenshot above is 2560 x 1080 and now covers the entire monitor edge-to-edge. The only thing I can’t see is the initial boot screen, the four raspberries.

The cheap, bad, adapter even interfered with the operation of the board itself. I tried to ssh into the RPi 4 and the performance while logged in was horrible, with lots of hangs between typing in commands at the prompt. I can’t say enough about how really bad that adapter is. I’m keeping it as a visual aid about what not to purchase and use with the RPi 4.

I’ve been able to work a bit further with the RPi 4, and it indeed has the smooth feel of a regular computer. That is, applications start reasonably quickly and execute reasonably smoothly. I say this comparing it to my mid-2014 Mac Mini Server and my mid-2015 15″ Macbook Pro. I’ve got other PCs lying about (the Samsung R580 with Ubuntu and another Samsung 17.3″ with Windows 10 Pro), but those are the two I use extensively and can compare to. All in all the RPi 4 is a decent utility computer. The RPi is performant enough that writing this entire post on the RPi 4 in Chromium has been a pleasure, rather than something of a chore on the earlier Raspberry Pi releases.

Having said all those nice things, the temperature issue with my RPi 4 still remains. I’ve got mine in the official two piece red-and-white case, with heat sinks on every chip, and it still generates a lot of excess heat. Right this instance in time, ‘vcgencmd measure_temp’ show 70 C, which is excessive, especially with the so-called “proper” heat sinks applied, and with the USB firmware update applied as well. A quick check with vl805 shows firmware version 000137a8.

I will probably spend a bit more money for one of the newer RPi 4 specific cases coming out, to pipe away the heat in a more efficient manner. They don’t cost that much so I can afford to experiment a little. I may also pick up a second RPi 4 card, this one with 2GB of RAM, as those are beginning to show up now. The top-end with 4GB are still missing in action, with a promise delivery date sometime in August.

Right now, if I had to make a choice as to which Raspberry Pi to use in an embedded situation, I’d probably pick the earlier RPi 3B+ or a Raspberry Pi Zero, not this one. That earlier generation is fast enough for embedded work, but runs considerably cooler than this one. I tend to put my systems in locations that aren’t air conditioned and can’t be reached easily, and so they need to be a bit more rugged. I have a feeling that we might get a re-spin of the RPi 4 sooner than expected. I wish they’d worked a bit more on the silicon rather than deciding to go with this CPU revision, with an emphasis on reducing the heat generated.

Overall I’m far more pleased with how the RPI 4 is behaving. The lesson learned today is to never get anything from Walmart.