ESP8266 and DS18B20 sensor and MIcropython example

In this example we look at a DS18b20 example in Micropython for an ESP8266. Once again we use uPyCraft and again we use Wemos shields.

Lets remind ourselves about the DS18B20

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.

Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems

Requirements

Lets take a look a the shields and boards that are required for this example

 

Image Summary
The Wemos mini – ESP8266 based board, it comes with various headers. This is the beauty of it you can create stackable projects with the board and pin compatible shields
This is not an official Wemos shield – this uses a DS18B20 and is connected to D2. This does mean that you can use another I2C device
This is simply a base, you plug the Wemos Mini into one side and you can plug a shield or shields into the other side

 

Parts List

I connect the Wemos Mini to the dual base and then put the DS18B20 shield along side this, you can connect the Wemos DS18B20 shield directly to the Wemos Mini if you want.

Name Links
Wemos Mini
DS18B20
Connecting cables

Code

Create a new file called ds.py and import it into uPyCraft

 

from machine import Pin
import time, ds18x20
import onewire
ow = onewire.OneWire(Pin(4)) # create a OneWire bus on GPIO12

ds = ds18x20.DS18X20(ow)

roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)

for rom in roms:
    print(ds.read_temp(rom))

 

 

Output

You should see something like this

Ready to download this file,please wait!
..
download ok
exec(open(‘ds.py’).read(),globals())
26.4375
>>>

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here