Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsiever/microbit-dstemp
Micro:bit DS18B20 Temp Sensor Blocks
https://github.com/bsiever/microbit-dstemp
microbit pxt-microbit
Last synced: 3 months ago
JSON representation
Micro:bit DS18B20 Temp Sensor Blocks
- Host: GitHub
- URL: https://github.com/bsiever/microbit-dstemp
- Owner: bsiever
- License: mit
- Created: 2019-01-25T03:36:33.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-06T22:48:59.000Z (about 1 year ago)
- Last Synced: 2024-01-26T07:04:12.716Z (6 months ago)
- Topics: microbit, pxt-microbit
- Language: C++
- Homepage: https://bsiever.github.io/microbit-dstemp/
- Size: 239 KB
- Stars: 4
- Watchers: 1
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Lists
- awesome-microbit - DSTemp - Read the temperature from one or multiple DS18B20 sensors. (👩💻 Programming / 🗿 JavaScript and MakeCode)
README
# dstemp
```package
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
```sig
dstemp.celsius(pin: DigitalPin) : number
```Get the current temperature in Celsius. Returns `-Infinity` on error.
# Errors```sig
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:
```block
temp = dstemp.celsius(DigitalPin.P0)
if (temp > -300) {
basic.showString("" + (temp))
}
```makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");