Giter VIP home page Giter VIP logo

pxt-dstemp's Introduction

dstemp

dstemp=github:bsiever/microbit-dstemp

This extension allows the micro:bit to use the Dallas Semiconductor DS18B20 temperature sensor.

Hardware

This module supports use of one or more DS18B20 temperature sensors. Each sensor must be connected to a separate pin and must include a 4.7k Ohm pull-up resistor between 3V and the signal.

Common wiring is:

  • Micro:bit GND to GND (black wire) of the sensor
  • Micro:bit 3V to Vdd (red wire) of the sensor
  • Micro:bit I/O pin, like P0, to the data in/out (white wire) of the sensor

Getting the Temperature

dstemp.celsius(pin: DigitalPin) : number 

Get the current temperature in Celsius. Returns -Infinity on error.

Errors

dstemp.sensorError(errCallback: (errorMessage: string, errorCode: number, port: number) => void) { 

Report on any errors

  • ||errorMessage|| will be a string describing the error
  • ||errorCode|| will be a numeric code
  • ||port|| will indicate which specific port encountered the error (if multiple sensors are connected)

Recommended usage

It's best to capture the temperature in a variable and only use it if the value isn't -Infinity. Since -300 C is below absolute zero, ensuring the temperature is over -300 is sufficient. For example:

temp = dstemp.celsius(DigitalPin.P0)
if (temp > -300) {
    basic.showString("" + (temp))
}
<script src="https://makecode.com/gh-pages-embed.js"></script> <script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script>

pxt-dstemp's People

Contributors

bsiever avatar moore007 avatar doralc avatar

Forkers

moore007

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.