conecting the radio module on a MEGA 2560 ?? !!



  • i have a problem to make a radio NRF24L01 working on a MEGA 2560 to create a sensor node

    i am using the standard mysensor connection (its working for me on a nano)
    but when i use the same connection on the mega it is not working at all
    i select the good board type before uploading .....

    serial is giving me this message :

    Starting repeater (RNNRA-, 2.0.0)
    TSM:INIT
    !TSM:RADIO:FAIL
    !TSM:FAILURE
    TSM:PDT

    the radio moduleis working correctly on an other node.....

    is there anithing i dont know to use a MEGA....
    is the connection the same than on a nano

    PS sorry for my bad english


  • Mod

    @samdel the mega uses different pins. follow the instructions for mega linked from https://www.mysensors.org/build/connect_radio



  • You have to use the correct pins for MISO,MOSI,SS,SCK and Pin 2 for the interrupt. You can get them here:
    https://lynx2015.files.wordpress.com/2015/08/arduino-mega-pinout-diagram.png
    You also have to modify the Arduino Mysensors in Library, inside Drivers/RFM69/RFM69.h you must specify interrupt number 4 for the mega 2560 (it's 0 for the 328).

    #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
      #define RF69_IRQ_PIN          2
      #define RF69_IRQ_NUM          0
    #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
      #define RF69_IRQ_PIN          2
      #define RF69_IRQ_NUM          2
    #elif defined(__AVR_ATmega32U4__)
      #define RF69_IRQ_PIN          3
      #define RF69_IRQ_NUM          0
    #elif defined(__arm__)//Use pin 10 or any pin you want
      #define RF69_IRQ_PIN          10
      #define RF69_IRQ_NUM          10
    #else 
    #define RF69_IRQ_PIN          2 
    #define RF69_IRQ_NUM          4
    #endif
    

    PS. I've tried using the #define MY_RF69_IRQ_NUM inside the main sketch but I couldn't get it to work.



  • i used Mfalkvidd advices ......
    its working better but stil not recognised from the gateway

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT


  • Mod

    @executivul The OP is using an nrf24 radio, not rfm69. Let's not give him wrong advise 😉


  • Mod

    @samdel great work. Could you post the log from the gateway?



  • 0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0)
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    0;255;3;0;9;TSM:READY
    IP: 192.168.1.19
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    0;255;3;0;9;TSP:MSG:READ 1-1-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=1)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-1-1 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
    0;255;3;0;9;TSP:MSG:READ 14-14-255 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:READ 0-14-255 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
    0;255;3;0;9;TSP:MSG:READ 14-14-255 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:READ 0-14-255 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:READ 1-1-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=1)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-1-1 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=255)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;TSP:MSG:SEND 0-0-255-255 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=bc:0
    0;255;3;0;9;TSP:MSG:READ 14-14-255 s=255,c=3,t=8,pt=1,l=1,sg=0:1
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:READ 0-14-255 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:READ 1-1-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=1)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-1-1 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC



  • befor was the serial monitor of the gateway and below is the sketch i an using in the mega :

    // Enable debug prints to serial monitor
    #define MY_DEBUG

    // Enable and select radio type attached
    #define MY_RADIO_NRF24

    #define SN "RelayButtonArray"
    #define SV "1.0"

    // Pin Confuguration for Arduino Mega
    #define MY_RF24_CE_PIN 40
    #define MY_RF24_CS_PIN 53
    #include <MySensors.h>
    #include <SPI.h>
    #include <Bounce2.h>
    #define RELAY_ON 0 // switch around for ACTIVE LOW / ACTIVE HIGH relay
    #define RELAY_OFF 1
    //

    #define noRelays 8 //2-4
    const int relayPin[] = {2, 4, 6, 8, 10, 12, 14, 16}; // switch around pins to your desire
    const int buttonPin[] = {3, 5, 7, 9, 11, 13, 15, 17}; // switch around pins to your desire

    class Relay // relay class, store all relevant data (equivalent to struct)
    {
    public:
    int buttonPin; // physical pin number of button
    int relayPin; // physical pin number of relay
    boolean relayState; // relay status (also stored in EEPROM)
    };

    Relay Relays[noRelays];
    Bounce debouncer[noRelays];
    MyMessage msg[noRelays];

    /*
    void before() {
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
    }
    }*/

    void setup() {
    wait(100);
    // Initialize Relays with corresponding buttons
    for (int i = 0; i < noRelays; i++) {
    Relays[i].buttonPin = buttonPin[i]; // assign physical pins
    Relays[i].relayPin = relayPin[i];
    msg[i].sensor = i; // initialize messages
    msg[i].type = V_LIGHT;
    pinMode(Relays[i].buttonPin, INPUT_PULLUP);
    wait(100);
    pinMode(Relays[i].relayPin, OUTPUT);
    Relays[i].relayState = loadState(i); // retrieve last values from EEPROM
    digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
    send(msg[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status
    wait(50);
    debouncer[i] = Bounce(); // initialize debouncer
    debouncer[i].attach(buttonPin[i]);
    debouncer[i].interval(30);
    wait(50);
    }
    }

    void presentation()
    {
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo(SN, SV);

    wait(100);

    for (int i = 0; i < noRelays; i++)
    present(i, S_LIGHT); // present sensor to gateway

    wait(100);
    }

    void loop()
    {
    for (byte i = 0; i < noRelays; i++) {
    if (debouncer[i].update()) {

      int value = debouncer[i].read();
      
      if ( value == LOW) {
        Relays[i].relayState = !Relays[i].relayState;
        digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);
        send(msg[i].set(Relays[i].relayState ? true : false));
        // save sensor state in EEPROM (location == sensor number)
        saveState( i, Relays[i].relayState );
    
      }
    
    }
    

    }
    //wait(20);
    }

    void receive(const MyMessage &message) {
    if (message.type == V_LIGHT) {
    if (message.sensor < noRelays) { // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]]
    Relays[message.sensor].relayState = message.getBool();
    digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
    saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
    }
    }
    wait(20);
    }


  • Mod

    @samdel the gateway receives the request for parens and replies, but the sensor does not "hear" the reply.

    See https://forum.mysensors.org/topic/666/debug-faq-and-how-ask-for-help for information on how to troubleshoot range and power issues.



  • i double (triple) checked connections all ok
    i checkes power suplies ; all ok
    i have condansators installed on each nrf24
    and i am testing it on my desk so no long distance to travel...
    ......

    i tried to assigne a node id ;

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=44)
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=44)
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 44-44-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT

    gateway ;
    0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0)
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    0;255;3;0;9;TSM:READY
    IP: 192.168.1.19
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    0;255;3;0;9;TSP:MSG:READ 1-1-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=1)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-1-1 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 44-44-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=44)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-44-44 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 61-61-0 s=1,c=1,t=0,pt=7,l=5,sg=0:20.9
    0;255;3;0;9;TSP:MSG:READ 61-61-0 s=0,c=1,t=1,pt=7,l=5,sg=0:33.3
    0;255;3;0;9;TSP:MSG:READ 44-44-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=44)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK


  • Mod

    @samdel does it start working if you move the sensor and the gateway further apart? There have been several cases where people have had trouble when the nodes are too close.


  • Admin

    The 3v3 line on mega was super noisy when I used it. I had to put a step down from the 5V rail.



  • 2 metres away stillthe same result

    i also tried to load an other sketch asthe one i was using was tuned by me....
    still the same

    i finaly tried using an other arduinoboard (original one) and it is working good......

    the one who was not working correctly was this one ;
    https://www.amazon.fr/gp/product/B00OPO44UE/ref=ox_sc_act_title_32?ie=UTF8&psc=1&smid=A21548PJTFXT87

    di i have to put it to trash or is there a way to test it or to make it working ???



  • hi Hek

    how do you measur the noisyness?? with a fluck in AC ?? what are the limits .?


  • Admin

    @samdel said:

    how do you measur the noisyness

    Empirically, I just couldn't get it working.


 

407
Online

7.9k
Users

8.8k
Topics

93.8k
Posts