User Tools

Site Tools


tempsensr

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tempsensr [20.06.2015 14:07]
andreas [Activate Sensor]
tempsensr [20.06.2015 14:07] (current)
andreas [Activate Sensor]
Line 1: Line 1:
 +The easiest way to measure temperature with a Raspberry Pi is to use a digital DS18S20 sensor. This sensor is working with three pins, two are for power supply (3,3V and GND) and the third is the digital data transmission pin. 
 +These type of sensors are from the family of the 1wire bus devices, which is a quite flexible and easy to implement bus.
  
 +===== Datasheet informations =====
 +{{:​ds18s20_pin_configuration.png?​nolink&​70|}}
 +
 +===== Installation =====
 +{{::​ds18s20_raspberry_connection.png?​nolink|}}
 +
 +{{::​ds18s20_installation1.jpg?​direct&​100|}}
 +{{:​ds18s20_installation2.jpg?​direct&​100|}}
 +
 +===== Activate Sensor =====
 +Connect to raspberry and load the kernel modules
 +<code bash>
 +sudo modprobe w1-gpio
 +</​code>​
 +<code bash>
 +sudo modprobe w1-therm
 +</​code>​
 +You can also add these modules to /​etc/​modules to load them during the booting time.
 +
 +Since kernel 3.18 the Device Tree (DT) is used and should be the prefered way to use it. Ensure it's enabled (using raspi-config) and then edit "​**/​boot/​config.txt**"​ and add the following line:
 +
 +<​code>​
 +dtoverlay=w1-gpio,​gpiopin=4,​pullup=on
 +</​code>​
 +
 +The **w1-therm** module should be added to the file "​**/​etc/​modules**"​ anyway.
 +
 +Each sensor will be one device. So we should find our DS18S20 as a device in
 +<code bash>
 +/​sys/​bus/​w1/​devices/​
 +</​code>​
 +
 +My device has the identification "​10-0008028d56e7"​. Inside this folder we can find the file "​w1-slave"​.
 +<code bash>
 +2c 00 4b 46 ff ff 0e 10 17 : crc=17 YES
 +2c 00 4b 46 ff ff 0e 10 17 t=21875
 +</​code>​
 +
 +The crc=17 YES indicates that the sensor is active and t=21875 is the temperature (21.875°C).
 +
 +__Warning:​__ When trying to use an 1wire sensor together with the RaspberryPi camera by using a modern kernel (e.g. 3.10.24+ up to at least 3.12.26+), then please also read the article "​[[1wireandraspicam|Solving mmal error with RaspberryPi Cam and 1wire modules]]",​ when getting mmal errors.
 +===== Shell Script =====
 +If you would like to read the temperature by using a shell script, you can use this short example:
 +
 +<code bash>
 +#!/bin/bash
 +sensor=$(cat /​sys/​bus/​w1/​devices/​10-000802bf3a5e/​w1_slave | cut -c 30-)
 +crc=$(echo $sensor | cut -c 8-10)
 +rawtemp=$(echo $sensor | cut -c 12-)
 +temp=$(echo "​scale=2;​ $rawtemp/​1000"​ | bc -l | awk '​{printf "​%3.2f",​ $0}')
 +if [ "​$rawtemp"​ = ""​ -o "​$crc"​ = "NO " -o "​$crc"​ = ""​ ] ; then
 +        echo "​N/​A";​
 +    else
 +        echo $temp
 +fi
 +exit 0
 +</​code>​
 +
 +The advantage here is, that the script only returns the temperature,​ if the CRC checksum was correct.
 +
 +Probably you have to install //bc// first, before beeing able to execute the script:
 +<code bash>
 +sudo apt-get install bc
 +</​code>​
tempsensr.txt · Last modified: 20.06.2015 14:07 by andreas