Forum Index > Kits > Ultimate Kit How to get DS18B20 working
Ultimate Kit How to get DS18B20 working

Post a reply

User: tmc***
Posts: 0
Joined: 2017-01-27 17:03:43

Ultimate Kit How to get DS18B20 working
January 2017 03:51 am

The Ultimate Kit documentation is missing some important information for Lesson 37 How to make a simple Thermometer 2. The DS18B20 is a 1-Wire bus device and each device has a specific serial number address that must be updated in the code. When using the 1602 LCD the address on the I2C bus may also be different, so two commands a required to correctly identify these devices.

$ ls /sys/bus/w1/devices/
28-031656c3cbff  w1_bus_master1

If you only have one DS18B20 sensor connnected, this will be the 28-xxx folder, so copy this serial number into the "open" line of code to use the correct device endpoint in ds18b20.py

#!/usr/bin/env python

def ds18b20Read():
tfile = open("/sys/bus/w1/devices/28-031656c3cbff/w1_slave")
text = tfile.read()
tfile.close()
secondline = text.split(" ")[1]
temperaturedata = secondline.split(" ")[9]
temperature = float(temperaturedata[2:])
temperature = temperature / 1000
temperature = round(temperature, 2)
print temperature
return temperature

For the LCD, use the i2cdetect command to find the correct address of the LCD controller.

$ i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3f 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

In this case 0x3F is the correct address, which is updated in main.py.

#!/usr/bin/env python

import RPi.GPIO as GPIO
import ds18b20
import i2c_lcd1602
import time

screen = i2c_lcd1602.Screen(bus=1, addr=0x3f, cols=16, rows=2)

...

POST A REPLY

Edit

Preview

  • CONNECT WITH US 
Copyright © 2016 Adeept.com All Rights Reserved.