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
Lets take a look a the shields and boards that are required for this example
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.
|Wemos Mini||D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos|
|Wemos Base||Tripler Base V1.0.0 Shield for WeMos D1 Mini|
|Wemos DS18B20 Temperature Sensor Shield||DS18B20 Temperature Sensor Shield Wemos D1 Mini D1 Mini Pro ESP NodeMCU|
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))
You should see something like this
Ready to download this file,please wait!