Identifying the sensor for use in Gauges

21 March 2012

About a 1-minute read

I am prototyping the software for Gauges from the Ubuntu partition on my white MacBook from 2007. One of the early tasks was finding the name of the temperature sensor corresponding to the main CPU. I installed a cool utility called Psensor that charts sensor outputs over time. Then I opened every application I could think of, and waited for the CPU temperature to increase. Psensor clearly showed that the sensor named “TC0D” corresponded to the CPU temperature. That acronym may mean “Temp-CPU 0 Die”, but I don’t know for sure.

Psensors Screenshot

Once I knew the sensor name, I ran “sensors” in a terminal and found that my computer uses a chip called “applesmc-isa-300”:

travis@travis-ubuntu:~/Projects/Gauges$ sensors
applesmc-isa-0300
Adapter: ISA adapter
Exhaust  :   3074 RPM  (min = 1800 RPM)
TB0T:         +32.5°C
TC0D:         +57.2°C
TC0P:         +55.0°C
TM0P:         +58.0°C
TN0P:         +54.0°C
TTF0:         +55.0°C
TW0P:         +74.0°C
Th0H:         +54.8°C
Th0S:         +54.5°C
Th1H:         +54.2°C

Every Linux sensor has a corresponding pseudo-file for reading programmatically. I dug through online references of various sorts until I found the directory of my chipset, called ‘/sys/bus/platform/devices/applesmc.768/‘. Once I had the directory, I ran sensors again with the -u flag set for “debugging” output:

travis@travis-ubuntu:~/Projects/Gauges$ sensors -u
applesmc-isa-0300
Adapter: ISA adapter
Exhaust  :
  fan1_input: 2309.000
  fan1_min: 1800.000
TB0T:
  temp1_input: 32.500
TC0D:
  temp2_input: 58.250
TC0P:
  temp3_input: 56.000
TM0P:
  temp4_input: 57.750
TN0P:
  temp5_input: 54.500
TTF0:
  temp6_input: 56.250
TW0P:
  temp7_input: 74.000
Th0H:
  temp8_input: 56.000
Th0S:
  temp9_input: 55.750
Th1H:
  temp10_input: 55.500

The verbose output told me that the sensor I want, TC0D, is also called “temp2_input”. Looking in the /sys/bus/platform/devices/applesmc.768/ directory, I found a pseudo-file called “temp2_input”. Perfect!

When my Python script reads /sys/bus/platform/devices/applesmc.768/temp2_input, it gets a string something like “59500” corresponding to 59.5°C. My script converts the number to a float, divides by 1000, then rounds off to the nearest integer so I can fit the number in one byte. Awesome!

Comments