temperature sensor on gpio [raspberry pi]

for DS18B20 (http://www.amazon.de/dp/B00E7PSHEU)
20150202_232100

based on:
http://www.kompf.de/weather/pionewiremini.html
http://willy-tech.de/temperatursensor-an-raspberry-pi/

enable I2C:
sudo raspi-config
expand filesystem
advanced options -> I2C -> enable I2C + load I2C kernel module by default
reboot

edit the config file:
sudo nano /boot/config.txt

paste the following line at the end:
dtoverlay=w1-gpio,gpiopin=4

reboot the pi:
sudo reboot

run the following commands:
sudo modprobe w1-gpio pullup=1
sudo modprobe w1-therm

get the device id:
cd /sys/bus/w1/devices
ls

[cd 28-0000057*
cat w1_slave]

install bc:
sudo apt-get install bc

edit the modules file:
sudo nano /etc/modules

paste the following lines at the end:
w1-gpio
w1-therm

create a bash script that can print the temperature:
sudo touch /usr/bin/temp
sudo chmod +x /usr/bin/temp
sudo nano /usr/bin/temp

#! /bin/bash

temp=$(cat /sys/bus/w1/devices/28-000005765bf6/w1_slave | sed -n "s/.*t=\(.*\)/\1/p")
temp=`echo "scale=3; $temp / 1000" | bc`
#printf "Aktuelle Temperatur: %05.2f°C\n" $temp #was not working anymore dont know why
printf "Aktuelle Temperatur: $temp°C\n"

bc stopped working and needs to be burned with fire.
http://serverfault.com/questions/644651/bc-using-scale-with-bash-variable

then run it with:
temp

or:
cat /sys/bus/w1/devices/28-000005765bf6/w1_slave | sed -n "s/.*t=\(.*\)/\1/p"

you can also use a python library for it:
(https://github.com/timofurrer/w1thermsensor)

git clone https://github.com/timofurrer/w1thermsensor.git && cd w1thermsensor
python setup.py install

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s