RFM69HCW beginning of a newbie with ATMEGA328P



  • Re: [SOLVED] Newbie trying to get RFM69HCW working with ATMEGA328P

    Hi all,
    I continue this topic here to have more details on the beginning with MySensors

    • I have 2 moteino (clone) with RFM69HCW 868MHz and ATMEGA328p at 3.3v
    • both are connected to the pc with FTDIs on 2 USB sockets, and therefore 2 ARDUINO IDE windows open.
    • RFM69HCW connections are: SCK: 13, MISO: 12, MOSI: 11, CS: 10, IRQ: 2
    • 1 integrated blue led out of 9

    What I managed to do: use an example from the RFM69 library of lowPowerLab = the 2 modules communicate well.

    What I would like to do with MySensors:

    • correctly initialize my modules (I saw that there is an RFM69_new_driver): define the RFM69HCW, the pins, the frequency, the ATC mode ...
    • do a first sketch of "hello world!" that the Node transmits to the Gateway.

    I have read a lot of examples and it is very confusing for me because there are different ways to initialize the RFM69. Some are obsolete, others don't work, or are only made for HW. Anyway, can you help me create my first start-up sketch to get started on a solid foundation.


  • Hardware Contributor

    Hi,

    if you're new to mysensors and still don't have a network in prod, I would recommend to use the new driver.

    example for rfm69cw

    #define MY_RADIO_RFM69 
    #define MY_RFM69_NEW_DRIVER
    #define MY_RFM69_FREQUENCY			RFM69_868MHZ
     #define MY_SIGNAL_REPORT_ENABLED
    #define MY_RFM69_ATC_TARGET_RSSI_DBM (-85)
    //#define MY_RFM69_ENABLE_ENCRYPTION
    //#define MY_DEBUG_VERBOSE_RFM69
    //#define MY_RFM69_NETWORKID 110  
    #define MY_RFM69_IRQ_PIN 2
    #define MY_RFM69_CS_PIN 10
    

    for rfm69H, add this too

    #define MY_IS_RFM69HW
    

    https://www.mysensors.org/apidocs/MyConfig_8h.html

    you could also show your sketch, and logs so people can help you.



  • @scalz said in RFM69HCW beginning of a newbie with ATMEGA328P:

    you could also show your sketch, and logs so people can help you.

    Thank you for your help, precisely, I did not have a sketch to start which corresponds to my material which is however basic.
    yes for the "new driver". i test your example.



  • I come back here with good news 😆

    Here I succeeded in making communicate the Node and the Gateway.
    At first I did not have a Parent and I understood that this was because I had not given a hard NODE_ID.
    To remedy this I downloaded the excel: Windows GUI / Controller for MySensors which automatically assigns the NODE_lD

    So if I resume my start test installation:

    • a Node RFM69HCW + ATmega 328p with the following sketch:
    /*
      This is an example that demonstrates how to report the battery level for a sensor
      Instructions for measuring battery capacity on A0 are available here:
      http://www.mysensors.org/build/battery
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    //#define MY_DEBUG_VERBOSE_SIGNING
    
    // RFM config
    #define MY_RADIO_RFM69
    #define MY_RFM69_NEW_DRIVER
    #define MY_RFM69_FREQUENCY  RFM69_868MHZ
    #define MY_SIGNAL_REPORT_ENABLED
    #define MY_RFM69_ATC_TARGET_RSSI_DBM (-85)
    //#define MY_RFM69_ENABLE_ENCRYPTION
    //#define MY_DEBUG_VERBOSE_RFM69
    //#define MY_RFM69_NETWORKID 101
    #define MY_RFM69_IRQ_PIN 2
    #define MY_RFM69_CS_PIN 10
    #define MY_IS_RFM69HW
    
    //========== LED ==========
    //#define MY_DEFAULT_TX_LED_PIN  9  // the PCB, on board LED
    #define MY_DEFAULT_RX_LED_PIN  9  // Receive led pin
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    // Inverses the behavior of leds
    #define MY_WITH_LEDS_BLINKING_INVERSE
    
    //========== ANALOG INPUT ==========
    //#define  BATTERY_SENSE_PIN = 0;  // select the input pin for the battery sense point
    //int oldBatteryPcnt = 0;
    //========== DIGITAL INPUT ==========
    //#define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    //#define CHILD_ID 1   // Id of the sensor child
    
    //========== NODE ID ==========
    //#define MY_NODE_ID 1
    //#define MY_NODE_TYPE "NODE"
    
    #include <MySensors.h>
    
    // ID of the sensor child
    #define CHILD_ID_UPLINK_QUALITY (0)
    #define CHILD_ID_TX_LEVEL       (1)
    #define CHILD_ID_TX_PERCENT     (2)
    #define CHILD_ID_TX_RSSI        (3)
    #define CHILD_ID_RX_RSSI        (4)
    #define CHILD_ID_TX_SNR         (5)
    #define CHILD_ID_RX_SNR         (6)
    
    // Initialize general message
    //MyMessage msgUplinkQuality(CHILD_ID_UPLINK_QUALITY, V_CUSTOM);
    //MyMessage msgTxLevel(CHILD_ID_TX_LEVEL, V_CUSTOM);
    //MyMessage msgTxPercent(CHILD_ID_TX_PERCENT, V_CUSTOM);
    MyMessage msgTxRSSI(CHILD_ID_TX_RSSI, V_CUSTOM);
    //MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_CUSTOM);
    //MyMessage msgTxSNR(CHILD_ID_TX_SNR, V_CUSTOM);
    //MyMessage msgRxSNR(CHILD_ID_RX_SNR, V_CUSTOM);
    
    //===================================
    //=              SETUP              =
    //===================================
    void setup()
    {
    }//FIN du SETUP
    //==========================================
    //=              PRESENTATION              =
    //==========================================
    void presentation()
    {
      // Send the sketch version information to the gateway and controller
      sendSketchInfo("ATC_report", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      //present(CHILD_ID_UPLINK_QUALITY, S_CUSTOM, "UPLINK QUALITY RSSI");
      // present(CHILD_ID_TX_LEVEL, S_CUSTOM, "TX LEVEL DBM");
      //present(CHILD_ID_TX_PERCENT, S_CUSTOM, "TX LEVEL PERCENT");
      present(CHILD_ID_TX_RSSI, S_CUSTOM, "TX RSSI");
      // present(CHILD_ID_RX_RSSI, S_CUSTOM, "RX RSSI");
      // present(CHILD_ID_TX_SNR, S_CUSTOM, "TX SNR");
      // present(CHILD_ID_RX_SNR, S_CUSTOM, "RX SNR");
    }
    //===================================
    //=              LOOP               =
    //===================================
    void loop()
    {
      // send messages to GW
      //send(msgUplinkQuality.set(transportGetSignalReport(SR_UPLINK_QUALITY)));
      //send(msgTxLevel.set(transportGetSignalReport(SR_TX_POWER_LEVEL)));
      //send(msgTxPercent.set(transportGetSignalReport(SR_TX_POWER_PERCENT)));
      send(msgTxRSSI.set(transportGetSignalReport(SR_TX_RSSI)));
    
      // retrieve RSSI / SNR reports from incoming ACK
      //  send(msgRxRSSI.set(transportGetSignalReport(SR_RX_RSSI)));
      //  send(msgTxSNR.set(transportGetSignalReport(SR_TX_SNR)));
      //  send(msgRxSNR.set(transportGetSignalReport(SR_RX_SNR)));
      // wait a bit
      wait(10000);
    }// FIN de LOOP
    ///*
    void receive(const MyMessage &message) {
      Serial.print("Message recu pour le capteur :");
      Serial.print(message.sensor);
      Serial.print(", Nouveau statut : ");
      Serial.println(message.getBool());
    }
    //*/
    
    • a Gateway RFM69HCW + ATmega 328p with the following sketch, connected to the PC win10 on a USB socket (thanks to an FTDI) :
    /*
      DESCRIPTION
      The ArduinoGateway prints data received from sensors on the serial link.
      The gateway accepts input on serial which will be sent out on radio network.
    
      The GW code is designed for Arduino Nano 328p / 16MHz
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    //#define MY_DEBUG_VERBOSE_SIGNING
    
    // RFM config
    #define MY_RADIO_RFM69 
    #define MY_RFM69_NEW_DRIVER
    #define MY_RFM69_FREQUENCY      RFM69_868MHZ
    #define MY_SIGNAL_REPORT_ENABLED
    //#define MY_RFM69_ATC_TARGET_RSSI_DBM (-85)
    //#define MY_RFM69_ENABLE_ENCRYPTION
    //#define MY_DEBUG_VERBOSE_RFM69
    //#define MY_RFM69_NETWORKID 101
    #define MY_RFM69_IRQ_PIN 2
    #define MY_RFM69_CS_PIN 10
    #define MY_IS_RFM69HW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    /*
      // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
      #if F_CPU == 8000000L
      #define MY_BAUD_RATE 38400
      #endif
    
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
    
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    */
    //========== LED ==========
    //#define MY_DEFAULT_TX_LED_PIN  9  // the PCB, on board LED
    #define MY_DEFAULT_RX_LED_PIN  9  // Receive led pin
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    // Inverses the behavior of leds
    #define MY_WITH_LEDS_BLINKING_INVERSE
    
    #include <MySensors.h>
    //===================================
    //=              SETUP              =
    //===================================
    void setup()
    {
      // Setup locally attached sensors
    }
    //==========================================
    //=              PRESENTATION              =
    //==========================================
    void presentation()
    {
      // Present locally attached sensors
    }
    //===================================
    //=              LOOP               =
    //===================================
    void loop()
    {
      // Send locally attached sensor data here
    }
    
    • On the PC the execution of the Controller program: Windows GUI / Controller for MySensors.
      Which give :
      6b45fd87-9d2b-4208-8d05-96cc591f18e2-image.png
      We can see in sky blue, the sending of the state of a virtual "Motion" sensor from the Gateway to the Node (adjustable at the bottom of the interface).
      The other V_CUSTOMs are the RSSI of the RFM69 transmition stage.
      Oddity: after receiving the state of the Motion sensor, sent by the Gateway, the Node transmits a value of 127 ??

    Everything works, out of the box, you just had to know how to start with the configuration of the RFM69HCW, thank you @scalz

    The second step is to replace the Win10 Controller with a Node-Red Controller.
    I already have a Node-Red server with its Dashboard running on an RPI 3B.
    I found "node-red-contrib-mysensors" but it still seems blurry to me (sorry I learn fast but you have to explain myself a long time) 😋

    I think I'll open another Topic or continue on the original node-red-contrib-mysensors, Topic.


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 2
  • 5
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts