Temp sensor added

This commit is contained in:
c3ma 2020-10-14 17:10:55 +02:00
parent c470ba6dc7
commit 5bda74bbcc
2 changed files with 19 additions and 0 deletions

View File

@ -13,3 +13,4 @@ platform = espressif32
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
framework = arduino framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
lib_deps = OneWire

View File

@ -1,5 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "esp_sleep.h" #include "esp_sleep.h"
#include <DS18B20.h>
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #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) */ #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_LIPO 34 /**< GPIO 34 (ADC1) */
#define SENSOR_SOLAR 35 /**< GPIO 35 (ADC1) */ #define SENSOR_SOLAR 35 /**< GPIO 35 (ADC1) */
#define SENSOR_DS18B20 2 /**< GPIO 2 */
#define OUTPUT_PUMP0 23 /**< GPIO 23 */ #define OUTPUT_PUMP0 23 /**< GPIO 23 */
#define OUTPUT_PUMP1 22 /**< GPIO 22 */ #define OUTPUT_PUMP1 22 /**< GPIO 22 */
@ -33,6 +36,8 @@ RTC_DATA_ATTR int bootCount = 0;
RTC_DATA_ATTR int pumpActive = 0; RTC_DATA_ATTR int pumpActive = 0;
int secondBootCount = 0; int secondBootCount = 0;
Ds18B20 ds(SENSOR_DS18B20);
void print_wakeup_reason(){ void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason; esp_sleep_wakeup_cause_t wakeup_reason;
@ -61,6 +66,7 @@ void setAll2Off() {
} }
void setup() { void setup() {
pinMode(OUTPUT_PUMP0, OUTPUT); pinMode(OUTPUT_PUMP0, OUTPUT);
pinMode(OUTPUT_PUMP1, OUTPUT); pinMode(OUTPUT_PUMP1, OUTPUT);
pinMode(OUTPUT_PUMP2, OUTPUT); pinMode(OUTPUT_PUMP2, OUTPUT);
@ -126,6 +132,18 @@ void loop() {
double value = analogRead(SENSOR_LIPO); double value = analogRead(SENSOR_LIPO);
Serial.println(value); 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); double volt = ADC_5V_TO_3V3(value);
Serial.print("Lipo: "); Serial.print("Lipo: ");