kazz
Posts: 3
Joined: Wed May 28, 2014 4:51 pm

Reading or Detecting newly attached Dallas 1-wire sensors

Wed May 28, 2014 5:00 pm

Hi,

If you are newly attaching Dallas 1-wire sensors such as DS18B20 temp sensors, to your Rasp Pi GPIO pins, the following script may help, as you add each sensor on to the bus. It will quickly let you see
o it is visible or not
o temp reading from the DS18B20
o device unique ID

Hope it is helpful

:)

Save it as devices.sh and execute it with ./devices.sh on the command line

Code: Select all

#!/bin/bash

echo

echo DS18B20 Sensors detected on the 1-wire Dallas bus, and readings at $(date +"%H:%M:%S") on  $(date +"%a %d %b") are .. 

echo

counter=0

SENSORS=$(cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves)

for item in ${SENSORS[*]}; do

let counter=counter+1

TEMP=$(cat /sys/bus/w1/devices/$item/w1_slave | grep t= | cut -f2 -d= | awk '{printf "%2.2f\n",$1/1000}' )

echo sensor$counter = $TEMP degC, deviceID = $item

done

echo

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Reading or Detecting newly attached Dallas 1-wire sensor

Thu May 29, 2014 1:13 pm

I've seen a number of queries about 1-wire sensors on these forums, so I'm sure this diagnostic will be helpful.

But may I point out that it does not behave very elegantly if there are no such sensors detected:

Code: Select all

[email protected] ~ $ sh kazz.sh

DS18B20 Sensors detected on the 1-wire Dallas bus, and readings at 13:09:00 on Thu 29 May are ..

cat: /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves: No such file or directory
kazz.sh: 13: kazz.sh: Bad substitution
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Return to “Automation, sensing and robotics”