Skip to content

Commit c2aa014

Browse files
authored
Merge pull request #25 from junkfix/junkfix-patch-1
additional example added
2 parents e98a88a + c7a68d9 commit c2aa014

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

examples/loop/loop.ino

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// https://github.com/junkfix/esp32-ds18b20
2+
3+
#include "OneWireESP32.h"
4+
const uint8_t MaxDevs = 2;
5+
uint8_t tempErr[MaxDevs];
6+
uint8_t tempReady[MaxDevs];
7+
float currTemp[MaxDevs];
8+
uint64_t addr[MaxDevs];
9+
10+
//uint64_t addr[] = {
11+
// 0x183c01f09506f428,
12+
// 0xf33c01e07683de28,
13+
//};
14+
15+
void tempTask(void *pvParameters){
16+
OneWire32 ds(13); //gpio pin
17+
18+
//to find addresses
19+
uint8_t devices = ds.search(addr, MaxDevs);
20+
for (uint8_t i = 0; i < devices; i += 1) {
21+
Serial.printf("%d: 0x%llx,\n", i, addr[i]);
22+
//char buf[20]; snprintf( buf, 20, "0x%llx,", addr[i] ); Serial.println(buf);
23+
}
24+
//end
25+
26+
for(;;){
27+
ds.request();
28+
vTaskDelay(750 / portTICK_PERIOD_MS);
29+
for(byte i = 0; i < MaxDevs; i++){
30+
tempErr[i] = ds.getTemp(addr[i], currTemp[i]);
31+
tempReady[i] = 1;
32+
}
33+
vTaskDelay(3000 / portTICK_PERIOD_MS); //sleep for 3 sec
34+
}
35+
} // tempTask
36+
37+
void setup() {
38+
delay(1000);
39+
Serial.begin(115200);
40+
xTaskCreatePinnedToCore(tempTask, "tempTask", 2048, NULL, 1, NULL, 0);
41+
}
42+
43+
44+
void loop() {
45+
46+
for(byte i = 0; i < MaxDevs; i++){
47+
if(tempReady[i]){
48+
tempReady[i] = 0;
49+
if(tempErr[i]){
50+
const char *errt[] = {"", "CRC", "BAD","DC","DRV"};
51+
Serial.print(i); Serial.print(": "); Serial.println(errt[tempErr[i]]);
52+
}else{
53+
Serial.print(i); Serial.print(": "); Serial.println(currTemp[i]);
54+
}
55+
}
56+
}
57+
58+
59+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=esp32-ds18b20
2-
version=2.0.2
2+
version=2.0.3
33
author=junkfix
44
maintainer=junkfix
55
sentence=Minimal, non-blocking, DS18B20 sensor library for ESP32 using RMT pheripheral, supports multiple sensors, lightweight, no dependencies, will need Arduino esp32 3.x based on IDF 5.X

0 commit comments

Comments
 (0)