Dienstag, 11. November 2014

Montag, 10. November 2014

Temperature sensor DS18S20 and RaspberryPi

The DS18S20 is an integrated circuit, which is 1wire compatible.
It can be connected to the raspi as followed:

DS18S20 Pin1 (GND) --> Raspi P1-06 (Ground)
DS18S20 Pin2 (DATA) --> Raspi P1-07 (GPIO4)
DS18S20 Pin3 (VCC) --> Raspi P1-01 (3,3V)
Additionally we have to add a 4K7 resistor between DS18S20 Pin2 and Pin3

Once you have connected everything you can power up the raspi.


Raspbian comes with almost everything you need to read the temperature from DS18S20

We have to start now the 1wire modules on raspberry:

$ sudo modbrobe w1-gpio pullup=1
$ sudo modprobe w1-therm

Attention! After the next reboot these modules will be not active.
If you want the modules to be started at each reboot, you have to add them to /etc/modules:

$ sudo nano /ect/modules
(add the follwoing lines:)
w1-gpio pullup=1
w1-therm

a quick check for current loaded modules can be done with:
$ lsmod -l

If everything is wired correctly and the modules were started, you can check the sensor by reading it's ID:
$ cat /sys/bus/w1/devices/w1_bus_master/w1_master_slaves
28-00080293af31

The sensors temperature data can be quickly checked by:
$ cat/sys/bus/w1/devices/28-00080293af31/w1-slave
2b 00 4b 46 ff ff 06 10 b1 : grc=b1 YES
2b 00 4b 46 ff ff 06 10 b1 : t=17375

't' has to be devided by 1000 to get the correct temp value - here 17,375 °C


good links for more details:

(en) http://www.raspberrypi-spy.co.uk/2013/03/raspberry-pi-1-wire-digital-thermometer-sensor/
(de) http://kampis-elektroecke.de/?page_id=3678