Wednesday, December 10, 2014
On 9:16 AM by Richard St-Pierre
OverviewThe 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 1SSH into the BeagleBone and create a bash file using your favorite text editor.
We use 'nano' here to create this simple file.
Copy-paste or simply type the few lines as shown.
|Nano editor creating bash file|
Press ^O (Cntl+O) to write out the file and ^X (Cntl+X) to exit.
# 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 executableWe need to change the permission of the text file so that it can be executable.
chmod 755 cpu_temp
STEP 3 - Running the program
|Sample CPU Temperature Output|
Program OverviewA 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.