PyScada on Raspberry PI for temperature monitoring with DS18B20 on 1-Wire – Part 2 – DS18B20 Hardware and Software

Following on from Part 1 (Link)  of this series, this post will cover the DS18B20 and 1-wire communication parts of this project.

Hardware Design

The DS18B20s are connected to the Raspberry PI based on the schematic below.

Using the Raspberry PI’s internal 3.3V Supply and GND pins we can power the DS18B20s on their VDD and GND pins respectively. The 1-wire network is a daisy chained system so we just tie all the DQ pins together. The final component is a single 4.7kOhm resistor that we connect across the 3.3V and Data line. The choice of GPIO4 for the 1-wire connection for the Rasberry PI is based on the default configuration of the 1-wire module.
Raspi-04

The full details are available on the circuits.io page at this (Link).

Current Considerations

When designing the system it was noted that the temperature sensors are powered by the Raspberry PI internal 3.3V supply. It was difficult to find definition of the maximum current rating of the 3.3V regulator. Some sources described the maximum demand from a GPIO point of view to be 50mA however others point out that the hardware has changed between revisions and that this is likely a very conservative number.

If we start with this 50mA number and head to the DS18B20 datasheet (Link) in the DC characteristics table the maximum active current is 1.5mA and the typical is 1mA. So considering the design above does not have anything else connected to the to the 3.3V bus and the likely conservative nature of the 50mA maximum we are looking at being able to calculate the maximum number of DS18B20 on our network using the formula below.

Number of Devices = \frac{50mA}{1.5mA} = 33

This is many more devices than I will be using so we can continue as planned.

Software testing and first measurements

In part 1 (Link) of this series we turned on 1-wire support in the raspi-config application. With the devices connected the setup is complete. Login to the Raspberry PI using SSH run the command below to access the folder where the 1-wire devices will be enumerated and then list everything in the directory.

cd /sys/devices/w1_bus_master1/
ls

My results are below.

28-0317019e43ff
28-031701a251ff
28-031701e813ff
28-031701e81aff
28-0416b3e789ff
28-041701e0caff
28-041701e495ff
28-04170201acff
28-0417020b6bff
28-0417020be3ff
28-0417022dd5ff
driver
power
subsystem
uevent
w1_master_add
w1_master_attempts
w1_master_max_slave_count
w1_master_name
w1_master_pointer
w1_master_pullup
w1_master_remove
w1_master_search
w1_master_slave_count
w1_master_slaves
w1_master_timeout
w1_master_timeout_us

While there is a number of different items here rows 1-11 are the ones that we are interested in at the moment. At the time of writing I have 11 DS18B20 devices connected to the Raspberry PI and their unique serial numbers are listed starting with 28- and ending in ff. The 1-wire driver automatically searches the network and lists the devices found here by creating a folder for each device. If we now look inside the first devices folder using

cd /sys/devices/w1_bus_master1/28-0317019e43ff
ls

We get the following results

driver
id
name
power
subsystem
uevent
w1_slave

Again there are a number of useful files here but the one we are interested in is called w1_slave. Run the cat command to read the file.

cat /sys/devices/w1_bus_master1/28-0317019e43ff/w1_slave

Returns

1e 01 4b 46 7f ff 0c 10 18 : crc=18 YES
1e 01 4b 46 7f ff 0c 10 18 t=17875

This file shows us the current reading by this sensor. The two components that are useful here are the crc=18 YES. Where the YES confirms that we have a valid reading and that it did not get corrupted in transit. The other t=17875 is the temperature measured in millidegree Celsius where the temperature in the room is 17.875 Degrees Celsius.

That’s the basic temperature measurements working nicely, the next part of this series will be about implementing PyScada for monitoring and logging.

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