Coder Social home page Coder Social logo

microbit-ds18b20's Introduction

microbit-ds18b20 - a ds18b20 thermometer class

This is a class for the dallas ds18b20 thermometer it has the following methods.

readhas a single the argument, it can be READ_SCRATCH, SEARCH_ROM, ALARM_SEARCH or READ_ROM. on success 8 or 9 bytes of data is returned. If there is no data None will be returned for SEARCH commands, but will raise an exception for READ_SCRATCH and READ_ROM. Only use READ_ROM if there is *ONLY* one sensor on the wire. If there a multiple sensors when using READ_ROM they all will respond causing a data collision on the wire. With a sucessful read the ROM code of the sensor will be returned. Using the SEARCH_ROM or ALARM_SEARCH argument has to be done in a loop until no sensor responds and None is returned. READ_SCRATCH retrieves the scratchpad for further processing with the temperature or scratch_data methods
temperaturehas a single argument the scratchpad, which it processes bytes 0 and 1 to create a decimal number
write_scratchwrite arguments register tH, register tL and the number of bits resolution to the scratchpad adjusting the running of the device.
scratch_datahas a single argument the scratchpad and returns a list of the scratchpad data, register tH, register Tl and bits of resolution
match_romhas a single argument the ROM code, this method signals to a ds18b20 that the next read, write or command is for it.

These methods have no arguments.

on_parasitic_powerhas return True if the sensor is running on parasitic power
skip_romalerts all roms that the next instruction is for them to processs such as converting the temperature on all sensors simultaneously or can be used when ther is only one sensor on the wire to avoid having to match the rom before each operation.
convertinstruct the sensor to convert raw data into a temperature and write to scratchpad, this takes some time between 90ms and 750ms the sensor signals when ready, one can wait with the convert_wait method, sleep or just get on with processing knowing plenty of time will have elapsed before a read(READ_SCRATCH) method is called
convert_waituse this method imediately after the convert method to pause processing until the ds18b20 is ready for the next operation
resetuse this method on a new powered up sensor to initialise or to correct alarm coditions or other running issues
copy_to_epromcopies the tH and tL registers and the control byte which stores the number of bits of precission to calculate temperatures to.
cache_from_epromrestores the registers tH and tL an the contol byte to scratchpad

An example of single operation is as follows:

sensor = DS18B20(pin0)

sensor.reset()
sensor.skip_rom()
sensor.convert()
sleep(1000)

sensor.skip_rom()
data = sensor.read(sensor.READ_SCRATCH)
print(sensor.temperature(data))

microbit-ds18b20's People

Contributors

rhubarbdog avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

g-boronad

microbit-ds18b20's Issues

Does the code work?

Hy,
I tryed your code with a micro:bit V2 but nothing is happening. Did you try it with a sensor?
Thanks for your job.
Best regard
Gwendal

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.