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. Bug Reports
  3. RFM69 with Binary Switch example requires additional code

RFM69 with Binary Switch example requires additional code

Scheduled Pinned Locked Moved Bug Reports
2 Posts 2 Posters 3.4k Views 1 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.
  • CARSTENC Offline
    CARSTENC Offline
    CARSTEN
    wrote on last edited by
    #1

    Hi
    I finally managed to try out the MySensors v1.5 library. I mainly was looking for the support of the RFM69 radios because of their better range and low power consumption.
    The serial gateway worked like a charm out of the box. But then I struggled to get the binary switch example working. I mostly got an error 'Radio Init Fail'.
    Looking into the code I also struggled to see where the code says that this should work with an RFM69 radio, like it does in the Serial Gateway code in "MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);"
    So I eventually copied a whole bunch of lines from the Serial Gateway example and now it is working perfectly.

    I may have copied too many lines and perhaps there is a much smarterway of solving this but as a feedback of what I tried and what worked, herewith the code I eventually used in my Binary Switch node:
    /**

    • 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-2015 Sensnology AB
    • Full contributor list: https://github.com/mysensors/Arduino/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.

    • DESCRIPTION
    • Simple binary switch example
    • Connect button or door/window reed switch between
    • digitial I/O pin 3 (BUTTON_PIN below) and GND.
    • http://www.mysensors.org/build/binary
      */

    #include <MySigningNone.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySigningAtsha204Soft.h>
    #include <MySigningAtsha204.h>

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>

    #define CHILD_ID 3
    #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch

    MyTransportRFM69 transport;

    // Hardware profile
    MyHwATMega328 hw;

    // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
    // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
    #ifdef WITH_LEDS_BLINKING
    MySensor gw(transport, hw /, signer/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
    #else
    MySensor gw(transport, hw /, signer/);
    #endif

    Bounce debouncer = Bounce();
    int oldValue=-1;

    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);

    void setup()
    {
    gw.begin(NULL,3);

    // Setup the button
    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);

    // After setting up the button, setup debouncer
    debouncer.attach(BUTTON_PIN);
    debouncer.interval(5);

    // Register binary input sensor to gw (they will be created as child devices)
    // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
    // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
    gw.present(CHILD_ID, S_DOOR);
    }

    // Check if digital input has changed and send in new value
    void loop()
    {
    debouncer.update();
    // Get the update value
    int value = debouncer.read();

    if (value != oldValue) {
    // Send in the new value
    gw.send(msg.set(value==HIGH ? 1 : 0));
    oldValue = value;
    }
    }

    I hope this helps somebody and perhaps somebody wants to advise on how to do this much better.
    Anyhow, Big Thank You to the guys (@KOLAF,@YVEAUX, @HEK and a bunch of others) who made the effort to extend the library to RFM69. Much appreciated.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      muguran
      wrote on last edited by
      #2

      Excellent, it worked

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


      6

      Online

      11.7k

      Users

      11.2k

      Topics

      113.0k

      Posts


      Copyright 2019 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