microDS18B20: an example that runs
Yes. You can use the microDS18B20 library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Temperature sensor, DS18B20). The example below, "DS18B20s by address and alone on a pin, the microDS18B20 way", runs on the Arduino Uno R3.
Built in on Mokxi: #include <microDS18B20.h> and it builds, with nothing to install. Free, and no account needed.
What microDS18B20 does
DS18B20 thermometers through the MicroDS18B20<pin> template, alone on a pin or by address: requestTemp(), readTemp(), getTemp(), getTempInt(), setResolution(), readAddress() and online(). That is what microDS18B20, by AlexGyver, covers. The sketch below uses it on the Arduino Uno: “DS18B20s by address and alone on a pin, the microDS18B20 way”.
The microDS18B20 library's interface (AlexGyver and Egor 'Nich1con' Zakharov, 3.10), for DS18B20 thermometers.
DS_CHECK_CRC set false before the include turns the CRC check off, as upstream.
The calls follow release 3.10.0 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | microDS18B20 |
|---|---|
| Author | AlexGyver |
| Include | #include <microDS18B20.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | Temperature sensor, DS18B20 |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <microDS18B20.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "microDS18B20" by AlexGyver from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add microDS18B20 to lib_deps in PlatformIO. Mokxi follows the calls of release 3.10.0, so a sketch written here builds there too.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
MicroDS18B20<2, addr1> sensor1
Makes sensor1, the MicroDS18B20 object the calls below are made on.
sensor3.readAddress(address)
Returns the address as true or false.
sensor3.setResolution(10)
Sets the resolution to the value you pass in.
sensor1.requestTemp()
Requests the temp.
sensor1.getTemp()
Returns the temp as a decimal number.
sensor2.readTemp()
Returns the temp as true or false.
Example: DS18B20s by address and alone on a pin, the microDS18B20 way
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <microDS18B20.h>
// Two sensors on one pin, by their addresses.
uint8_t addr1[] = {0x28, 0xFF, 0x78, 0x5B, 0x50, 0x17, 0x04, 0xCF};
uint8_t addr2[] = {0x28, 0xFF, 0x7B, 0x5B, 0x50, 0x17, 0x04, 0x81};
MicroDS18B20<2, addr1> sensor1;
MicroDS18B20<2, addr2> sensor2;
// A third alone on its own pin: no address needed.
MicroDS18B20<3> sensor3;
void setup() {
Serial.begin(9600);
uint8_t address[8];
if (sensor3.readAddress(address)) {
Serial.print("sensor3: {");
for (uint8_t i = 0; i < 8; i++) {
Serial.print("0x");
Serial.print(address[i], HEX);
if (i < 7) Serial.print(", ");
}
Serial.println("}");
} else {
Serial.println("Not connected");
}
sensor3.setResolution(10);
}
void loop() {
sensor1.requestTemp();
sensor2.requestTemp();
sensor3.requestTemp();
delay(1000);
Serial.print("t1: ");
Serial.print(sensor1.getTemp());
Serial.print(", t2: ");
if (sensor2.readTemp()) Serial.print(sensor2.getTemp());
else Serial.print("error");
Serial.print(", t3: ");
if (sensor3.readTemp()) Serial.println(sensor3.getTemp());
else Serial.println("error");
}Wiring
- Arduino Uno R3 2 to Temperature sensor, DS18B20 DQ
- Arduino Uno R3 2 to Temperature sensor, DS18B20 DQ
- Arduino Uno R3 3 to Temperature sensor, DS18B20 DQ
- Arduino Uno R3 5V to Temperature sensor, DS18B20 VDD
- Arduino Uno R3 GND to Temperature sensor, DS18B20 GND
- Arduino Uno R3 5V to Temperature sensor, DS18B20 VDD
- Arduino Uno R3 GND to Temperature sensor, DS18B20 GND
- Arduino Uno R3 5V to Temperature sensor, DS18B20 VDD
- Arduino Uno R3 GND to Temperature sensor, DS18B20 GND
Keep going
Try microDS18B20 without installing anything
Open the example, change the sketch, and keep your version in a free account.