Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Hydreon connection with teensy board 2++

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Location
    sg
    Posts
    6

    Hydreon connection with teensy board 2++

    Hi all,(am a new user here,so if there is any mistake pls do tell)
    im currently connected my teensy board(2++) to my rain gauge (hydreon) and there's no output(serial monitor) for my arduino 1.8.5 whenever the hydreon (tipping bucket mode) activated. (i've tested with another standard coding(serial print example) and saw serial print in it )
    im unsure whether this is correct cause im following this website (http://cactus.io/hookups/weather/rai...11-rain-sensor) and i need help in term of the pin/coding whether it's correct ornt.
    my pin is connect to f7 on the teensy board 2++ Which i have also wrote to LED to test and its fine.

    this is my coding

    Code:
    #define BOARD "Teensy++ 2.0"
    
    
    #define RG11_Pin 45
    #define Bucket_Size 0.01
    
    volatile unsigned long tipCount; // bucket tip counter used in interrupt routine
    volatile unsigned long ContactTime; // Timer to manage any contact bounce in interrupt routine
    
    
    long lastCount;
    float totalRainfall;
    float AverageperTime;
    
    void setup() {
    
    lastCount = 0;
    tipCount = 0;
    totalRainfall = 0;
    AverageperTime = 0;
    
    Serial.begin(1200);
    Serial.println("Hydreon RG-11 Rain Sensor");
    Serial.print("Bucket Size: "); Serial.print(Bucket_Size); Serial.println(" mm");
    
    pinMode(RG11_Pin, INPUT); // set the digital input pin to input for the RG-11 Sensor
    // attach interrupt handler to input pin.
    // we trigger the interrupt on the voltage falling from 5V to GND
    
    sei(); //Enables interrupts
    }
    
    void loop() {
    // we only display the tip count when it has been incremented by the sensor
    cli(); //Disable interrupts
    
    if(tipCount != lastCount) {
    lastCount = tipCount;
    totalRainfall = tipCount * Bucket_Size;
    AverageperTime = totalRainfall / tipCount; 
    Serial.print("Tip Count: ");
    Serial.print(tipCount);
    Serial.print("\tTotal Rainfall: ");
    Serial.println(totalRainfall);Serial.println("mm/hr"); Serial.println(AverageperTime); 
    
    }
    
    sei(); //Enables interrupts
    }
    
    // Interrrupt handler routine that is triggered when the rg-11 detects rain
    void rgisr () {
    
    if ((millis() - ContactTime) > 15 ) { // debounce of sensor signal
    tipCount++;
    ContactTime = millis();
    }
    }
    // end of rg-11 rain detection interrupt handler

    if anyone could please kindly assist me ?? appreciate it alot & thanks a million!
    Last edited by ivan bingu; 03-21-2018 at 04:27 AM. Reason: link problem

  2. #2
    Senior Member
    Join Date
    Dec 2013
    Location
    East Stroudsburg PA.
    Posts
    290
    Hey can you fix the link it doesn't work at least for me?
    404 Page Not Found
    Crikey! the page you wanted has disappeared, maybe never existed or is a bit shy.
    EDIT:
    Never mind, this is the sensor right:
    http://cactus.io/sensors/weather/rai...n-sensor-RG-11
    Click image for larger version. 

Name:	hydreon-rg-11-hookup-circuit.jpg 
Views:	63 
Size:	20.4 KB 
ID:	13338
    Data Sheets Hydreon RG-11 Instructions
    http://static.cactus.io/docs/sensors...structions.pdf

  3. #3
    Senior Member
    Join Date
    Dec 2013
    Location
    East Stroudsburg PA.
    Posts
    290
    where is the attach interrupt handler ?
    Code:
    attachInterrupt(digitalPinToInterrupt(RG11_pin), rgisr, FALLING);
    HERE:
    Code:
    #define BOARD "Teensy++ 2.0"
    
    
    #define RG11_Pin 45
    #define Bucket_Size 0.01
    
    volatile unsigned long tipCount; // bucket tip counter used in interrupt routine
    volatile unsigned long ContactTime; // Timer to manage any contact bounce in interrupt routine
    
    
    long lastCount;
    float totalRainfall;
    float AverageperTime;
    
    void setup() {
    
      lastCount = 0;
      tipCount = 0;
      totalRainfall = 0;
      AverageperTime = 0;
    
      Serial.begin(1200);
      Serial.println("Hydreon RG-11 Rain Sensor");
      Serial.print("Bucket Size: "); Serial.print(Bucket_Size); Serial.println(" mm");
    
      pinMode(RG11_Pin, INPUT); // set the digital input pin to input for the RG-11 Sensor
      // attach interrupt handler to input pin.
      attachInterrupt(digitalPinToInterrupt(RG11_pin), rgisr, FALLING);  // <------------ THE FIX?
      // we trigger the interrupt on the voltage falling from 5V to GND
    
      sei(); //Enables interrupts
    }
    
    void loop() {
      // we only display the tip count when it has been incremented by the sensor
      cli(); //Disable interrupts
    
      if (tipCount != lastCount) {
        lastCount = tipCount;
        totalRainfall = tipCount * Bucket_Size;
        AverageperTime = totalRainfall / tipCount;
        Serial.print("Tip Count: ");
        Serial.print(tipCount);
        Serial.print("\tTotal Rainfall: ");
        Serial.println(totalRainfall); Serial.println("mm/hr"); Serial.println(AverageperTime);
    
      }
    
      sei(); //Enables interrupts
    }
    
    // Interrrupt handler routine that is triggered when the rg-11 detects rain
    void rgisr () {
    
      if ((millis() - ContactTime) > 15 ) { // debounce of sensor signal
        tipCount++;
        ContactTime = millis();
      }
    }
    // end of rg-11 rain detection interrupt handler

  4. #4
    Senior Member
    Join Date
    Dec 2013
    Location
    East Stroudsburg PA.
    Posts
    290
    Okay i don't have Teensy++ 2.0 but they are based on AVR MCU which i believe you have limited number of interrupt pins, unlike Teensy 3.x series, all pins have interrupt capability.
    You should use only PD0, PD1, PD2 or PD3
    Click image for larger version. 

Name:	pinout4a.png 
Views:	55 
Size:	277.7 KB 
ID:	13339

    Connect the sensor to pin PD0
    Edit this:
    #define RG11_Pin 45
    to
    #define RG11_Pin 0

  5. #5
    Junior Member
    Join Date
    Mar 2018
    Location
    sg
    Posts
    6
    Hi @Chris O.!
    Thanks for the help!
    i have copy & paste into my coding and this is the error i have recieved
    Code:
    Arduino: 1.8.5 (Linux), TD: 1.41, Board: "Teensy++ 2.0, Serial, 8 MHz, US English"
    
    In file included from /home/ivan/Desktop/arduino-1.8.5/hardware/teensy/avr/cores/teensy/Arduino.h:2:0,
                     from /home/ivan/Desktop/arduino-1.8.5/hardware/teensy/avr/cores/teensy/elapsedMillis.h:29,
                     from /home/ivan/Desktop/arduino-1.8.5/hardware/teensy/avr/cores/teensy/WProgram.h:26,
                     from /home/ivan/Desktop/arduino-1.8.5/hardware/teensy/avr/cores/teensy/Arduino.h:1,
                     from /tmp/arduino_build_548723/sketch/RG-11_Sketch.ino.cpp:1:
    /home/ivan/Desktop/open this file to test/RG-11_Sketch/RG-11_Sketch.ino: In function 'void setup()':
    /home/ivan/Desktop/open this file to test/RG-11_Sketch/RG-11_Sketch.ino:29:42: error: 'RG11_pin' was not declared in this scope
        attachInterrupt(digitalPinToInterrupt(RG11_pin), rgisr, FALLING);// attach interrupt handler to input pin.
                                              ^
    /home/ivan/Desktop/arduino-1.8.5/hardware/teensy/avr/cores/teensy/pins_arduino.h:64:36: note: in definition of macro 'digitalPinToInterrupt'
     #define digitalPinToInterrupt(p) ((p) <= 3 ? (p) : (((p) == 36 || (p) == 37) ? (p) - 32 : (((p) == 18 || (p) == 19) ? (p) - 12 : -1)))
                                        ^
    /home/ivan/Desktop/open this file to test/RG-11_Sketch/RG-11_Sketch.ino: In function 'void loop()':
    /home/ivan/Desktop/open this file to test/RG-11_Sketch/RG-11_Sketch.ino:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
        if(tipCount!= lastCount) {
                   ^
    Error compiling for board Teensy++ 2.0.
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    which i dont really understand TT

  6. #6
    Junior Member
    Join Date
    Mar 2018
    Location
    sg
    Posts
    6
    if i were to pin my connection to PDO
    do i change it to
    Code:
    #define RG11_Pin PD0
    OR

    Code:
    #define RG11_Pin 0
    OR Some different coding which is not #define ?

    Thanks alot!

  7. #7
    Senior Member
    Join Date
    Dec 2013
    Location
    East Stroudsburg PA.
    Posts
    290
    Your defining the pin as 45, I'm not sure if Teensy 2++ has that many pins?

    Edit this 1st ok
    Connect the sensor to pin PD0
    Edit this:
    #define RG11_Pin 45
    to
    #define RG11_Pin 0

    this is correct
    Code:
    #define RG11_Pin 0

  8. #8
    Senior Member
    Join Date
    Dec 2013
    Location
    East Stroudsburg PA.
    Posts
    290
    lol
    Code:
                                   #define RG11_Pin 0
     attachInterrupt(digitalPinToInterrupt(RG11_pin), rgisr, FALLING);  // <------------ THE FIX?
    pin or Pin

    Code:
    #define BOARD "Teensy++ 2.0"
    
    #define RG11_Pin 0
    #define Bucket_Size 0.01
    
    volatile unsigned long tipCount; // bucket tip counter used in interrupt routine
    volatile unsigned long ContactTime; // Timer to manage any contact bounce in interrupt routine
    
    long lastCount;
    float totalRainfall;
    float AverageperTime;
    
    void setup() {
    
      lastCount = 0;
      tipCount = 0;
      totalRainfall = 0;
      AverageperTime = 0;
    
      Serial.begin(1200);
      Serial.println("Hydreon RG-11 Rain Sensor");
      Serial.print("Bucket Size: "); Serial.print(Bucket_Size); Serial.println(" mm");
    
      pinMode(RG11_Pin, INPUT); // set the digital input pin to input for the RG-11 Sensor
      // attach interrupt handler to input pin.
      attachInterrupt(digitalPinToInterrupt(RG11_Pin), rgisr, FALLING);  //
      // we trigger the interrupt on the voltage falling from 5V to GND
    
      sei(); //Enables interrupts
    }
    
    void loop() {
      // we only display the tip count when it has been incremented by the sensor
      cli(); //Disable interrupts
    
      if (tipCount != lastCount) {
        lastCount = tipCount;
        totalRainfall = tipCount * Bucket_Size;
        AverageperTime = totalRainfall / tipCount;
        Serial.print("Tip Count: ");
        Serial.print(tipCount);
        Serial.print("\tTotal Rainfall: ");
        Serial.println(totalRainfall); Serial.println("mm/hr"); Serial.println(AverageperTime);
    
      }
    
      sei(); //Enables interrupts
    }
    
    // Interrrupt handler routine that is triggered when the rg-11 detects rain
    void rgisr () {
    
      if ((millis() - ContactTime) > 15 ) { // debounce of sensor signal
        tipCount++;
        ContactTime = millis();
      }
    }
    // end of rg-11 rain detection interrupt handler

  9. #9
    Junior Member
    Join Date
    Mar 2018
    Location
    sg
    Posts
    6
    Hi Chris!
    It works! THANKYOU THANKYOU THANKYOU THANKYOU THANKYOU Gladly appreciated!
    Last edited by ivan bingu; 03-21-2018 at 04:58 AM. Reason: :D

  10. #10
    Senior Member
    Join Date
    Dec 2013
    Location
    East Stroudsburg PA.
    Posts
    290
    No problem
    As far as the division I'm not sure without the hardware it's hard for me to give you advice on this.
    In the post that you show the error the Teensy 2++ appears to be running on 8 MHz
    Arduino: 1.8.5 (Linux), TD: 1.41, Board: "Teensy++ 2.0, Serial, 8 MHz, US English"
    Perhaps you should change that to 16Mhz not sure if the setting will have any timing issues.
    You can change the setting in Arduino Tools menu.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •