1

I'm trying to measure my Raspberry Pi's temperature using vcgencmd measure_temp but it only works whenever it feels like it:

pi@raspberrypi ~ $ sudo /opt/vc/bin/vcgencmd measure_temp
vc_gencmd_send returned -1
vchi_msg_dequeue -> -1(22)

Any idea what might be going on? It just hangs there, I need to use Ctrl+C to get out of there.

Aurora0001
  • 6,308
  • 3
  • 23
  • 38
João Pereira
  • 285
  • 3
  • 12

2 Answers2

2

This appears to do the trick:

pi@raspberrypi  $ cat /sys/class/thermal/thermal_zone0/temp
57838
João Pereira
  • 285
  • 3
  • 12
  • 1
    I guess that's why hwmon isn't in the stock kernel. This one is from the ACPI interface, which is probably newer but seems a little strange since the pi doesn't have any power management features; presumably it's used because it standardizes /sys better. So I might have been hasty in calling it "daft" ;) – goldilocks Mar 12 '14 at 16:34
0

Any idea what might be going on?

No, but the information is available from the kernel via /sys.

> cat /sys/class/thermal/thermal_zone0/temp
52996

That's thousandths of a degree Celcius (i.e., 52.996 °C).

If your kernel has the hardware monitoring module available (try sudo modprobe -v hwmon; if it says insmod and a path, you do), and you want something more formal, install apt-get lm-sensors and try:

> sensors
bcm2835_hwmon-isa-0000
Adapter: ISA adapter
temp1:        +53.0°C  (high = +85.0°C)

Unfortunately this only seems to work on the single core models.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
  • Hmmm temp1_input does not exist. The "bcm2835_hwmon.0" folder has: modalias power/ subsystem/ uevent – João Pereira Mar 12 '14 at 15:25
  • lm-sensors can't find any sensors by the way, and sensor-detect returns: "/sys/bus/pci/devices: No such file or directory at /usr/sbin/sensors-detect line 3003." – João Pereira Mar 12 '14 at 15:36
  • 1
    Huh -- I use a custom kernel, which probably accounts for that. Raspbian should have a hwmon or bcm2835-hwmon module available, but looking through a copy of a recent image, I don't see it. The max temp is the "high =" number, btw (85.0°C), but the pi does not significantly change temperature even when maxed out (I just did this for 5 min, it got up to 57 °C); I think the only way to truly heat it up is to overclock it... – goldilocks Mar 12 '14 at 15:51
  • Very interesting. I'll ask another question straight away. In any case, I think i've nailed it with: "cat /sys/class/thermal/thermal_zone0/temp" – João Pereira Mar 12 '14 at 16:05
  • Also, it does not work at all in Stretch. – SDsolar Jun 22 '18 at 16:24
  • @SDsolar It is more likely because of the model as this was written when there were only the single core BCM2835 ones. The more generic interface is the one from the accepted answer (/sys/class/thermal/thermal_zone0/temp). That works in Stretch. The sensors CLI, as mentioned, may require kernel modules that aren't included by default in the Pi kernel. – goldilocks Jun 23 '18 at 11:50
  • Understood. However, the Python alternative is ridiculously simple: First, pip install setuptools then sudo pip install git+https://github.com/nicmd/vcgencmd.git then you can use import vcgencmd then CPUc=vcgencmd.temp() then convert to F with CPUf=CPUc*1.8+32 -- works for me. --- FYI, if Python3, then you would use pip3 -- Works for Raspbian Stretch (and Jessie and Wheezy). – SDsolar Jun 24 '18 at 03:33
  • 1
    That presumes the python vcgencmd lib isn't going to fall prey to the problem in the original question, whereas the kernel interface is distinct from that. Anyway, this one is a bit like that Paul Simon song about leaving your lover: echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp) / 1000" | bc -l (I'm a Canuck so Celsius is fine by me.) – goldilocks Jun 24 '18 at 12:23