Go Down

Topic: Tipping bucket rain gauge sensor with TTGO-T-Beam (Read 144 times) previous topic - next topic

uziboy

Hello,

I am the new one with TTGO-T-Beam board using Arduino IDE. Can someone provide a good sketch to connect TTGO-T-Beam board (one of ESP32 board but some difference) with a tipping bucket rain gauge sensor(has two switch contacts)?

Thank you.

Kai

septillion

#1
Aug 21, 2019, 04:36 pm Last Edit: Aug 21, 2019, 04:37 pm by septillion
No, but we can help you make code :)

Just tell us what your tried. What did you expect? What happened? Where are you stuck?
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

uziboy

Hello, I have an example code for connection between ESP32 and tipping bucket rain gauge. But when it uploads to TTGO-T-Beam which is a integrated device contains ESP32 MCU and other chips. It fails.
And this is the code:

//Rain_Gauge_One.ino

//Original code by jurs od Arduino.cc forum for use with "tipping bucket rain gauge.
//jurs code modified 6/3/2019 @ 14:58 EDT by William Lucid, Github.com/tech500.


#define FIVEMINUTES (30*1000L) // 30 Seconds, for 5 minutes will need changed to 300000 milliseconds

#define REEDPIN 14
#define REEDINTERRUPT 0

int count;
int hourCount;

volatile int pulseCount_ISR = 0;

portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR reedSwitch_ISR()
{
    static unsigned long lastReedSwitchTime;
    // debounce for a quarter second = max. 4 counts per second
    if (labs(millis()-lastReedSwitchTime)>250)
    {
        portENTER_CRITICAL_ISR(&mux);
        pulseCount_ISR++;
       
        lastReedSwitchTime=millis();
        portEXIT_CRITICAL_ISR(&mux);
    }
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("Total\tCurrent");

  pinMode(REEDPIN,INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(REEDPIN),reedSwitch_ISR, FALLING);  // <----- changed to this line
}

unsigned long lastSecond,last5Minutes;
float lastPulseCount;
int currentPulseCount;
float rain5min;
float rainHour;
float rainDay;

void loop()
{
 
  float rainFall;
 
  // each second read and reset pulseCount_ISR
  if (millis()-lastSecond>=1000)
  {
      lastSecond+=1000;
      portENTER_CRITICAL(&mux);
      currentPulseCount+=pulseCount_ISR; // add to current counter  <--changed to this line
      pulseCount_ISR=0; // reset ISR counter
      rainFall = currentPulseCount * .047;
      portEXIT_CRITICAL(&mux);
           
      Serial.print("Rainfall:  " + (String)rainFall);Serial.print('\t');Serial.print("Dumps during 5 Minutes:  " + (String)currentPulseCount);
 
      Serial.println();
  }

    // each 5 minutes save data to another counter
    if (millis()-last5Minutes>=FIVEMINUTES)
    {
 
      count++;
     
      float daysRain;
 
      rain5min = rainFall;
      rainHour = rainHour + rainFall;  //accumulaing 5 minute rainfall for 1 hour then reset -->rainHour Rainfall
      rainDay = rainDay + rainFall;  //Only 1 hour
      daysRain = daysRain + rainDay  ;  //accumulaing every hour rainfall for 1 day then reset -->day total
      //Serial.println("5 Minute Rainfall:  " + (String)rain5min);
      Serial.println("Hourly rainfall rate:  " + (String)rainHour);
      Serial.println("60 Minute Accumulating:  " + (String)rainHour);
      Serial.println("Day Rainfall:  " + (String)rainDay);
      last5Minutes+=FIVEMINUTES; // remember the time
      lastPulseCount+=currentPulseCount; // add to last period Counter
      currentPulseCount=0;; // reset counter for current period
 
      Serial.println("count:  " + (String)count);
 
           if(count == 3) //End of 1 hour  (for testing 90 Seconds); otherwise, count = 20 for real 1 hour.)
           {
               rainFall = 0;
               rainHour = 0;
           }
           
           if (count == 6)  //End of 1 day  (for testing 180 Seconds); otherwise, count = 24 for real 1 hour.)
           {
              rainFall = 0;
              rainHour = 0;
              rainDay = 0;
              daysRain = 0;
              count = 0;         
           
          }
    }
}

uziboy

Whether TTGO borad has the same controller system with ESP32 but cannot upload the same program? After I have changed pin set.

groundFungus

Quote
It fails.
A little more detail would help a lot.  What does "fails" mean?  Fails to compile with some errors?  Post the complete and entire error message(s).  There is a copy errors button in the IDE (lower right).  Copy the errors and paste into a post (in code tags).  Or does "fails" mean compiles but fails to upload?  Or does "fails" mean that the code compiles and uploads but fails to do what you want?

Read the how to use this forum-please read sticky to see how to, properly, post code and some advice on how to ask a good question.  Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

uziboy

Sorry. As 'It fails', I mean when uploaded the same programy on TTGO board instead of ESP32 board, no errors in this uploading process.  the counter of rainfall rate is always '0'. Which means the board did not receive any command to control the rain gauge sensor. So I want to know whether and how can I change the program and make it suit for connection between TTGO board and rain gauge sensor.

Go Up