From b11e3dc9b26fed65e40991633db263b20b8adbe3 Mon Sep 17 00:00:00 2001 From: Fisch Date: Thu, 27 Jun 2024 20:38:59 +0200 Subject: [PATCH] enable waterlevel again --- platformio.ini | 21 ++++++++-------- src/main.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/platformio.ini b/platformio.ini index 011cb75..11e09ce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -52,28 +52,29 @@ monitor_speed = 115200 build_flags= - '-D CLIENT_ID="hydroponic-DB"' - -D PIN_BUTTON + '-D CLIENT_ID="hydroponic-Test"' + -D PIN_BUTTON=12 - -D EC_PIN_RELAY_PROBE - -D EC_PIN_FREQ + -D EC_PIN_RELAY_PROBE=6 + -D EC_PIN_FREQ=5 -D EC_CALIBRATION_POLYNOM={8.718380956513695,-0.026463423062356713,3.425216464107108e-05,-4.069826379094172e-09,2.478900495960682e-13} -D EC_CALIBRATION_LINEARIZE_BELOW_ADC=2000 -D EC_CALIBRATION_LINEAR_LOWADC=728 -D EC_CALIBRATION_LINEAR_LOWEC=0 - -D FLOW_PIN - -D ONE_WIRE_BUS_PIN + -D FLOW_PIN=16 + -D ONE_WIRE_BUS_PIN=18 -D THERMOMETER_ADDR_RESERVOIR={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB5} - -D THERMOMETER_ADDR_CASE + -D THERMOMETER_ADDR_CASE={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB6} - -D PIN_SDA - -D PIN_SCL + -D PIN_SDA=1 + -D PIN_SCL=2 lib_deps = https://github.com/milesburton/Arduino-Temperature-Control-Library/ https://github.com/emilv/ArduinoSort/ robtillaart/ADS1X15@^0.3.9 256dpi/MQTT@^2.5.2 - pololu/VL53L0X@^1.3.1 \ No newline at end of file + pololu/VL53L0X@^1.3.1 + adafruit/Adafruit NeoPixel \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 58bc852..4620c3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,14 +48,36 @@ ADS1115 ADS(0x48); //#include "soilmoisture.h" - +#ifdef PIN_NEOPIXEL +#include +Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); +#endif void setup() { pinMode(PIN_BUTTON,INPUT_PULLUP); +#ifdef PIN_LED pinMode(PIN_LED,OUTPUT); digitalWrite(PIN_LED,LOW); +#endif + + + +#if defined(NEOPIXEL_POWER) + // If this board has a power control pin, we must set it to output and high + // in order to enable the NeoPixels. We put this in an #if defined so it can + // be reused for other boards without compilation errors + pinMode(NEOPIXEL_POWER, OUTPUT); + digitalWrite(NEOPIXEL_POWER, HIGH); +#endif +#ifdef PIN_NEOPIXEL + pixels.begin(); + pixels.setBrightness(100); // not so bright + pixels.clear(); +#endif + + Serial.begin(115200); if (mqtt) { WiFi.begin(ssid, pass); @@ -66,7 +88,7 @@ void setup() { Serial.println("Setup Waterlevel"); - //waterlevel_setup(); //Temporarily disabled + waterlevel_setup(); //init ADS1115 @@ -127,7 +149,7 @@ void loop() { temperature_loop(loopmillis); if (!ec_measurementRunning()){ //skip tof read when ec measurement running, because vlxx sensor reading takes quite long per cycle - //Temporarily disabled waterlevel_loop(loopmillis); + waterlevel_loop(loopmillis); } flow_loop(loopmillis); @@ -141,17 +163,35 @@ void loop() { if (!digitalRead(PIN_BUTTON)) { //button pressed valueError=false; Serial.println("Reset ValueError flag by user"); +#ifdef PIN_LED digitalWrite(PIN_LED,valueError); //set led before delay to blink if error persists +#endif +#ifdef PIN_NEOPIXEL + pixels.setPixelColor(0, pixels.Color(255*valueError, 0,0)); + pixels.show(); +#endif delay(100); } static bool last_valueError=true; if (!valuesStabilized) { //if values are not okay since boot +#ifdef PIN_LED digitalWrite(PIN_LED,(loopmillis/250)%2==0); //blink led +#endif +#ifdef PIN_NEOPIXEL + pixels.setPixelColor(0, pixels.Color((loopmillis/250)%2==0,(loopmillis/250)%2==0,0)); + pixels.show(); +#endif }else{ //LED shows valueError flag status when values were okay once if (last_valueError!=valueError) { //update led if valueerror flag changed last_valueError=valueError; +#ifdef PIN_LED digitalWrite(PIN_LED,valueError); +#endif +#ifdef PIN_NEOPIXEL + pixels.setPixelColor(0, pixels.Color((loopmillis/250)%2==0,(loopmillis/250)%2==0,0)); + pixels.show(); +#endif } } } @@ -162,16 +202,32 @@ void loop() { if (eccalibrationoutput && !digitalRead(PIN_BUTTON) && !getReading) { //Calibration UI if (!isValueArrayOK(ec_calib_array,EC_CALIB_ARRAY_SIZE,EC_ADC_UNAVAILABLE)) { for (uint8_t blink=0;blink<5;blink++) { +#ifdef PIN_LED digitalWrite(PIN_LED,HIGH); delay(100); digitalWrite(PIN_LED,LOW); delay(100); +#endif +#ifdef PIN_NEOPIXEL + pixels.setPixelColor(0, pixels.Color(0,0,255)); + pixels.show(); + delay(100); + pixels.setPixelColor(0, pixels.Color(0,0,0)); + pixels.show(); + delay(100); +#endif } }else{ getReading=true; force_ec_measurement=true; ec_flag_measurement_available=false; +#ifdef PIN_LED digitalWrite(PIN_LED,HIGH); +#endif +#ifdef PIN_NEOPIXEL + pixels.setPixelColor(0, pixels.Color(0,255,0)); + pixels.show(); +#endif } } @@ -180,7 +236,13 @@ void loop() { ec_flag_measurement_available=false; getReading=false; +#ifdef PIN_LED digitalWrite(PIN_LED,LOW); +#endif +#ifdef PIN_NEOPIXEL + pixels.setPixelColor(0, pixels.Color(0,0,0)); + pixels.show(); +#endif Serial.print(loopmillis); Serial.print(","); Serial.print(tempCmean_reservoir); Serial.print(","); Serial.print(ec_calib_adc); Serial.print(",");