Approved content

The content below is provided by a partner.

bsiever/microbit-dstemp 0.1.26 GitHub

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:

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

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))
}

makeCodeRender(“{{ site.makecode.home_url }}”, “{{ site.github.owner_name }}/{{ site.github.repository_name }}”);

microbit-dstemp=github:bsiever/microbit-dstemp#v0.1.26