Giter Site home page Giter Site logo

micropython_ds18x20's Introduction

micropython_ds18x20

this is a really basic tutorial for using the Dallas DS18b20 temperature sensor
on the esp8266 port of micropython

i used the lolin esp8266 D1 mini board and a cheap ds18b20 breakout shield .

the ds18b20 sensors are often sold in a waterproof sealed unit with just the wires exposed. You will need to pull up the data line (normally yellow or white) to VCC with a 4.7kOhm resistor. I am not covering this aspect in this tutorial but this is explained well elsewhere


  • OneWire and ds18x20 micropython library are both in the standard esp8266 port of micropython so it is really easy to get started.

  • The data line on this particular shield is connected to D2 on the Wemos (GPIO 4)

  • create a dat object to specify the Pin the one wire data is supplied through

  • pass the dat object into a onewire , and pass that into a ds18x20

  • each ds18b20 has a 64bit address fixed at manufacture which you access by the scan function, you need this address to run the read_temp function

  • a convert_temp function is called every time a reading is taken

  • then you can run read_temp function which returns temp in Celcius

dat = machine.Pin(4) 
ds = ds18x20.DS18X20(onewire.OneWire(dat))
roms = ds.scan() #this should return a single entry in a byte array
while True:
    ds.convert_temp()
    time.sleep_ms(750) #temp conversion takes 750ms from datasheet
    temp = ds.read_temp(roms[0])
    print(temp)
    time.sleep(5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.