Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Interrupt and sleep

Interrupt and sleep

Scheduled Pinned Locked Moved Development
26 Posts 7 Posters 10.6k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gohanG Offline
    gohanG Offline
    gohan
    Mod
    wrote on last edited by
    #5

    Are you referring to the sleep(0xff,0x00, 0xff, 0x00, 0)?

    mfalkviddM 1 Reply Last reply
    0
    • gohanG gohan

      Are you referring to the sleep(0xff,0x00, 0xff, 0x00, 0)?

      mfalkviddM Online
      mfalkviddM Online
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #6

      @gohan no. I am referring to "For some reason I am unable to get the board to respond to pin change interrupts when using MySensors gw.sleep() using the MotionSensor.ino" in the first post in the thread I linked to.

      1 Reply Last reply
      0
      • elysionE Offline
        elysionE Offline
        elysion
        wrote on last edited by
        #7

        From your description it sounds like your problem is pretty much exactly same as mine was when I started that thread. I have not experienced any crashes. The issue is just that the board does not wake up on CHANGE. Have you tried using LOW instead of CHANGE for sleep? There were comments in the aforementioned thread that this might be an issue with a certain version of Arduino and boards file. Have not yet had time to investigate tough.

        gohanG 1 Reply Last reply
        1
        • elysionE elysion

          From your description it sounds like your problem is pretty much exactly same as mine was when I started that thread. I have not experienced any crashes. The issue is just that the board does not wake up on CHANGE. Have you tried using LOW instead of CHANGE for sleep? There were comments in the aforementioned thread that this might be an issue with a certain version of Arduino and boards file. Have not yet had time to investigate tough.

          gohanG Offline
          gohanG Offline
          gohan
          Mod
          wrote on last edited by
          #8

          @elysion
          I have updated IDE to latest version and I got a change: now it takes a variable time between 30 sec to 2 minutes for the motion sensor to restore to "0" .
          If I set it to LOW it just skips the sleep as I see continuously errors from reading from the DHT11 sensor until I trigger the motion sensor. Changing it to HIGH or CHANGE I get the same result. Now it's late, so maybe tomorrow I'll try downgrading IDE and boards to 1.6.8 as suggested in another thread.

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #9

            Downgraded to 1.6.8 IDE and boards but no change, also tried to compile it in Visual Studio but behavior is the same. Maybe the Mega has some issues that other boards don't have?
            Here is log

            5079 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
            5107 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
            5112 MCO:SLP:TPD
            5113 MCO:SLP:WUP=1
            1
            5118 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
            5149 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:20.9
            T: 20.94
            5156 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
            5160 MCO:SLP:TPD
            5163 MCO:SLP:WUP=-1
            1
            5168 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
            5196 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
            5200 MCO:SLP:TPD
            5202 MCO:SLP:WUP=-1
            1
            5208 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
            5238 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:20.0
            H: 20.00
            5244 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
            5250 MCO:SLP:TPD
            5252 MCO:SLP:WUP=-1
            1
            5256 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
            5284 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
            5289 MCO:SLP:TPD
            5291 MCO:SLP:WUP=1
            0
            5298 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
            5326 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
            5331 MCO:SLP:TPD
            

            As you can see when motion is triggered (the "1" on 5th line) it takes a while for it to go back to "0" and each message is 10 seconds from the previous like it is ignoring the interrupt.
            I'm running out of options besides buying a few Pro Mini and start building a definitive sensor

            sundberg84S 1 Reply Last reply
            0
            • gohanG gohan

              Downgraded to 1.6.8 IDE and boards but no change, also tried to compile it in Visual Studio but behavior is the same. Maybe the Mega has some issues that other boards don't have?
              Here is log

              5079 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
              5107 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
              5112 MCO:SLP:TPD
              5113 MCO:SLP:WUP=1
              1
              5118 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
              5149 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:20.9
              T: 20.94
              5156 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
              5160 MCO:SLP:TPD
              5163 MCO:SLP:WUP=-1
              1
              5168 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
              5196 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
              5200 MCO:SLP:TPD
              5202 MCO:SLP:WUP=-1
              1
              5208 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
              5238 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:20.0
              H: 20.00
              5244 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
              5250 MCO:SLP:TPD
              5252 MCO:SLP:WUP=-1
              1
              5256 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
              5284 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
              5289 MCO:SLP:TPD
              5291 MCO:SLP:WUP=1
              0
              5298 TSF:MSG:SEND,2-2-0-0,s=0,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
              5326 MCO:SLP:MS=10000,SMS=0,I1=1,M1=1,I2=255,M2=255
              5331 MCO:SLP:TPD
              

              As you can see when motion is triggered (the "1" on 5th line) it takes a while for it to go back to "0" and each message is 10 seconds from the previous like it is ignoring the interrupt.
              I'm running out of options besides buying a few Pro Mini and start building a definitive sensor

              sundberg84S Offline
              sundberg84S Offline
              sundberg84
              Hardware Contributor
              wrote on last edited by
              #10

              @gohan - any change if you try to change the trigger delay on the motion sensor?

              Controller: Proxmox VM - Home Assistant
              MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
              MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
              RFLink GW - Arduino Mega + RFLink Shield, 433mhz

              1 Reply Last reply
              0
              • gohanG Offline
                gohanG Offline
                gohan
                Mod
                wrote on last edited by
                #11

                No, I tried to move it around but it doesn't change the behavior in this case.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JoergP
                  wrote on last edited by
                  #12

                  ahhhhhhhhhhhh - I created a door/window sensor some weeks ago - but I couldn't make it run to fire an interrupt on pin change (INT0 and INT1 are used to connect external magnetic sensors) - today I decided to work on this issue again and found this topic at the forum - so I downgraded my arduino IDE by downloading v1.6.8 from arduino.cc today - compiled my code again - falshed it - and voilà - it works
                  That is really frustrating by wasting that many hours of time only by inconsistancy with compiler/board definitions.
                  Is there any need to update to newer arduino-IDE - otherwise I would recommend to general stick to one version ...

                  gohanG 1 Reply Last reply
                  1
                  • J JoergP

                    ahhhhhhhhhhhh - I created a door/window sensor some weeks ago - but I couldn't make it run to fire an interrupt on pin change (INT0 and INT1 are used to connect external magnetic sensors) - today I decided to work on this issue again and found this topic at the forum - so I downgraded my arduino IDE by downloading v1.6.8 from arduino.cc today - compiled my code again - falshed it - and voilà - it works
                    That is really frustrating by wasting that many hours of time only by inconsistancy with compiler/board definitions.
                    Is there any need to update to newer arduino-IDE - otherwise I would recommend to general stick to one version ...

                    gohanG Offline
                    gohanG Offline
                    gohan
                    Mod
                    wrote on last edited by gohan
                    #13

                    @JoergP
                    Would you mind posting board version you are using and also your code? Did some test but I couldn't figure out anything on my mega so probably there is also something about that kind of board, so I didn't spend too much time on it and wait for the other minis I ordered

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JoergP
                      wrote on last edited by
                      #14

                      I checked the used versions - as I already wrote the used arduino-IDE is 1.6.8. But due to the case that I used 1.8.0 before and downgraded the board definition by "Board manager" the board definition is 1.6.11 (if you down/upgrade by BoardManager you can find the files in dir "C:\Users...\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11"
                      I added my own definitions to board.txt (because I use 2AA Battery node -> https://www.openhardware.io/view/10/My-Slim-2AA-Battery-Node)

                      here my quick and dirty source - have to clean up if it works as expected:

                      // ---------------------------------------------------------
                      // based on 2AA Battery Node
                      // ATMEGA328P (@ internal OSC 1MHz)
                      // device ID = 0x07D5 (2005d )
                      // ---------------------------------------------------------
                      // 0  - Input 0 -> S_DOOR / V_TRIPPED
                      // 1  - Input 1 -> S_DOOR / V_TRIPPED
                      // 2  - temperature (HTU)
                      // 3  - humidity (HTU)
                      // ---------------------------------------------------------
                      
                      
                      // ---------------------------------------------------------
                      // includes
                      // ---------------------------------------------------------
                      #include <Wire.h>
                      #include "Adafruit_HTU21DF.h"
                      
                      #include <Vcc.h>
                      #include <avr/wdt.h>
                      
                      // ---------------------------------------------------------
                      // MySensors
                      // ---------------------------------------------------------
                      #define MY_RADIO_NRF24
                      #define MY_RF24_PA_LEVEL RF24_PA_MAX
                      #include <MySensors.h>
                      #include <SPI.h>
                      
                      // ---------------------------------------------------------
                      // MySensor
                      // ---------------------------------------------------------
                      #define SN "AA - Windows / Temperature"
                      #define SV "1.1"
                      #define ms_input_0      0
                      #define ms_input_1      1
                      #define ms_temperature  2
                      #define ms_humidity     3
                      
                      // ---------------------------------------------------------
                      // used PINs
                      // ---------------------------------------------------------
                      #define PIN_INPUT_0     2
                      #define PIN_INPUT_1     3
                      
                      // ---------------------------------------------------------
                      // Sleep
                      // ---------------------------------------------------------
                      #define SLEEP_TIME 300000   // ms => 5 min
                      #define VALUE_MIN_COUNT 12  // send min every 12th measurement one value (once per hour)
                      
                      // ---------------------------------------------------------
                      // Vcc
                      // ---------------------------------------------------------
                      #define VCC_MIN 1.9
                      #define VCC_MAX 3.3
                      #define BATTERY_COUNT 288   // 288 * 5 min = 1 day
                      
                      // ---------------------------------------------------------
                      // global vars
                      // ---------------------------------------------------------
                      MyMessage msg(0,0);
                      
                      Adafruit_HTU21DF htu = Adafruit_HTU21DF();
                      boolean htu_available = false;
                      float htu_temperature = 1000;
                      float htu_humidity = 1000;
                      int batteryCnt = 0;
                      int temperatureCnt = 0;
                      int humidityCnt = 0;;
                      
                      Vcc vcc;
                      
                      
                      // #########################################################
                      // setup
                      // #########################################################
                      void setup() {
                        // ---------
                        // PINs
                        // ---------  
                        pinMode(PIN_INPUT_0, INPUT_PULLUP);
                        pinMode(PIN_INPUT_1, INPUT_PULLUP);
                        
                        // ---------
                        // HTU21
                        // ---------
                        if (htu.begin())
                          htu_available = true;
                      }
                      
                      // #########################################################
                      // presentation
                      // #########################################################
                      void presentation()
                      {
                        // Send the sketch version information to the gateway and Controller
                        sendSketchInfo(SN, SV);
                        
                        // Send sensor information
                        present(ms_input_0, S_DOOR);
                        present(ms_input_1, S_DOOR);
                      
                        if(htu_available) {
                          present(ms_temperature, S_TEMP);
                          present(ms_humidity, S_HUM);
                        }
                      }
                      
                      // #########################################################
                      // loop
                      // #########################################################
                      void loop() {
                        // enable watchdog
                        wdt_enable(WDTO_8S);
                      
                        // -------------
                        // inputs
                        // -------------
                        sendInput0();
                        sendInput1();
                      
                        // -------------
                        // check battery
                        // -------------
                        if(batteryCnt == 0)
                          sendBatteryReport();
                      
                        batteryCnt++;
                        if(batteryCnt > BATTERY_COUNT)
                          batteryCnt = 0;
                        
                        // -------------
                        // temperature
                        // -------------
                        if(htu_available) {
                          sendTemperature();
                          sendHumidity();
                        }
                        
                        // -------------
                        // sleep
                        // -------------
                        delay(500);
                        wdt_disable();
                        sleep(digitalPinToInterrupt(PIN_INPUT_0), CHANGE, digitalPinToInterrupt(PIN_INPUT_1), CHANGE, SLEEP_TIME);
                      }
                      
                      
                      // #########################################################
                      // helper functions
                      // #########################################################
                      float rfloat(float val, unsigned int num) {
                        if(num) {
                          float f = 10.0 * num;
                          return round(val*f)/f;
                        }
                        else
                          return round(val);
                      }
                      
                      void sendTemperature() {
                        wdt_reset();
                        float tmp = htu.readTemperature();
                        if(tmp < 900){ // check errors
                          tmp = rfloat(tmp, 1);
                          if((tmp != htu_temperature) || (temperatureCnt >= VALUE_MIN_COUNT)){
                            htu_temperature = tmp;
                            send(msg.setSensor(ms_temperature).setType(V_TEMP).set(htu_temperature,1));
                            temperatureCnt = 0;
                          }
                          else
                            temperatureCnt++;
                        }
                      }
                      
                      void sendHumidity() {
                        wdt_reset();
                        float tmp = htu.readHumidity();
                        if(tmp < 900){ // check errors
                          tmp = rfloat(tmp, 0);
                          if((tmp != htu_humidity) || (humidityCnt >= VALUE_MIN_COUNT)){
                            htu_humidity = tmp;
                            send(msg.setSensor(ms_humidity).setType(V_HUM).set(htu_humidity,0));
                            humidityCnt = 0;
                          }
                          else
                            humidityCnt++;
                        }  
                      }
                      
                      void sendBatteryReport() {
                        wdt_reset();
                        delay(500);
                        float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
                        int batteryPcnt = static_cast<int>(p);
                        sendBatteryLevel(batteryPcnt);
                      }
                      
                      void sendInput0() {
                        wdt_reset();
                        if(digitalRead(PIN_INPUT_0) == HIGH)
                          send(msg.setSensor(ms_input_0).setType(V_TRIPPED).set(0));
                        else
                          send(msg.setSensor(ms_input_0).setType(V_TRIPPED).set(1));
                      }
                      
                      void sendInput1() {
                        wdt_reset();
                        if(digitalRead(PIN_INPUT_1) == HIGH)
                          send(msg.setSensor(ms_input_1).setType(V_TRIPPED).set(0));
                        else
                          send(msg.setSensor(ms_input_1).setType(V_TRIPPED).set(1));
                      }```
                      EfflonE 1 Reply Last reply
                      0
                      • gohanG Offline
                        gohanG Offline
                        gohan
                        Mod
                        wrote on last edited by
                        #15

                        What does this do?
                        wdt_enable(WDTO_8S);

                        1 Reply Last reply
                        0
                        • gohanG Offline
                          gohanG Offline
                          gohan
                          Mod
                          wrote on last edited by
                          #16

                          Tests so far are just as the same as before even with the changes you suggested, so I believe I'll just wait for the other new arduinos and use the mega for other purposes

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            JoergP
                            wrote on last edited by
                            #17

                            That's bad - if you like you can send me your source and I can try to compile it on my environment.
                            I use the watchdog in general - in the past I had the issue that some nodes stopped working without any reason - watchdog helped to solve this

                            1 Reply Last reply
                            0
                            • gohanG Offline
                              gohanG Offline
                              gohan
                              Mod
                              wrote on last edited by
                              #18

                              Look at my first post, that's the code. It's a draft so it's not really cleaned up

                              1 Reply Last reply
                              0
                              • J JoergP

                                I checked the used versions - as I already wrote the used arduino-IDE is 1.6.8. But due to the case that I used 1.8.0 before and downgraded the board definition by "Board manager" the board definition is 1.6.11 (if you down/upgrade by BoardManager you can find the files in dir "C:\Users...\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.11"
                                I added my own definitions to board.txt (because I use 2AA Battery node -> https://www.openhardware.io/view/10/My-Slim-2AA-Battery-Node)

                                here my quick and dirty source - have to clean up if it works as expected:

                                // ---------------------------------------------------------
                                // based on 2AA Battery Node
                                // ATMEGA328P (@ internal OSC 1MHz)
                                // device ID = 0x07D5 (2005d )
                                // ---------------------------------------------------------
                                // 0  - Input 0 -> S_DOOR / V_TRIPPED
                                // 1  - Input 1 -> S_DOOR / V_TRIPPED
                                // 2  - temperature (HTU)
                                // 3  - humidity (HTU)
                                // ---------------------------------------------------------
                                
                                
                                // ---------------------------------------------------------
                                // includes
                                // ---------------------------------------------------------
                                #include <Wire.h>
                                #include "Adafruit_HTU21DF.h"
                                
                                #include <Vcc.h>
                                #include <avr/wdt.h>
                                
                                // ---------------------------------------------------------
                                // MySensors
                                // ---------------------------------------------------------
                                #define MY_RADIO_NRF24
                                #define MY_RF24_PA_LEVEL RF24_PA_MAX
                                #include <MySensors.h>
                                #include <SPI.h>
                                
                                // ---------------------------------------------------------
                                // MySensor
                                // ---------------------------------------------------------
                                #define SN "AA - Windows / Temperature"
                                #define SV "1.1"
                                #define ms_input_0      0
                                #define ms_input_1      1
                                #define ms_temperature  2
                                #define ms_humidity     3
                                
                                // ---------------------------------------------------------
                                // used PINs
                                // ---------------------------------------------------------
                                #define PIN_INPUT_0     2
                                #define PIN_INPUT_1     3
                                
                                // ---------------------------------------------------------
                                // Sleep
                                // ---------------------------------------------------------
                                #define SLEEP_TIME 300000   // ms => 5 min
                                #define VALUE_MIN_COUNT 12  // send min every 12th measurement one value (once per hour)
                                
                                // ---------------------------------------------------------
                                // Vcc
                                // ---------------------------------------------------------
                                #define VCC_MIN 1.9
                                #define VCC_MAX 3.3
                                #define BATTERY_COUNT 288   // 288 * 5 min = 1 day
                                
                                // ---------------------------------------------------------
                                // global vars
                                // ---------------------------------------------------------
                                MyMessage msg(0,0);
                                
                                Adafruit_HTU21DF htu = Adafruit_HTU21DF();
                                boolean htu_available = false;
                                float htu_temperature = 1000;
                                float htu_humidity = 1000;
                                int batteryCnt = 0;
                                int temperatureCnt = 0;
                                int humidityCnt = 0;;
                                
                                Vcc vcc;
                                
                                
                                // #########################################################
                                // setup
                                // #########################################################
                                void setup() {
                                  // ---------
                                  // PINs
                                  // ---------  
                                  pinMode(PIN_INPUT_0, INPUT_PULLUP);
                                  pinMode(PIN_INPUT_1, INPUT_PULLUP);
                                  
                                  // ---------
                                  // HTU21
                                  // ---------
                                  if (htu.begin())
                                    htu_available = true;
                                }
                                
                                // #########################################################
                                // presentation
                                // #########################################################
                                void presentation()
                                {
                                  // Send the sketch version information to the gateway and Controller
                                  sendSketchInfo(SN, SV);
                                  
                                  // Send sensor information
                                  present(ms_input_0, S_DOOR);
                                  present(ms_input_1, S_DOOR);
                                
                                  if(htu_available) {
                                    present(ms_temperature, S_TEMP);
                                    present(ms_humidity, S_HUM);
                                  }
                                }
                                
                                // #########################################################
                                // loop
                                // #########################################################
                                void loop() {
                                  // enable watchdog
                                  wdt_enable(WDTO_8S);
                                
                                  // -------------
                                  // inputs
                                  // -------------
                                  sendInput0();
                                  sendInput1();
                                
                                  // -------------
                                  // check battery
                                  // -------------
                                  if(batteryCnt == 0)
                                    sendBatteryReport();
                                
                                  batteryCnt++;
                                  if(batteryCnt > BATTERY_COUNT)
                                    batteryCnt = 0;
                                  
                                  // -------------
                                  // temperature
                                  // -------------
                                  if(htu_available) {
                                    sendTemperature();
                                    sendHumidity();
                                  }
                                  
                                  // -------------
                                  // sleep
                                  // -------------
                                  delay(500);
                                  wdt_disable();
                                  sleep(digitalPinToInterrupt(PIN_INPUT_0), CHANGE, digitalPinToInterrupt(PIN_INPUT_1), CHANGE, SLEEP_TIME);
                                }
                                
                                
                                // #########################################################
                                // helper functions
                                // #########################################################
                                float rfloat(float val, unsigned int num) {
                                  if(num) {
                                    float f = 10.0 * num;
                                    return round(val*f)/f;
                                  }
                                  else
                                    return round(val);
                                }
                                
                                void sendTemperature() {
                                  wdt_reset();
                                  float tmp = htu.readTemperature();
                                  if(tmp < 900){ // check errors
                                    tmp = rfloat(tmp, 1);
                                    if((tmp != htu_temperature) || (temperatureCnt >= VALUE_MIN_COUNT)){
                                      htu_temperature = tmp;
                                      send(msg.setSensor(ms_temperature).setType(V_TEMP).set(htu_temperature,1));
                                      temperatureCnt = 0;
                                    }
                                    else
                                      temperatureCnt++;
                                  }
                                }
                                
                                void sendHumidity() {
                                  wdt_reset();
                                  float tmp = htu.readHumidity();
                                  if(tmp < 900){ // check errors
                                    tmp = rfloat(tmp, 0);
                                    if((tmp != htu_humidity) || (humidityCnt >= VALUE_MIN_COUNT)){
                                      htu_humidity = tmp;
                                      send(msg.setSensor(ms_humidity).setType(V_HUM).set(htu_humidity,0));
                                      humidityCnt = 0;
                                    }
                                    else
                                      humidityCnt++;
                                  }  
                                }
                                
                                void sendBatteryReport() {
                                  wdt_reset();
                                  delay(500);
                                  float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
                                  int batteryPcnt = static_cast<int>(p);
                                  sendBatteryLevel(batteryPcnt);
                                }
                                
                                void sendInput0() {
                                  wdt_reset();
                                  if(digitalRead(PIN_INPUT_0) == HIGH)
                                    send(msg.setSensor(ms_input_0).setType(V_TRIPPED).set(0));
                                  else
                                    send(msg.setSensor(ms_input_0).setType(V_TRIPPED).set(1));
                                }
                                
                                void sendInput1() {
                                  wdt_reset();
                                  if(digitalRead(PIN_INPUT_1) == HIGH)
                                    send(msg.setSensor(ms_input_1).setType(V_TRIPPED).set(0));
                                  else
                                    send(msg.setSensor(ms_input_1).setType(V_TRIPPED).set(1));
                                }```
                                EfflonE Offline
                                EfflonE Offline
                                Efflon
                                wrote on last edited by
                                #19

                                @JoergP ans others, I have tried versions 1.6.8 and the board definitions 1.6.11 and interrupt seems to work but in the case of using a PIR the sensor somehow seems to be triggered when going out of sleep due to time...

                                J 1 Reply Last reply
                                0
                                • EfflonE Efflon

                                  @JoergP ans others, I have tried versions 1.6.8 and the board definitions 1.6.11 and interrupt seems to work but in the case of using a PIR the sensor somehow seems to be triggered when going out of sleep due to time...

                                  J Offline
                                  J Offline
                                  JoergP
                                  wrote on last edited by
                                  #20

                                  @Efflon I'm not sure what exactly you mean - do you refer to my code? In that case this is a quick and dirty try - I'll send at every pin change and at timeout the input values ...

                                  EfflonE 1 Reply Last reply
                                  0
                                  • gohanG Offline
                                    gohanG Offline
                                    gohan
                                    Mod
                                    wrote on last edited by
                                    #21

                                    My mega goes to sleep for the time specified, but it doesn't wake up when pir is triggered

                                    1 Reply Last reply
                                    0
                                    • J JoergP

                                      @Efflon I'm not sure what exactly you mean - do you refer to my code? In that case this is a quick and dirty try - I'll send at every pin change and at timeout the input values ...

                                      EfflonE Offline
                                      EfflonE Offline
                                      Efflon
                                      wrote on last edited by Efflon
                                      #22

                                      @JoergP Sorry, what I meant was regarding the versions you were using to get your sensor to work. I've been fighting to get interrupts to work for a day and your suggestion helped.
                                      Now it's just that going out of sleep triggers the PIR, then it goes for sleep and wakes up immediately and then finally goes to sleep ... gahh

                                      Tripped: 0
                                      13207 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
                                      13213 MCO:SLP:TPD
                                      13217 MCO:SLP:WUP=-1
                                      interrupt: -1
                                      Tripped: 0
                                      Tripped: 1
                                      Tripped: 1
                                      Tripped: 1
                                      Tripped: 1
                                      interrupt: -1
                                      Tripped: 1
                                      Tripped: 0
                                      Tripped: 0
                                      Tripped: 0
                                      Tripped: 0
                                      14024 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
                                      14032 MCO:SLP:TPD
                                      14034 MCO:SLP:WUP=1
                                      interrupt: 1
                                      Tripped: 0
                                      Tripped: 0
                                      Tripped: 0
                                      Tripped: 0
                                      Tripped: 0
                                      14440 MCO:SLP:MS=30000,SMS=0,I1=1,M1=3,I2=255,M2=255
                                      14446 MCO:SLP:TPD```
                                      1 Reply Last reply
                                      0
                                      • J Offline
                                        J Offline
                                        JoergP
                                        wrote on last edited by
                                        #23

                                        hmmmm .... I'm not so familiar with the arduino build process - I guess that Interrupt Request registers are not reset correctly, but never did that manual with Arduino

                                        I use following board setting

                                        AAnode1.name=AA sensor node (1MHz int)
                                        
                                        AAnode1.upload.tool=avrdude
                                        AAnode1.upload.protocol=arduino
                                        AAnode1.upload.maximum_size=32256
                                        AAnode1.upload.speed=9600
                                        AAnode1.bootloader.tool=avrdude
                                        AAnode1.bootloader.low_fuses=0x62
                                        AAnode1.bootloader.high_fuses=0xde
                                        AAnode1.bootloader.extended_fuses=0x07
                                        AAnode1.bootloader.path=optiboot_v50
                                        AAnode1.bootloader.unlock_bits=0x3F
                                        AAnode1.bootloader.lock_bits=0x2F
                                        AAnode1.build.mcu=atmega328p
                                        AAnode1.build.f_cpu=1000000L
                                        AAnode1.build.core=arduino
                                        AAnode1.build.variant=standard
                                        AAnode1.build.board=AVR_AANODE_1MHz
                                        

                                        I guess the xxx.build.xxx settings are of interest - do you use the same or do you have different?

                                        EfflonE 1 Reply Last reply
                                        0
                                        • J JoergP

                                          hmmmm .... I'm not so familiar with the arduino build process - I guess that Interrupt Request registers are not reset correctly, but never did that manual with Arduino

                                          I use following board setting

                                          AAnode1.name=AA sensor node (1MHz int)
                                          
                                          AAnode1.upload.tool=avrdude
                                          AAnode1.upload.protocol=arduino
                                          AAnode1.upload.maximum_size=32256
                                          AAnode1.upload.speed=9600
                                          AAnode1.bootloader.tool=avrdude
                                          AAnode1.bootloader.low_fuses=0x62
                                          AAnode1.bootloader.high_fuses=0xde
                                          AAnode1.bootloader.extended_fuses=0x07
                                          AAnode1.bootloader.path=optiboot_v50
                                          AAnode1.bootloader.unlock_bits=0x3F
                                          AAnode1.bootloader.lock_bits=0x2F
                                          AAnode1.build.mcu=atmega328p
                                          AAnode1.build.f_cpu=1000000L
                                          AAnode1.build.core=arduino
                                          AAnode1.build.variant=standard
                                          AAnode1.build.board=AVR_AANODE_1MHz
                                          

                                          I guess the xxx.build.xxx settings are of interest - do you use the same or do you have different?

                                          EfflonE Offline
                                          EfflonE Offline
                                          Efflon
                                          wrote on last edited by
                                          #24

                                          @JoergP Don't know. I just select "mini pro" from within Arduino IDE.
                                          I'll create a new trouble shooting topic with my problem since this is going out of topic.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular