In this example we look at a DS18b20 example in Micropython for an ESP8266.
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
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 | Link |
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 |
Code
Create a new file called ds.py and import it into uPyCraft
[codesyntax lang=”python”]
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))
[/codesyntax]
Output
You should see something like this
Ready to download this file,please wait!
..
download ok
exec(open(‘ds.py’).read(),globals())
26.4375
>>>
Links