Help troubleshoting sketch



  • I am trying to use this sketch with an RFM69H Radio. It complies and uploads but the radio does not work.

    I can't use the serial monitor as it is an 1Mhz Optiboot firmware.

    // EgSlimReed2
    // By m26872, 2015-12-22
    // Interrupt driven binary switch for Slim Node with Reed switch and external pull-up (10Mohm)
    // Inspired by mysensors example:
    // https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Vcc.h>
    #include <MyTransportRFM69.h>
    
    #define NODE_ID 5 //12 var senaste "reed-node"-id // 110    // Use static Node_ID  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    #define SKETCH_NAME "Testing"
    #define SKETCH_VERSION "2.0 2015-12-22"
    #define SW_CHILD_ID 5
    #define SW_PIN 3
    #define BATTERY_REPORT_DAY 2   // Desired heartbeat interval when inactive. Maximum heartbeat/report interval is equal to this due to the dayCounter.
    #define BATTERY_REPORT_BY_IRT_CYCLE 10  // Adjust this according to usage frequency.
    #define ONE_DAY_SLEEP_TIME 86400000
    #define VCC_MIN 1.9
    #define VCC_MAX 3.3
    
    int dayCounter = 0;
    int irtCounter = 0;
    uint8_t value;
    uint8_t sentValue=2;
    bool interruptReturn=false;
    
    MyTransportRFM69 transport;
    //MySensor gw(transport, hw, signer);
    //MyTransportRFM69 transport (RFM69_FREQUENCY, RFM69_NETWORKID, RF69_SPI_CS, RF69_IRQ_PIN, false, RF69_IRQ_NUM) ; 
    Vcc vcc;
    MySensor gw(transport);
    MyMessage msg(SW_CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      delay(100); // to settle power for radio
      gw.begin(NULL,NODE_ID);
      pinMode(SW_PIN, INPUT);
      digitalWrite(SW_PIN, LOW);    // Disable internal pull-ups
      gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      gw.present(SW_CHILD_ID, S_DOOR);  
    }
    
    void loop() 
    {
      if (!interruptReturn) { // Woke up by timer (or first run)
        dayCounter++; 
        if (dayCounter >= BATTERY_REPORT_DAY) {
              dayCounter = 0;
              sendBatteryReport();
        }
      }
      else {    // Woke up by pin change
          irtCounter++;
          gw.sleep(50);       // Short delay to allow switch to properly settle
          value = digitalRead(SW_PIN);
          if (value != sentValue) {
             gw.send(msg.set(value==HIGH ? 1 : 0));
             sentValue = value;
          }
          if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
            irtCounter=0;
            sendBatteryReport();
          }
      }
    
      // Sleep until something happens with the sensor,   or one sleep_time has passed since last awake.
      interruptReturn = gw.sleep(SW_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
    
    } 
    
    void sendBatteryReport() {
              float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
              int batteryPcnt = static_cast<int>(p);
              gw.sendBatteryLevel(batteryPcnt);
    }
    

  • Mod

    Why do you think that the radio does not work?



  • I tried the sketch with nrf radio and it worked perfectly in domoticz. But with this sketch and rfm69 radio I get nothing in the domoticz log when powering up.


  • Mod

    Do you know that your RFM69 gateway works?



  • Yes I have tried adding a sensor using the dev-branch and the # define My_Radio_RFM69 option



  • Hmm... just cracking a guess here, but maybe it's the 1MHz of the oscillator? Can you use a 8MHz bootloader and see if it makes a difference?


  • Hardware Contributor

    @Cliff-Karlsson said:

    I can't use the serial monitor as it is an 1Mhz Optiboot firmware.

    Why can´t you debug?

    Just make sure to add:

    • Serial.begin(9600); in setup()
    • Change to baudrate 9600 in MyConfig.h
    • Set 9600 in your Serial Monitor


  • @Cliff-Karlsson you can check on the gateway serial output



  • Ok, I added the info from @m26872 and when I start serial monitor I only get this: "find parent"

    the sketch I am using is:

    // EgSlimReed2
    // By m26872, 2015-12-22
    // Interrupt driven binary switch for Slim Node with Reed switch and external pull-up (10Mohm)
    // Inspired by mysensors example:
    // https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Vcc.h>
    #include <MyTransportRFM69.h>
    
    #define NODE_ID 5 //12 var senaste "reed-node"-id // 110    // Use static Node_ID  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    #define SKETCH_NAME "Testing"
    #define SKETCH_VERSION "2.0 2015-12-22"
    #define SW_CHILD_ID 5
    #define SW_PIN 3
    #define BATTERY_REPORT_DAY 2   // Desired heartbeat interval when inactive. Maximum heartbeat/report interval is equal to this due to the dayCounter.
    #define BATTERY_REPORT_BY_IRT_CYCLE 10  // Adjust this according to usage frequency.
    #define ONE_DAY_SLEEP_TIME 86400000
    #define VCC_MIN 1.9
    #define VCC_MAX 3.3
    
    int dayCounter = 0;
    int irtCounter = 0;
    uint8_t value;
    uint8_t sentValue=2;
    bool interruptReturn=false;
    
    MyTransportRFM69 transport;
    //MySensor gw(transport, hw, signer);
    //MyTransportRFM69 transport (RFM69_FREQUENCY, RFM69_NETWORKID, RF69_SPI_CS, RF69_IRQ_PIN, false, RF69_IRQ_NUM) ; 
    Vcc vcc;
    MySensor gw(transport);
    MyMessage msg(SW_CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      Serial.begin(9600);
      delay(100); // to settle power for radio
      gw.begin(NULL,NODE_ID);
      pinMode(SW_PIN, INPUT);
      digitalWrite(SW_PIN, LOW);    // Disable internal pull-ups
      gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      gw.present(SW_CHILD_ID, S_DOOR);  
    }
    
    void loop() 
    {
      if (!interruptReturn) { // Woke up by timer (or first run)
        dayCounter++; 
        if (dayCounter >= BATTERY_REPORT_DAY) {
              dayCounter = 0;
              sendBatteryReport();
        }
      }
      else {    // Woke up by pin change
          irtCounter++;
          gw.sleep(50);       // Short delay to allow switch to properly settle
          value = digitalRead(SW_PIN);
          if (value != sentValue) {
             gw.send(msg.set(value==HIGH ? 1 : 0));
             sentValue = value;
          }
          if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
            irtCounter=0;
            sendBatteryReport();
          }
      }
    
      // Sleep until something happens with the sensor,   or one sleep_time has passed since last awake.
      interruptReturn = gw.sleep(SW_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
    
    } 
    
    void sendBatteryReport() {
              float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
              int batteryPcnt = static_cast<int>(p);
              gw.sendBatteryLevel(batteryPcnt);
    }
    

  • Hardware Contributor

    @Cliff-Karlsson Also enable debug in MyConfig.h



  • I think it is enabled by default.

    This is the first lines in MyConfig.h

    #ifndef MyConfig_h
    #define MyConfig_h
    #include <stdint.h>
    
    // Enable debug flag for debug prints. This will add a lot to the size of the final sketch but good
    // to see what is actually is happening when developing
    #define DEBUG
    
    // Disable this line, If you are using TX(1), RX(0) as normal I/O pin
    #define ENABLED_SERIAL
    
    // Serial output baud rate (for debug prints and serial gateway)
    #define BAUD_RATE 9600
    
    


  • I tried the lightluxsensor sketch from the dev 2.0 branch and now I get this from the serial monitor:

    Starting sensor (RRNNA-, 2.0.0-beta)
    Radio init successful.
    find parent
    


  • Hmm... sorry for spamming, I don't know exactly what I did but I tried another sketch from the dev-branch and now it works.

    Can it be that the RFM69 gateway is using 2.0-beta and the original sketch is 1.5 ?

    Is it difficult to convert the original sketch to 2.0 ?

    I tried to modify it like this but it did not work either:

    
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define MY_BAUD_RATE 9600
    #include <Vcc.h>
    #include <SPI.h>
    #include <MySensor.h>
    #define NODE_ID 5 //12 var senaste "reed-node"-id // 110    // Use static Node_ID  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    #define SKETCH_NAME "Optiboot"
    #define SKETCH_VERSION "2.0 2015-12-22"
    #define SW_CHILD_ID 5
    #define SW_PIN 3
    #define BATTERY_REPORT_DAY 2   // Desired heartbeat interval when inactive. Maximum heartbeat/report interval is equal to this due to the dayCounter.
    #define BATTERY_REPORT_BY_IRT_CYCLE 10  // Adjust this according to usage frequency.
    #define ONE_DAY_SLEEP_TIME 86400000
    #define VCC_MIN 1.9
    #define VCC_MAX 3.3
    
    int dayCounter = 0;
    int irtCounter = 0;
    uint8_t value;
    uint8_t sentValue=2;
    bool interruptReturn=false;
    
    
    Vcc vcc;
    
    MyMessage msg(SW_CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      delay(100); // to settle power for radio
      //begin(NULL,NODE_ID);
      pinMode(SW_PIN, INPUT);
      digitalWrite(SW_PIN, LOW);    // Disable internal pull-ups
    }
    
    void presentation() {
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      present(SW_CHILD_ID, S_DOOR);   
    }
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop() 
    {
      if (!interruptReturn) { // Woke up by timer (or first run)
        dayCounter++; 
        if (dayCounter >= BATTERY_REPORT_DAY) {
              dayCounter = 0;
              sendBatteryReport();
        }
      }
      else {    // Woke up by pin change
          irtCounter++;
          sleep(50);       // Short delay to allow switch to properly settle
          value = digitalRead(SW_PIN);
          if (value != sentValue) {
             send(msg.set(value==HIGH ? 1 : 0));
             sentValue = value;
          }
          if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
            irtCounter=0;
            sendBatteryReport();
          }
      }
    
    
      // Sleep until something happens with the sensor
       interruptReturn = sleep(SW_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
    }
    void sendBatteryReport() {
              float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
              int batteryPcnt = static_cast<int>(p);
              sendBatteryLevel(batteryPcnt);
    }
    

  • Plugin Developer

    @Cliff-Karlsson

    I'm not sure exactly what you have done so far. Were you trying an old sketch with the dev branch library? If you update your library to dev branch you can't compile sketches from previous mysensors releases without updating them to the dev style.

    As far as I know one mysensored arduino gateway with dev branch should be able to talk to one mysensored arduino node with 1.5 release.

    If you're using the dev branch, why not start with one of the sketches from the dev branch examples, that should be working, and take it from there. First try it without changing anything. Then modify them one step at a time. Less chance of errors that way, until you feel more confident.



  • I have multiple arduino IDE installs witch use different versions of mysensors. As could not get the RFM69 radio to work using the 1.5 version I tried to adopt the sketch to 2.0 where it is simple to get the radio to work with just "#define MY_RADIO_RFM69"

    But I am not very good at the programing bit so I cant get the original sketch to work with 2.0. I must admit I don't really know what the major different parts between 1.5 and 2.0 is but I removed all gw.send, gw.sleep etc and replaced it with just send, sleep etc.

    There might be multiple errors in my converted sketch but the part where I am pretty sure there is some error in is:

    void setup()  
    {  
      delay(100); // to settle power for radio
      //begin(NULL,NODE_ID);
      pinMode(SW_PIN, INPUT);
      digitalWrite(SW_PIN, LOW);    // Disable internal pull-ups
    }
    

  • Plugin Developer

    @Cliff-Karlsson

    What error or problem are you getting? Does nothing happen after find parent?

    The only thing I can see that could be wrong with your converted sketch is that you don't define the node id using MY_NODE_ID, but NODE_ID. Fix that and try again.

    Here are the instructions for converting a sketch from 1.5 to dev version:

    //Converting sketch from 1.5 to to 2.0
    
    //Add the following to activate NRF-radio support
    #define MY_RADIO_NRF24
    
    //Remove MySensor constructor 
    MySensors gw; 
    
    //Remove MySensors setup() call 
    gw.setup(....);
    
    //If node expects incoming messages, add the following function to handle data:
    void receive(const MyMessage &msg) {}
    
    //Move present() and sendSketchInfo() from setup() to a new function called presentation().
    void presentation() {
         sendSketchInfo(...)	
         present(...);
    }
    
    //If you’re using static ids , add:
    #define MY_NODE_ID xx
    
    //If static parent node is used, add:
    #define MY_PARENT_NODE_ID xx
    
    //If you want node to be a repeater, add
    #define MY_REPEATER_FEATURE
    
    //Remove all “gw.” before MySensors library calls.
    
    //If node requests time using requestTime(), remove callback argument define define the following function to handle time response:
    void receiveTime(unsigned long ts) {
    }
    
    //Make sure to include MySensor.h after any configuration defines. 
    


  • I have tried to modify again but still can't get it to work.

    This is the original sketch:

    // EgSlimReed2
    // By m26872, 2015-12-22
    // Interrupt driven binary switch for Slim Node with Reed switch and external pull-up (10Mohm)
    // Inspired by mysensors example:
    // https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Vcc.h>
    
    #define NODE_ID 5 //12 var senaste "reed-node"-id // 110    // Use static Node_ID  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    #define SKETCH_NAME "EgSlimReed"
    #define SKETCH_VERSION "2.0 2015-12-22"
    #define SW_CHILD_ID 5
    #define SW_PIN 3
    #define BATTERY_REPORT_DAY 2   // Desired heartbeat interval when inactive. Maximum heartbeat/report interval is equal to this due to the dayCounter.
    #define BATTERY_REPORT_BY_IRT_CYCLE 10  // Adjust this according to usage frequency.
    #define ONE_DAY_SLEEP_TIME 86400000
    #define VCC_MIN 1.9
    #define VCC_MAX 3.3
    
    int dayCounter = 0;
    int irtCounter = 0;
    uint8_t value;
    uint8_t sentValue=2;
    bool interruptReturn=false;
     
    Vcc vcc;
    MySensor gw;
    MyMessage msg(SW_CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      delay(100); // to settle power for radio
      gw.begin(NULL,NODE_ID);
      pinMode(SW_PIN, INPUT);
      digitalWrite(SW_PIN, LOW);    // Disable internal pull-ups
      gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      gw.present(SW_CHILD_ID, S_DOOR);  
    }
    
    void loop() 
    {
      if (!interruptReturn) { // Woke up by timer (or first run)
        dayCounter++; 
        if (dayCounter >= BATTERY_REPORT_DAY) {
              dayCounter = 0;
              sendBatteryReport();
        }
      }
      else {    // Woke up by pin change
          irtCounter++;
          gw.sleep(50);       // Short delay to allow switch to properly settle
          value = digitalRead(SW_PIN);
          if (value != sentValue) {
             gw.send(msg.set(value==HIGH ? 1 : 0));
             sentValue = value;
          }
          if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
            irtCounter=0;
            sendBatteryReport();
          }
      }
    
      // Sleep until something happens with the sensor,   or one sleep_time has passed since last awake.
      interruptReturn = gw.sleep(SW_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
    
    } 
    
    void sendBatteryReport() {
              float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
              int batteryPcnt = static_cast<int>(p);
              gw.sendBatteryLevel(batteryPcnt);
    }
    

    and this is my latest try:

    #include <SPI.h>
    #include <Vcc.h>
    
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define MY_BAUD_RATE 9600
    #define MY_NODE_ID 5
    #define NODE_ID 5 //12 var senaste "reed-node"-id // 110    // Use static Node_ID  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    #define SW_CHILD_ID 5
    #define SW_PIN 3
    #define BATTERY_REPORT_DAY 2   // Desired heartbeat interval when inactive. Maximum heartbeat/report interval is equal to this due to the dayCounter.
    #define BATTERY_REPORT_BY_IRT_CYCLE 10  // Adjust this according to usage frequency.
    #define ONE_DAY_SLEEP_TIME 86400000
    #define VCC_MIN 1.9
    #define VCC_MAX 3.3
    #include <MySensor.h>
    int dayCounter = 0;
    int irtCounter = 0;
    uint8_t value;
    uint8_t sentValue=2;
    bool interruptReturn=false;
    
    
    Vcc vcc;
    
    MyMessage msg(SW_CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      delay(100); // to settle power for radio
      pinMode(SW_PIN, INPUT);
      digitalWrite(SW_PIN, LOW);    // Disable internal pull-ups
      
    }
    
    void presentation()
    {
      sendSketchInfo("Plutt", "666");
      present(SW_CHILD_ID, S_DOOR);  
    }
    
    
    void loop() 
    {
      if (!interruptReturn) { // Woke up by timer (or first run)
        dayCounter++; 
        if (dayCounter >= BATTERY_REPORT_DAY) {
              dayCounter = 0;
              sendBatteryReport();
        }
      }
      else {    // Woke up by pin change
          irtCounter++;
          sleep(50);       // Short delay to allow switch to properly settle
          value = digitalRead(SW_PIN);
          if (value != sentValue) {
             send(msg.set(value==HIGH ? 1 : 0));
             sentValue = value;
          }
          if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
            irtCounter=0;
            sendBatteryReport();
          }
      }
    
      // Sleep until something happens with the sensor,   or one sleep_time has passed since last awake.
      interruptReturn = sleep(SW_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
    
    } 
    
    void sendBatteryReport() {
              float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
              int batteryPcnt = static_cast<int>(p);
              sendBatteryLevel(batteryPcnt);
    }
    

    But this is all I get in the serial monitor:

    Starting sensor (RRNNA-, 2.0.0-beta)
    Radio init successful.
    

  • Plugin Developer

    @Cliff-Karlsson

    I would first test the standard binary switch example sketch from github:
    https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino

    If that works, you know that your hardware is ok. Then you should be able to adjust that sketch slightly to get the extra functionality you need.



  • Hmm I tried the sketch. It works when using NRF radio, when I change to RFM69 radio it does not work.
    I tried connection the same RFM69 radio to a 3.3v mini pro and then it works.

    I am using this RFM69breakout on all my boards with only the RFM69 radio and pin headers soldered. Is there something funky about the breakoutboard? I con't understand why if that is as all other boards work using the same breakout,

    This is the result when trying the sketch with RFM69

    Starting sensor (RRNNA-, 2.0.0-beta)
    Radio init successful.
    send: 99-99-0-0 s=255,c=3,t=15,pt=0,l=2,sg=0,st=fail:
    send: 99-99-0-0 s=255,c=0,t=17,pt=0,l=10,sg=0,st=fail:2.0.0-beta
    send: 99-99-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
    send: 99-99-0-0 s=255,c=3,t=11,pt=0,l=13,sg=0,st=fail:Binary Sensor
    send: 99-99-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
    send: 99-99-0-0 s=3,c=0,t=0,pt=0,l=0,sg=0,st=fail:
    find parent
    send: 99-99-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    send: 99-99-0-0 s=4,c=0,t=0,pt=0,l=0,sg=0,st=fail:
    Init complete, id=99, parent=0, distance=255
    send: 99-99-0-0 s=3,c=1,t=16,pt=2,l=2,sg=0,st=fail:1
    send: 99-99-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,st=fail:1```

Log in to reply
 

Suggested Topics

12
Online

11.4k
Users

11.1k
Topics

112.7k
Posts