Template sketch for flexible use with many different sensor types



  • I've created a companion Arduino sketch / library to go along with the MySensors library. The companion library is designed with flexibility and inheritance to allow easy configuration of attached sensors and actuators. I.e. just tell the library you want to add a gpio output, an analog input, a PWM output, ... and the library handles all the necessary code. This makes the base Arduino sketch much simpler and allows for easier configuration and programming of modules with different and varying features.

    I'm midway through development and have some more features to add, but I wanted to solicit some feedback to see if there were general ideas or concepts that I am missing. Note: I'm not a professional programmer and am learning some of this as I go!

    The software is specifically designed for (and only tested with) the Home Assistant controller - though I hope other controller software is compatible.

    Github here: https://github.com/brahmafear/MySensors_Node. Best starting point is the Arduino sketch listed in the examples folder.

    Cheers.



  • @Dave-Myers said:

    Oops - forgot to add: for MySensors 2.x only.



  • @Dave-Myers

    Example of a full Arduino sketch with 4 sensors/actuators using this library:

    #define MY_RADIO_NRF24
    
    #include <SPI.h>
    #include <MySensors.h>
    #include "MySensors_Node.h"
      
    MySensors_Node node("Sample", "0.01");
    
    void presentation() {
    
      MySensors_Node_Sensor_Gpio_Out nsgo( 11, "Simple LED 1", 5, true );
      node.add_sensor( &nsgo );
    
      node.add_sensor(  new MySensors_Node_Sensor_Gpio_In( 13, "Simple Motion", 2, true, INPUT_PULLUP, 500 ) );
      node.add_sensor(  new MySensors_Node_Sensor_Analog_In( 14, "Analog In", A0, true, 1024, 10000 ) );
      node.add_sensor(  new MySensors_Node_Sensor_Pwm( 15, "PWM LED", 6, true, true, 255 ) );
    
      node.present();
    }
    
    void receive( const MyMessage &msg ) {
      node.receive( msg );
    }
    
    
    void setup() {
      node.setup();
    }
    
    void loop() {
      node.loop();
    }
    


  • @Dave-Myers this is asoweme will try in this days but sound amazing thanks for sharing.


  • Admin

    Looks great @Dave-Myers!

    This is an very nice start of the "Helper Classes" I was thinking of back in the old architecture document.



  • @hek

    Nice. Hadn't seen that doc before. Please let me know if there are any changes you suggest.



  • Have a look at https://github.com/mysensors/NodeManager/

    (I think this only became available since the last reply in this thread).


Log in to reply
 

Suggested Topics

  • 1
  • 10
  • 5
  • 6
  • 3
  • 1

12
Online

11.4k
Users

11.1k
Topics

112.7k
Posts