From 5bda74bbcc9f430c89bd632899a7da9366f7b277 Mon Sep 17 00:00:00 2001 From: c3ma Date: Wed, 14 Oct 2020 17:10:55 +0200 Subject: [PATCH] Temp sensor added --- esp32test/Esp32DeepSleepTest/platformio.ini | 1 + esp32test/Esp32DeepSleepTest/src/main.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/esp32test/Esp32DeepSleepTest/platformio.ini b/esp32test/Esp32DeepSleepTest/platformio.ini index 768aa93..27cb0c8 100644 --- a/esp32test/Esp32DeepSleepTest/platformio.ini +++ b/esp32test/Esp32DeepSleepTest/platformio.ini @@ -13,3 +13,4 @@ platform = espressif32 board = esp32doit-devkit-v1 framework = arduino build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY +lib_deps = OneWire diff --git a/esp32test/Esp32DeepSleepTest/src/main.cpp b/esp32test/Esp32DeepSleepTest/src/main.cpp index b918c7b..161e0b8 100644 --- a/esp32test/Esp32DeepSleepTest/src/main.cpp +++ b/esp32test/Esp32DeepSleepTest/src/main.cpp @@ -1,5 +1,6 @@ #include #include "esp_sleep.h" +#include #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ @@ -7,6 +8,8 @@ #define SENSOR_LIPO 34 /**< GPIO 34 (ADC1) */ #define SENSOR_SOLAR 35 /**< GPIO 35 (ADC1) */ +#define SENSOR_DS18B20 2 /**< GPIO 2 */ + #define OUTPUT_PUMP0 23 /**< GPIO 23 */ #define OUTPUT_PUMP1 22 /**< GPIO 22 */ @@ -33,6 +36,8 @@ RTC_DATA_ATTR int bootCount = 0; RTC_DATA_ATTR int pumpActive = 0; int secondBootCount = 0; +Ds18B20 ds(SENSOR_DS18B20); + void print_wakeup_reason(){ esp_sleep_wakeup_cause_t wakeup_reason; @@ -61,6 +66,7 @@ void setAll2Off() { } void setup() { + pinMode(OUTPUT_PUMP0, OUTPUT); pinMode(OUTPUT_PUMP1, OUTPUT); pinMode(OUTPUT_PUMP2, OUTPUT); @@ -126,6 +132,18 @@ void loop() { double value = analogRead(SENSOR_LIPO); Serial.println(value); + + float temp[2] = {0, 0}; + float* pFloat = temp; + + Serial.print("DS18B20 sensors: "); + Serial.println(ds.readDevices()); + delay(200); + if (ds.readAllTemperatures(pFloat, 2) > 0) { + Serial.println(temp[0]); + Serial.println(temp[1]); + } + double volt = ADC_5V_TO_3V3(value); Serial.print("Lipo: ");