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. Troubleshooting
  3. fails to wake with 2 interupts

fails to wake with 2 interupts

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 4 Posters 395 Views 4 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.
  • markjgabbM Offline
    markjgabbM Offline
    markjgabb
    wrote on last edited by
    #1

    hi all im having issue with the follow code...

    i have two devices on pin 2 and 3 on a pro mini but cant seem to get wake working one both...
    is anyone able to hint/advise on have gone wrong?

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     *
     * DESCRIPTION
     * Motion Sensor example using HC-SR501
     * http://www.mysensors.org/build/motion
     *
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <MySensors.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    #include <SPI.h>
    
    
    #define COMPARE_TEMP 0
    #define MAX_ATTACHED_DS18B20 1
    #define DOOR_PIN  3
    #define ONE_WIRE_BUS 5 // Pin where dallase sensor is connected
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=1;
    bool receivedConfig = false;
    bool metric = true;
    
    
    
    uint32_t SLEEP_TIME = 900000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID_MOTION 1   // Id of the sensor child
    #define CHILD_ID_TEMP 2
    #define CHILD_ID_DOOR 3
    // Initialize motion message
    MyMessage motion(CHILD_ID_MOTION, V_TRIPPED);
    MyMessage temp(CHILD_ID_TEMP,V_TEMP);
    MyMessage door(CHILD_ID_DOOR,V_TRIPPED);
    
    //=========================
    // BATTERY VOLTAGE DIVIDER SETUP
    // 1M, 470K divider across battery and using internal ADC ref of 1.1V
    // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
    // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
    // 3.44/1023 = Volts per bit = 0.003363075
    #define VBAT_PER_BITS 0.003363075  
    #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
    #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
    int batteryPcnt = 0;                              // Calc value for battery %
    int batLoop = 0;                                  // Loop to help calc average
    int batArray[3];                                  // Array to store value for average calc.
    int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
    //=========================
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();
    }
    
    
    
    void setup()
    {
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    
    pinMode(DOOR_PIN, INPUT);
      // Activate internal pull-up
      digitalWrite(DOOR_PIN, HIGH);
    
    
      
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Front Hall Motion&temp", "1.0");
    
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_MOTION, S_MOTION);
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_DOOR, S_DOOR);
    }
    
    void loop()
    {
        // Read digital motion value
        bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
        Serial.print("Montion Sensor State: ");
        Serial.println(tripped);
        send(motion.set(tripped?"1":"0"));  // Send tripped value to gw
    
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
    
     bool trippeddoor = digitalRead(DOOR_PIN) == HIGH;
        Serial.print("Door Sensor State: ");
        Serial.println(trippeddoor);
        send(door.set(trippeddoor?"1":"0"));  // Send tripped value to gw
        
        
    sensors.requestTemperatures();
      Serial.print("Temprature: ");
      Serial.println(sensors.getTempCByIndex(0));
      // query conversion time and sleep until conversion completed
      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
      wait(500);
    
      // Read temperatures and send them to controller 
    
        // Fetch and round temperature to one decimal
        float temperature = sensors.getTempCByIndex(0);
        
          // Send in the new temperature
          send(temp.setSensor(1).set(temperature,1));
          // Save new temperatures for next compare
    
          batM();
          delay(500);
          sleep(3000);
        sleep(DIGITAL_INPUT_SENSOR,CHANGE,DOOR_PIN,CHANGE,SLEEP_TIME);
    }
    
    
    void batM() //The battery calculations
    {
       delay(500);
       // Battery monitoring reading
       int sensorValue = analogRead(BATTERY_SENSE_PIN);    
       delay(500);
       
       // Calculate the battery in %
       float Vbat  = sensorValue * VBAT_PER_BITS;
       int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
       Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
       
       // Add it to array so we get an average of 3 (3x20min)
       batArray[batLoop] = batteryPcnt;
      
       if (batLoop > 2) {  
         batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
         batteryPcnt = batteryPcnt / 3;
     
       if (batteryPcnt > 100) {
         batteryPcnt=100;
     }
     
         Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
           sendBatteryLevel(batteryPcnt);
           batLoop = 0;
          }
         else 
         {
         batLoop++;
         }
    }
     
    
    BearWithBeardB 1 Reply Last reply
    0
    • markjgabbM markjgabb

      hi all im having issue with the follow code...

      i have two devices on pin 2 and 3 on a pro mini but cant seem to get wake working one both...
      is anyone able to hint/advise on have gone wrong?

      /*
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2019 Sensnology AB
       * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       *
       * DESCRIPTION
       * Motion Sensor example using HC-SR501
       * http://www.mysensors.org/build/motion
       *
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      //#define MY_RADIO_NRF5_ESB
      //#define MY_RADIO_RFM69
      //#define MY_RADIO_RFM95
      
      #include <MySensors.h>
      #include <DallasTemperature.h>
      #include <OneWire.h>
      #include <SPI.h>
      
      
      #define COMPARE_TEMP 0
      #define MAX_ATTACHED_DS18B20 1
      #define DOOR_PIN  3
      #define ONE_WIRE_BUS 5 // Pin where dallase sensor is connected
      OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
      DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
      float lastTemperature[MAX_ATTACHED_DS18B20];
      int numSensors=1;
      bool receivedConfig = false;
      bool metric = true;
      
      
      
      uint32_t SLEEP_TIME = 900000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      #define CHILD_ID_MOTION 1   // Id of the sensor child
      #define CHILD_ID_TEMP 2
      #define CHILD_ID_DOOR 3
      // Initialize motion message
      MyMessage motion(CHILD_ID_MOTION, V_TRIPPED);
      MyMessage temp(CHILD_ID_TEMP,V_TEMP);
      MyMessage door(CHILD_ID_DOOR,V_TRIPPED);
      
      //=========================
      // BATTERY VOLTAGE DIVIDER SETUP
      // 1M, 470K divider across battery and using internal ADC ref of 1.1V
      // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      // 3.44/1023 = Volts per bit = 0.003363075
      #define VBAT_PER_BITS 0.003363075  
      #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
      #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
      int batteryPcnt = 0;                              // Calc value for battery %
      int batLoop = 0;                                  // Loop to help calc average
      int batArray[3];                                  // Array to store value for average calc.
      int BATTERY_SENSE_PIN = A0;                       // select the input pin for the battery sense point
      //=========================
      
      void before()
      {
        // Startup up the OneWire library
        sensors.begin();
      }
      
      
      
      void setup()
      {
          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      
      pinMode(DOOR_PIN, INPUT);
        // Activate internal pull-up
        digitalWrite(DOOR_PIN, HIGH);
      
      
        
      }
      
      void presentation()
      {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Front Hall Motion&temp", "1.0");
      
          // Register all sensors to gw (they will be created as child devices)
          present(CHILD_ID_MOTION, S_MOTION);
          present(CHILD_ID_TEMP, S_TEMP);
          present(CHILD_ID_DOOR, S_DOOR);
      }
      
      void loop()
      {
          // Read digital motion value
          bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
          Serial.print("Montion Sensor State: ");
          Serial.println(tripped);
          send(motion.set(tripped?"1":"0"));  // Send tripped value to gw
      
          // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      
       bool trippeddoor = digitalRead(DOOR_PIN) == HIGH;
          Serial.print("Door Sensor State: ");
          Serial.println(trippeddoor);
          send(door.set(trippeddoor?"1":"0"));  // Send tripped value to gw
          
          
      sensors.requestTemperatures();
        Serial.print("Temprature: ");
        Serial.println(sensors.getTempCByIndex(0));
        // query conversion time and sleep until conversion completed
        // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
        wait(500);
      
        // Read temperatures and send them to controller 
      
          // Fetch and round temperature to one decimal
          float temperature = sensors.getTempCByIndex(0);
          
            // Send in the new temperature
            send(temp.setSensor(1).set(temperature,1));
            // Save new temperatures for next compare
      
            batM();
            delay(500);
            sleep(3000);
          sleep(DIGITAL_INPUT_SENSOR,CHANGE,DOOR_PIN,CHANGE,SLEEP_TIME);
      }
      
      
      void batM() //The battery calculations
      {
         delay(500);
         // Battery monitoring reading
         int sensorValue = analogRead(BATTERY_SENSE_PIN);    
         delay(500);
         
         // Calculate the battery in %
         float Vbat  = sensorValue * VBAT_PER_BITS;
         int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
         Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
         
         // Add it to array so we get an average of 3 (3x20min)
         batArray[batLoop] = batteryPcnt;
        
         if (batLoop > 2) {  
           batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
           batteryPcnt = batteryPcnt / 3;
       
         if (batteryPcnt > 100) {
           batteryPcnt=100;
       }
       
           Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
             sendBatteryLevel(batteryPcnt);
             batLoop = 0;
            }
           else 
           {
           batLoop++;
           }
      }
       
      
      BearWithBeardB Offline
      BearWithBeardB Offline
      BearWithBeard
      wrote on last edited by
      #2

      @markjgabb said in fails to wake with 2 interupts:

      #define DIGITAL_INPUT_SENSOR 2
      #define DOOR_PIN  3
      
      void loop()
      {
          sleep(DIGITAL_INPUT_SENSOR,CHANGE,DOOR_PIN,CHANGE,SLEEP_TIME);
      }
      

      Use the function digitalPinToInterrupt(). It translates the pin number (2, 3) to the corresponding interrupt vector (0, 1).

      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE,
            digitalPinToInterrupt(DOOR_PIN), CHANGE,
            SLEEP_TIME);
      
      1 Reply Last reply
      2
      • mntlvrM Offline
        mntlvrM Offline
        mntlvr
        wrote on last edited by
        #3

        @markjgabb said in fails to wake with 2 interupts:

        pinMode(DOOR_PIN, INPUT);

        to be a true pull up your the code should read pinMode(DOOR_PIN, INPUT_PULLUP);

        1 Reply Last reply
        2
        • skywatchS Offline
          skywatchS Offline
          skywatch
          wrote on last edited by
          #4

          @markjgabb Two great bits of advice from @BearWithBeard and @mntlvr .

          Put them both in your code and you should be good to go!

          1 Reply Last reply
          0
          • markjgabbM Offline
            markjgabbM Offline
            markjgabb
            wrote on last edited by
            #5

            thanks guys, ill add it to my code tonight and see how it goes

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            17

            Online

            12.0k

            Users

            11.2k

            Topics

            113.4k

            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