Home › Forums › Mayfly Data Logger › Rain Gauge Tip Data Without Rain
- This topic has 10 replies, 5 voices, and was last updated 2022-03-18 at 2:21 PM by BrianJastram.
-
AuthorPosts
-
-
2020-10-28 at 10:29 AM #14723
I’ve got 5 solar powered Mayflys deployed with ProTrinket tip counters connected to heated and non heated rain gauges reporting their data to MMW via Digi XBee3 – RF TXRX Cell 4G LTE AT&T Verison – XB3-C-A2-UT-001 modems. These deployments range in length from 2-14 months. Within the past few months two of these setups have started reporting tips when there is no precipitation or melting snow. I’ve tried re-terminating the rain gauge wires on the ProTrinket screw terminal but that didn’t fix the problem. There doesn’t seem to be more than one tip per recording period (5 min.) and I can’t see a pattern in the frequency of bad tip data. I’ve attached a photo of a graph showing all the rain gauges in my network. The two in question are represented by the thick blue line and the white line. Let me know if you have any troubleshooting ideas.
<p class=”user-nicename”>@aufdenkampe</p>Attachments:
-
2020-10-30 at 10:33 PM #14761
Hi Brian, You may want to describe the type of tipping bucket and the electrical interface for counting . Some types of relay contacts can oxidize and require a minimum wetting current at some point. Do you have a link for the ProTrinket.? regards
-
2020-11-02 at 11:20 AM #14767
I’m guessing you’ve made one of these: https://github.com/EnviroDIY/TippingBucketRainCounter
I’ve edited the code that makes it work with ModularSensors, but I haven’t ever built one. Sorry.
-
2020-11-02 at 4:51 PM #14776
@brianjastram, I think my colleagues in Washington DC have experienced a similar problem to yours, and after a bunch of troubleshooting, we figured out that it was due to electromagnetic interference in the analog signal line from the tipping bucket to the counting device. They had used unshielded cable and also had some unshielded connectors on the outside of the box. We solved the problem only after shielding the entire length of cable, and grounding one end (and only one end) to the battery negative.
I had never seen that my other installations, and those same stations worked fine our Ann Arbor office but started showing those tips at odd times of day in busy urban Environment at our DC office. Our clue was that two tipping buckets sitting next to each other on a desk were showing those random tips at the same time.
Let us know if this might make sense for your situation.
-
2020-11-02 at 9:49 PM #14777
Is there a benefit to using a Trinket for counting the tips instead of using the Mayfly? I’ve built a bunch of tipping bucket recorders using only Mayfly boards by just connecting the bucket’s reed switch to the Mayfly pin D10 and using code to look for an interrupt to wake the Mayfly, increment the count, and go back to sleep. It records and transmits (via 900mhz Xbee) the count every 5 minutes, and resets the daily total at midnight. I’m guessing the Trinket is there so that you don’t miss counting a tip that comes in while the Mayfly is busy doing an uninterruptible time-consuming function, like transmitting the data via cell?
What kind of heater power are you using (AC or DC?), and what circuitry is controlling the heater on-off functionality? Are the ones recording the bad tips equipped with heaters or not? I’d remove the rain gauge reed switch wires from the Trinket so there’s no input at all to the Trinket, and then see if it continues recording phantom tips or not. If it is still recording bad tips, then your problem is with the Trinket. If the bad tips stop, then your problem is likely in the wires going to the gauge (a short somewhere, corrosion, or RFI or other signal interference) or with the reed switch failing (which I’ve seen before).
-
2020-11-03 at 9:19 AM #14781
@shicks, that’s great to hear that you have a bunch of tipping buckets connected directly to the Mayfly. Could you share that code with us? Is it integrated with ModularSensors? It would be very valuable to do that.
I can’t remember all the reasons for developing the TippingBucketRainCounter device application for the Pro Trinket. I do remember exploring lots of options and getting lots of opinions back in the winter of 2018, and my memory was that there were good reasons for not using the Mayfly directly. I’ll see if I can dig up my notes on that.
-
2020-11-03 at 9:49 AM #14783
Below is the code I wrote several years ago that is still running on all our local tipping buckets. This was way before all the ModularSensors libraries and MMW portal, so things could be written differently now, but it can give you and idea on how the Mayfly handles the interrupt signal from the tipping bucket. There’s a 1-second delay after a tip is sensed to filter out any switch bouncing that sometimes occurs when a tip happens.
First you need to enable the pullup resistor on pin D10, which is already built in to the Mayfly board, you just have to close jumper SJ12 on the back of the Mayfly. Then this snippet of the code shows how to set up your sketch to look for a low trigger from the tipping bucket switch:
Arduino1234//enable the D10 pullup jumper on Mayfly solder jumper SJ12 in order for the next 2 lines to workpinMode(10, INPUT); //sets pin 10 as an inputattachInterrupt(2, pin10interrupt, LOW); //sets up an interrupt looking for a LOW trigger//connect one terminal of tipping bucket to Mayfly pin D10, connect other side of bucket switch to Mayfly groundI’ve sent the full sketch code to various people in the past few years who have requested it, and I thought it was already posted somewhere here on the forum, but if not, here’s the entire sketch. The biggest weak point is probably the delays that surround the Xbee radio wakeup and sleep, totaling 5 seconds. If a bucket tip were to happen during these delays, they don’t always get counted. A better option would be to use a milli timer to let the Mayfly go back to looking for tips and then execute the radio on and off functions independently, without using delays. But missing 5 seconds out of a 5 minute period isn’t too bad. (We’ve got Hobo event loggers on these rain gauges to record the actual data, these Mayfly boards are just there to transmit the live tips to our in-house data viz page for realtime viewing.) If the Mayfly has to do even more time-consuming things like cellular transmissions, then having the secondary device like the Trinket would ensure that no tips are missed. There are certainly more efficient ways to build a simple counter, but cost-wise, it’s hard to beat a $7 Trinket. If someone simply wants to count tips of a rain gauge (or any switch close/open event), then this code minus the telemetry stuff works great as an event counter/logger.
Arduino123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371#include <Wire.h>#include <avr/sleep.h>#include <avr/wdt.h>#include <SPI.h>#include <SD.h>//SODAQ libraries#include <RTCTimer.h>#include <Sodaq_DS3231.h>#include <Sodaq_PcInt_Mod.h>String targetURL;#define READ_DELAY 1//RTC TimerRTCTimer timer;String dataRec = ""; //a string to hold the data recordint currentminute, currenthour;long currentepochtime = 0;float boardtemp = 0.0;int daily_tips = 0; //the number of tipsvolatile int TipFlag = 0; //flag indicating that a tip has occurredvolatile int AlarmFlag = 0; //alarm flagint midnightflag = 0; //flag showing that it's midnightint batteryPin = A6;int batterysenseValue = 0;float batteryvoltage;#define XBEE_SleepPin 23 // sleep pin of the Xbee 900mhz radio module//RTC Interrupt pin#define RTC_PIN A7#define RTC_INT_PERIOD EveryMinute#define SD_SS_PIN 12//The data log file#define FILE_NAME "RainLog.txt"//Data header#define LOGGERNAME "Mayfly Rain Logger"#define DATA_HEADER "DateTime_UTC,TZ-Offset,Loggertime,BoardTemp,Battery_V,RainTips"void setup(){//Initialise the serial connectionSerial.begin(57600); //computer connectionSerial1.begin(9600); //xbee 900mhz radio module in bee headerrtc.begin();delay(200);pinMode(8, OUTPUT); //green LEDpinMode(9, OUTPUT); //red LEDgreenred4flash(); //blink the LEDs to show the board is onsetupLogFile();//Setup timer eventssetupTimer();//Setup sleep modesetupSleep();//Make first callSerial.println("Power On, running: mayfly_rain_1.ino");//enable the D10 pullup jumper on Mayfly solder jumper SJ12 in order for the next 2 lines to workpinMode(10, INPUT); //sets pin 10 as an inputattachInterrupt(2, pin10interrupt, LOW); //sets up an interrupt looking for a LOW trigger//connect one terminal of tipping bucket to Mayfly pin D10, connect other side of bucket switch to Mayfly ground}void loop(){//Update the timertimer.update();if (AlarmFlag == 1) {// Serial.println(" DS3231 Alarm ");AlarmFlag = 0;if (currenthour == 23 && currentminute == 59) {midnightflag = 1;digitalWrite(8, HIGH);dataRec = createDataRecord();logData(dataRec);assembleURL();delay(500);wakeXbee();delay(3000);sendviaXbee();delay(2500);sleepXbee();delay(500);String dataRec = "";digitalWrite(8, LOW);midnightflag = 0;daily_tips = 0; //start the daily total back to 0delay(200);}if (currentminute % 5 == 0) {digitalWrite(8, HIGH);dataRec = createDataRecord();logData(dataRec);assembleURL();delay(500);wakeXbee();delay(2000);sendviaXbee();delay(2500);sleepXbee();String dataRec = "";digitalWrite(8, LOW);delay(100);} //end if minute % 5 = 0rtc.clearINTStatus(); //This function call is a must to bring /INT pin HIGH after an interrupt.AlarmFlag = 0;} //end " if alarm_flag=1"if (TipFlag == 1) {// Serial.println(" TIP! ");daily_tips++;delay(1000);TipFlag = 0;}//Sleep//Serial.println("Going to sleep");systemSleep();// Serial.println("AWAKE!");}void showTime(uint32_t ts){//Retrieve and display the current date/timeString dateTime = getDateTime();//Serial.println(dateTime);}void setupTimer(){//Schedule the wakeup every minutetimer.every(READ_DELAY, showTime);//Instruct the RTCTimer how to get the current time readingtimer.setNowCallback(getNow);}void wakeISR(){AlarmFlag = 1;}void setupSleep(){pinMode(RTC_PIN, INPUT_PULLUP);PcInt::attachInterrupt(RTC_PIN, wakeISR);//Setup the RTC in interrupt modertc.enableInterrupts(RTC_INT_PERIOD);//Set the sleep modeset_sleep_mode(SLEEP_MODE_PWR_DOWN);}void systemSleep(){//Wait until the serial ports have finished transmittingSerial.flush();Serial1.flush();//The next timed interrupt will not be sent until this is clearedrtc.clearINTStatus();//Disable ADCADCSRA &= ~_BV(ADEN);//Sleep timenoInterrupts();sleep_enable();interrupts();sleep_cpu();sleep_disable();//Enbale ADCADCSRA |= _BV(ADEN);}String getDateTime(){String dateTimeStr;//Create a DateTime object from the current timeDateTime dt(rtc.makeDateTime(rtc.now().getEpoch()));currentepochtime = (dt.get()); //Unix time in secondscurrentminute = (dt.minute());currenthour = (dt.hour());//Convert it to a Stringdt.addToString(dateTimeStr);return dateTimeStr;}uint32_t getNow(){currentepochtime = rtc.now().getEpoch();return currentepochtime;}void greenred4flash() //fast blinks the LEDs 4 times{for (int i=1; i <= 4; i++){digitalWrite(8, HIGH);digitalWrite(9, LOW);delay(50);digitalWrite(8, LOW);digitalWrite(9, HIGH);delay(50);}digitalWrite(9, LOW);}void setupLogFile(){//Initialise the SD cardif (!SD.begin(SD_SS_PIN)){Serial.println("Error: SD card failed to initialise or is missing.");//Hang// while (true);}//Check if the file already existsbool oldFile = SD.exists(FILE_NAME);//Open the file in write modeFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Add header information if the file did not already existif (!oldFile){logFile.println(LOGGERNAME);logFile.println(DATA_HEADER);}//Close the file to save itlogFile.close();}void logData(String rec){//Re-open the fileFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Write the CSV datalogFile.println(rec);//Close the file to save itlogFile.close();}String createDataRecord(){//Create a String type data record in csv formatString data = getDateTime();data += ",0,"; //adds UTC-timezone offset if your RTC is set to something other than UTCrtc.convertTemperature(); //convert current temperature into registersboardtemp = rtc.getTemperature(); //Read temperature sensor valuebatterysenseValue = analogRead(batteryPin);batteryvoltage = (3.3/1023.) * 4.7 * batterysenseValue;data += currentepochtime;data += ",";addFloatToString(data, boardtemp, 3, 1); //floatdata += ",";addFloatToString(data, batteryvoltage, 4, 2);data += ",";data += daily_tips;//Serial.print("Data Record: "); //if you want to print to the serial port//Serial.println(data);return data;}static void addFloatToString(String & str, float val, char width, unsigned char precision){char buffer[10];dtostrf(val, width, precision, buffer);str += buffer;}void assembleURL(){targetURL = "";targetURL = "http://somewebsite.com/capturescript.php?"; //put a php script on a server with mySQL database to capture the datatargetURL += "LoggerID=SL053&Loggertime=";targetURL += currentepochtime;targetURL += "&BoardTemp=";addFloatToString(targetURL, boardtemp, 3, 1); //floattargetURL += "&Battery=";addFloatToString(targetURL, batteryvoltage, 4, 2); //floattargetURL += "&RainTips=";targetURL += daily_tips;targetURL += "&Summary=";targetURL += midnightflag;}void sendviaXbee() {Serial1.println(targetURL);}void sleepXbee() {delay (1000);pinMode (XBEE_SleepPin,OUTPUT); // put XBee to sleepdigitalWrite(XBEE_SleepPin,HIGH);}void wakeXbee() {pinMode(XBEE_SleepPin,OUTPUT); // Set the "wake-up pin" to outputdigitalWrite(XBEE_SleepPin,LOW); // wake-up XBeedelay(500); //make sure that XBee is ready}void pin10interrupt(){TipFlag = 1; //a tip was detected, set the tip flag} -
2020-11-04 at 11:26 AM #14785
After thinking about this old code yesterday, I was curious about what actually happens if a tip occurs during a long delay period, like the 2-second delay on line 123 and and 2.5-second delay on line 125 (which are delays to give the Xbee 900mhz radio module time to successfully wake up and then finish its routine before sleeping). I programmed a test board with the sketch from above, but increased the delay time to 10 seconds for each of those lines, to give me enough time to experiment. What I found was that if a simulated bucket tip on pin D10 happens anytime during a 10-second delay, the delay instantly ends and the interrupt routine successfully gets executed (meaning a tip gets counted) and then the sketch moves on with the next line of code (either line 124 or 126, depending on which delay the tip happened in). So this shows that no tips will get missed by the Mayfly, but the delay period gets instantly cut short. If you’ve got a radio or cell module that needs multiple seconds of uninterrupted wait times before doing the next step, then care should be taken about how you handle interrupts from D10 during that time. You could unattach the D10 interrupt during those important delay times, and then reattach it when you’re done, or find another way to handle either the interrupt or the telemetry delays.
-
2020-11-09 at 9:24 AM #14802
Shannon, great job moving the science forward. It seems like your line of experimentation could lead to a simpler way to count rain gauge tips and transmit the data to MMW possibly without using a ProTrinket. Maybe if a tip happens while a cellular transmission is happening the transmission could be interrupted, the tip could be counted, and then during the next send interval the data could then be sent to MMW. I am looking for a way to reliably count every tip and send all tip data to MMW even if a send interval is missed here or there.
Using @aufdenkampe ‘s advice as a clue I replaced the 25′ of extra, coiled, shielded analogue signal cable from the original installation between the rain gauge and the ProTrinked with a 3’ length of shielded analogue signal cable on 11/6/2020 and haven’t had any false tips since.
Thank you everyone for the input.
Best Regards,
Brian
-
2020-11-09 at 11:27 AM #14804
@brianjastram, I’m glad to hear that replacing the cable with a shorter length worked!
-
-
2022-03-18 at 2:21 PM #16767
It did seem to make a difference in the short term but the problem started again. My latest fix was to ground the analogue signal cable drain wire to the battery negative. I’ve done this now on 4 rain gauge systems and it seems to help, although one of the systems is still showing tips with no rain.
Attachments:
-
-
AuthorPosts
- You must be logged in to reply to this topic.