1-Wire is a device communications bus system designed by Dallas/Maxim that provides low-speed data, signaling, and power over a single signal. 1-Wire is similar in concept to I2C, but with lower data rates and longer range. It is typically used to communicate with small inexpensive devices such as digital thermometers and weather instruments (read more...).

This article illustrates how to interface a Dallas/Maxim DS18B20 thermal sensor the CORE9G25 boards and how to read the temperatures using the default 1-wire kernel driver.

Dallas/Maxim DS18B20 thermal sensor

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements. It communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of -55°C to +125°C and is accurate to ±0.5°C over the range of -10°C to +85°C. (read more...).

Area G25 wirings

How to read the temperature

The 1-wire driver automatically scans every 10 seconds if new sensors are plugged on the 1-wire bus.

For each 1-wire device detected a new directory is created on /sys/bus/w1/devices/w1 bus master.

Type:

debarm:~# cd "/sys/bus/w1/devices/w1 bus master"
debarm:/sys/bus/w1/devices/w1 bus master# ls
28-0000028f6667  w1_master_add              w1_master_remove
28-0000028fa89c  w1_master_attempts         w1_master_search
driver           w1_master_max_slave_count  w1_master_slave_count
power            w1_master_name             w1_master_slaves
subsystem        w1_master_pointer          w1_master_timeout
uevent           w1_master_pullup

The two directories 28-xxxx indicate that two thermal sensors are probed on the bus (28 is the family ID) and their unique IDs are 0000028f6667 and 0000028fa89c.

The file w1_master_slaves contains an updated list:

debarm:/sys/bus/w1/devices/w1 bus master# ls
debarm:/sys/bus/w1/devices/w1 bus master# cat w1_master_slaves
28-0000028fa89c
28-0000028f6667

To read the temperature for each sensor type:

debarm:/sys/bus/w1/devices/w1 bus master# cat 28-0000028f6667/w1_slave
49 01 4b 46 7f ff 07 10 f6 : crc=f6 YES
49 01 4b 46 7f ff 07 10 f6 t=20562
t=20562 indicates that the temperature read is 20.562 °C 

Reading the temperature in Python

These simple programs in Python scan the 1-wire bus to detect the thermal sensors available:

scan.py

This code example is downloadable from the CD. File: CD://debian/playground/python/1wire/scan.py

from ablib import w1buslist
 
print "Scan for the available thermal sensors"
 
for device in w1buslist():
	print "Sensor ID = " + device

Download this example from CD then launch it by typing:

debarm:/# debarm:~/playground/python/1wire# python scan1w.py
Scan for the available thermal sensors
Sensor ID = 0000028fa89c

This other example reads the temperature from a specific sensor.

read.py

This code example is downloadable from the CD. File: CD://debian/playground/python/1wire/read.py

from ablib import DS18B20
 
sensor = DS18B20("0000028fa89c")
print "Temp=%.2f C" % (sensor.getTemp())

Change the sensor ID in the source and try it:

debarm:/# debarm:~/playground/python/1wire# python read.py
Temp=20.38 C

Documentation Terms of Use
The Acme Systems srl provides this Debian system development and user manual.
The origin of these doc came from the website: http://www.acmesystems.it
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License


Market Mail : market@armdevs.com
Support Mail: support@armdevs.com Sales Phone: +86-755-29638421


CoreWind Online Chat>
Work time: 09:00-18:00
Copyright @ 2014 to 2020 - CoreWind Tech.