1-wire DS18B20 on NanosG20


I see that there is one wire support in NanosG20
ls /sys/bus/w1/devices
89-5e700faafa21 w1 bus master

A short question:

To which pin should connect a temperature sensor DS18B20 data leg?

Re: 1-wire DS18B20 on NanosG20

I start to feel like a detective, as there is no 1-wire chip in documentation schematics and pinout tables.
On board is 1kbit EEPROm chip DS2502. Soldered a temperature sensor DS18B20 to it's pin 2. Temperature sensor shows up:

cd /sys/bus/w1/drivers/w1_slave_driver
28-000002def034  89-5e700faafa21  bind  uevent  unbind

cd 28-000002def034

but there is no temperature value
Here is what helped to find out what to do:

modprobe wire
modprobe w1-gpio
modprobe w1-therm

cat  w1_slave

a3 01 4b 46 7f ff 0d 10 ce : crc=ce YES
a3 01 4b 46 7f ff 0d 10 ce t=26187

Nice it works. Temperature is 26.187C.

Now need to figure out how to process data. Good help is here:


while (true)
  TEMP=$(echo "scale=3;"`cat /sys/bus/w1/devices/28-000002def034/w1_slave | \
              tail -1 | awk -F "=" '{ print $2; }'`"/1000" | bc -l)
  echo $TEMP
  sleep 2

gives temperature 26.250C. So this forum problem is now solved.

Re: 1-wire DS18B20 on NanosG20

After using temperature sensor for some time notice spikes caused by sensor. To solve spike problem can use code bwelow.
It is run from php and checks for CRC errors. Live example is here:

$count = 0;
$value= 0;
function get_temp(){
global $count, $value;
$temp=`/bin/cat /sys/bus/w1/drivers/w1_slave_driver/28-000002dedb58/w1_slave`;
$crc = substr($temp, 36, 3);
if($crc == "YES"){
$value=substr($temp, 69);
$value = $value/1000;

return $data;
function retry_get_temp(){
global $count, $value;
$count ++;


if(!$output) $output = get_temp();

Re: 1-wire DS18B20 on NanosG20

Below is shell script checking for CRC error
#sleep 2
modprobe wire
modprobe w1-gpio
modprobe w1-therm

while [ $i -lt 10 ]
t=$(cat /sys/bus/w1/drivers/w1_slave_driver/28-000002dedb58/w1_slave)
crc=$(echo $t | awk -F "YES" '{ print $2; }')
t=$(echo $t | awk -F "t=" '{ print $2; }')
t=$(echo "scale=3;$t/1000" | bc -l)

if [ "$crc" = "" ];then echo "CRC error, repeating"
else echo "CRC ok, update database"
rrdtool update /var/www/t.rrd --template t1 N:$t
echo $i
echo $(date) $i $t >>/var/www/t.txt

Re: 1-wire DS18B20 on NanosG20

Did you use 4,7k Ohm resistor from DS18B20 data leg to +5V?
How did you figure that the leg 2 from DS2502 is the right if there is no documentation available? Is to use leg 2 from DS2502 the only way to use 1-wire on NanosG20??
Where did you get GND and +5V for DS18B20? From NanosG20 X11 pin-header (pin 10 for GND and pin 12 for +5V)?

Many thanks and regards!

Syndicate content