GyverDS18: an example that runs
Yes. You can use the GyverDS18 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, "Two DS18B20s on one pin, found and read by address", runs on the Arduino Uno R3.
Built in on Mokxi: #include <GyverDS18.h> and it builds, with nothing to install. Free, and no account needed.
What GyverDS18 does
DS18B20 thermometers by uint64_t address: GyverDS18Single for one a pin with tick(), GyverDS18 and GyverDS18Array for several, ready() and readTemp() on a timer, setResolution(), readAddress() and gds::Search to scan the bus. That is what GyverDS18, by AlexGyver, covers. The sketch below uses it on the Arduino Uno: “Two DS18B20s on one pin, found and read by address”.
The GyverDS18 library's interface (AlexGyver, 1.2.1), for DS18B20 thermometers on one pin, by address.
GyverDS18 sends requestTemp() and setResolution() to every sensor at once, or to one by its uint64_t address, and reads one sensor at a time into a shared buffer: readTemp(addr), then getTemp(). An addressed read of the power-up 85 C is an error. tick() here only requests, on the timer. gds::Search finds the addresses.
The calls follow release 1.2.1 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 | GyverDS18 |
|---|---|
| Author | AlexGyver |
| Include | #include <GyverDS18.h>#include <GyverDS18Single.h>#include <GyverDS18Array.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 <GyverDS18.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "GyverDS18" by AlexGyver from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add GyverDS18 to lib_deps in PlatformIO. Mokxi follows the calls of release 1.2.1, so a sketch written here builds there too.
What to know in the simulator: Parasite power is on by default, as upstream, and the pin is driven high during a conversion. The part runs on VDD only, so readPower() says external.
- 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.
GyverDS18 ds(DS_PIN)
Makes ds, the GyverDS18 object the calls below are made on.
ds.setResolution(12)
Sets the resolution to the value you pass in.
ds.requestTemp()
Requests the temp and returns true or false.
ds.readTemp(addr[i])
Returns the temp as true or false.
ds.getTemp()
Returns the temp as a decimal number.
Example: Two DS18B20s on one pin, found and read by address
On the Arduino Uno R3. It runs in the browser exactly as printed.
#include <GyverDS18.h>
#define DS_PIN 2
GyverDS18 ds(DS_PIN);
uint64_t addr[2];
uint8_t found;
void setup() {
Serial.begin(115200);
// Scan the bus for addresses.
found = gds::Search(DS_PIN).scan(addr, 2);
Serial.print("found: ");
Serial.println(found);
for (uint8_t i = 0; i < found; i++) {
Serial.print("address: ");
gds::Addr(addr[i]).printTo(Serial);
}
ds.setResolution(12); // all of them
ds.requestTemp(); // the first conversion, for all of them
}
void loop() {
if (ds.ready()) {
for (uint8_t i = 0; i < found; i++) {
if (ds.readTemp(addr[i])) {
Serial.print("temp ");
Serial.print(i);
Serial.print(": ");
Serial.println(ds.getTemp());
} else {
Serial.println("error");
}
}
ds.requestTemp();
}
}Wiring
- Arduino Uno R3 2 to Temperature sensor, DS18B20 DQ
- Arduino Uno R3 2 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
Keep going
Try GyverDS18 without installing anything
Open the example, change the sketch, and keep your version in a free account.