Skip to content

Commit 5063081

Browse files
committed
Add INPUT_PULLUP option for single DS18B20
1 parent dde5947 commit 5063081

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

sonoff/my_user_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
//#define USE_DS18x20_LEGACY // Optional for more than one DS18x20 sensors with dynamic scan using library OneWire (+1k5 code)
284284
#define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
285285
// #define W1_PARASITE_POWER // If using USE_DS18x20 then optimize for parasite powered sensors
286+
// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistors for single DS18B20
286287

287288
// -- I2C sensors ---------------------------------
288289
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)

sonoff/xsns_05_ds18b20.ino

+12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ uint8_t OneWireReset(void)
4242
uint8_t retries = 125;
4343

4444
//noInterrupts();
45+
#ifdef DS18B20_INTERNAL_PULLUP
46+
pinMode(ds18x20_pin, INPUT_PULLUP);
47+
#else
4548
pinMode(ds18x20_pin, INPUT);
49+
#endif
4650
do {
4751
if (--retries == 0) {
4852
return 0;
@@ -52,7 +56,11 @@ uint8_t OneWireReset(void)
5256
pinMode(ds18x20_pin, OUTPUT);
5357
digitalWrite(ds18x20_pin, LOW);
5458
delayMicroseconds(480);
59+
#ifdef DS18B20_INTERNAL_PULLUP
60+
pinMode(ds18x20_pin, INPUT_PULLUP);
61+
#else
5562
pinMode(ds18x20_pin, INPUT);
63+
#endif
5664
delayMicroseconds(70);
5765
uint8_t r = !digitalRead(ds18x20_pin);
5866
//interrupts();
@@ -81,7 +89,11 @@ uint8_t OneWireReadBit(void)
8189
pinMode(ds18x20_pin, OUTPUT);
8290
digitalWrite(ds18x20_pin, LOW);
8391
delayMicroseconds(3);
92+
#ifdef DS18B20_INTERNAL_PULLUP
93+
pinMode(ds18x20_pin, INPUT_PULLUP);
94+
#else
8495
pinMode(ds18x20_pin, INPUT);
96+
#endif
8597
delayMicroseconds(10);
8698
uint8_t r = digitalRead(ds18x20_pin);
8799
//interrupts();

0 commit comments

Comments
 (0)