Merge pull request #4738 from phreakmonkey/ds18b20_pullup

Add INPUT_PULLUP option for single DS18B20
This commit is contained in:
Theo Arends 2018-12-26 21:53:43 +01:00 committed by GitHub
commit 6f5596425c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -283,6 +283,7 @@
//#define USE_DS18x20_LEGACY // Optional for more than one DS18x20 sensors with dynamic scan using library OneWire (+1k5 code)
#define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
// #define W1_PARASITE_POWER // If using USE_DS18x20 then optimize for parasite powered sensors
// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistors for single DS18B20
// -- I2C sensors ---------------------------------
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)

View File

@ -42,7 +42,11 @@ uint8_t OneWireReset(void)
uint8_t retries = 125;
//noInterrupts();
#ifdef DS18B20_INTERNAL_PULLUP
pinMode(ds18x20_pin, INPUT_PULLUP);
#else
pinMode(ds18x20_pin, INPUT);
#endif
do {
if (--retries == 0) {
return 0;
@ -52,7 +56,11 @@ uint8_t OneWireReset(void)
pinMode(ds18x20_pin, OUTPUT);
digitalWrite(ds18x20_pin, LOW);
delayMicroseconds(480);
#ifdef DS18B20_INTERNAL_PULLUP
pinMode(ds18x20_pin, INPUT_PULLUP);
#else
pinMode(ds18x20_pin, INPUT);
#endif
delayMicroseconds(70);
uint8_t r = !digitalRead(ds18x20_pin);
//interrupts();
@ -81,7 +89,11 @@ uint8_t OneWireReadBit(void)
pinMode(ds18x20_pin, OUTPUT);
digitalWrite(ds18x20_pin, LOW);
delayMicroseconds(3);
#ifdef DS18B20_INTERNAL_PULLUP
pinMode(ds18x20_pin, INPUT_PULLUP);
#else
pinMode(ds18x20_pin, INPUT);
#endif
delayMicroseconds(10);
uint8_t r = digitalRead(ds18x20_pin);
//interrupts();