PLEASE NOTE: This site is no longer being actively maintained. For frequently updated BeagleBone resources please visit Beaglebone.org.

Wednesday, December 10, 2014

On 9:16 AM by Richard St-Pierre

inspire tutorial and project BeagleBone Black CPU Temperature


Overview

The BeagleBone Black is rated for operation at ambient temperatures from 0-to-50C (32-to-122F).
In many applications it can be helpful to know what temperature the CPU is running at. The Texas Instrument AM3358 ARM Cortex processor (CPU) has a built-in temperature sensors to ensure safe operation. In this tutorial we'll explore how this temperature sensor information can be easily accessed and displayed with just a few simple lines of code.

This tutorial is based on work from  Brian Heckathorne.

What You Will Need

You may want to consider a BeagleBone Starter kit.
  • BeagleBone Black
  • BeagleBone expandable case Orange or Black (recommended)
  • AC adapter 5 Volts, 2 Amp (optional)
  • Debian Linux distribution (pre-loaded on Rev C)

STEP 1

SSH into the BeagleBone and create a bash file using your favorite text editor.
We use 'nano'  here to create this simple file.

nano cpu_temp


Copy-paste or simply type the few lines as shown.

nano editor creating bash file for CPU temperature monitor
Nano editor creating bash file


Press ^O (Cntl+O) to write out the file and ^X (Cntl+X) to exit.

Program Listing

# CPU TEMP MONITOR
# CTRL-C TO STOP
# WRITTEN BY BRIAN HECKATHORNE - ME@GODFEAR.ORG 
# Modified by Richard St-Pierre - inspire.logicsupply.com
# Simple script for monitoring the CPU temp on a BeagleBone Black running Debian
 
#!/bin/bash
for (( ; ; ))
do
        echo -n "CPU Temp [Celsius]: "
        cat /sys/class/hwmon/hwmon0/device/temp1_input | sed 's/...$//'
        sleep 2
done

STEP 2 - Make the bash file executable

We need to change the permission of the text file so that it can be executable.

chmod 755 cpu_temp

STEP 3 - Running the program

./cpu_temp

Sample Output

Sample CPU Temperature Output

Note: The reading is in Celsius (ex:60C). This is the temperature 'inside' the cpu chip at ambient room condition. In the sample output the CPU temperature was lowered by placing a finger over the CPU chip. The junction temperature range for the TI  AM3358 commercial specification is 0-to-90C.

Program Overview

A simple bash file is used to extract readings from the system hardware monitor temperature sensor inside the AM3358 Cortex ARM processor. After the first (non-comment) line declaring the file as a bash document, an endless 'for-loop' is used to update the reading to the console. The bash file simply sends (using cat) the 'file' /sys/class/hwmon/hwmon0/device/temp1_input to display the reading.
The measurement data is piped using 'sed' statement to format the output (default format is '60000' representing 60C). A sleep statement provides a reasonable interval for the loop.

You may also be interested in our Temperature Sensor project using the analog input of the BeagleBone.

This plotting project tutorial might interest you, if you would like to graph the results using gnuplot.