Need help with ethernet/RFM95 gateway



  • I am building 3 ethernet/MQTT gateways, one for NRF24, one for RFM69HCW and one for RFM95W.
    For ethernet, I use the HanRun W5500 Lite modules (https://nl.aliexpress.com/item/32598945210.html?spm=a2g0s.9042311.0.0.27424c4d7XOuUi)
    For the processor I use Arduino Pro Mini 8MHz, 3.3V.
    I designed 2 small PCB's to build these gateways, one for the NRF24 module and one for the RFM modules since they have the same pinout.
    I use hardware SPI for all interfaces; connections are as follows...
    W5500:

    W5500 SCK  - Arduino SCK
    W5500 MISO - Arduino MISO
    W5500 MOSI - Arduino MOSI
    W5500 SS   - Arduino SS
    

    RFM69/95 gateway:

    RFM69/95 SCK  - Arduino SCK
    RFM69/95 MISO - Arduino MISO
    RFM69/95 MOSI - Arduino MOSI
    RFM69/95 NSS  - Arduino D6
    RFM69/95 DIO0 - Arduino D2
    

    NRF24 gateway:

    NRF24 SCK  - Arduino SCK
    NRF24 MISO - Arduino MISO
    NRF24 MOSI - Arduino MOSI
    NRF24 CSN  - Arduino D6
    NRF24 CE   - Arduino D5
    

    The NRF24 gateway and the RFM69 gateway are working fine, but I cannot get the RFM95 gateway working. If I plug in the RFM95 module, the ethernet module will not work anymore. The RFM95 gateway initcode runs ok but the ethernet code will abort with a timeout.
    If I unplug the RFM95 module, the W5500 runs fine (tested with simple ethernet client sketch).
    If the RFM95 is in the circuit (with NSS line forced to low) the W5500 will not work anymore.
    If I replace the RFM95 with a RFM69, everything is ok again.

    This is my gateway sketch:

    #define MY_DEBUG
    #define MY_BAUD_RATE 9600
    
    #define MY_RADIO_RFM95
    #define MY_RFM95_FREQUENCY        RFM95_868MHZ
    #define MY_RFM95_CS_PIN           6
    #define MY_DEBUG_VERBOSE_RFM95
    
    #define MY_GATEWAY_MQTT_CLIENT
    
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway3-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway3-in"
    #define MY_MQTT_CLIENT_ID "mysensors-3"
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03
    
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 90
    #define MY_PORT 1883
    
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    #define MY_WITH_LEDS_BLINKING_INVERSE
    #define MY_DEFAULT_RX_LED_PIN   7
    #define MY_DEFAULT_TX_LED_PIN   8
    #define MY_DEFAULT_ERR_LED_PIN  9
    
    #include <Ethernet.h>
    #include <MySensors.h>
    
    void setup() {}
    void presentation() {}
    void loop() {}
    

    Am I doing something wrong? I thought the RFM69 and RFM95 are pin compatible, but they are not?
    I cannot find any significant difference in the datasheets.
    Has someone else managed to get a ethernet/RFM95 gateway working?


  • Mod

    @willemx you likely need to set the cs lines to output high for both the w5500 and the radio before the mysensors stack initializes.
    If you leave the cs lines floating both spi devices might be active at the same time.

    Mysensors adds the before() function for this, which you need to implement and set the cs lines high, just like you would in e.g. setup().



  • Hi @Yveaux, thanks for stepping in. I added the before() function, but no change.
    I had tried two RFM95 modules which both failed. Then I tried a third RFM95 module, but this failed in a different way: it did initialise, but then it reset itself and started over again. Although I didn't have much faith anymore I did try my last and fourth module and to my surprise it did work!
    I think maybe I got a bunch of unreliable modules. I did some inspection under a microscope and found a tombstoned resistor on one module and another module had a lot of debris between the components. Somehow I managed to get the resistor in place with my hotgun and I cleaned the other modules. Now I have 3 out of 4 RFM95 modules working!
    The before() function does not seem to matter.
    Only one module is still caught in an endless init loop:

    0 MCO:BGN:INIT GW,CP=RLNGA---,FQ=8,REL=255,VER=2.3.2
    53 MCO:BGN:BFR
    69 TSM:INIT
    81 TSF:WUR:MS=0
    100 RFM95:INIT
    114 RFM95:INIT:PIN,CS=6,IQP=2,IQN=0
    163 RFM95:PTX:LEVEL=13
    188 TSM:INIT:TSP OK
    208 TSM:INIT:GW MODE
    231 TSM:READY:ID=0,PAR=0,DIS=0
    264 MCO:REG:NOT NEEDED
    1026 GWT:TPC:IP=192.168.178.75
    2058 MCO:BGN:STP
    2076 MCO:BGN:INIT OK,TSP=1
    2260 GWT:TPC:IP=192.168.178.75
    3293 GWT:RMQ:CONNECTING...
    3325 GWT:RMQ:OK
    3344 GWT:TPS:TOPIC=mygateway3-out/0/255/0/0/18,MSG SENT
    3403 TSM:READY:NWD REQ
    3428 RFM95:SWR:SEND,TO=255,SEQ=0,RETRY=0
    0 MCO:BGN:INIT GW,CP=RLNGA---,FQ=8,REL=255,VER=2.3.2
    53 MCO:BGN:BFR
    69 TSM:INIT
    81 TSF:WUR:MS=0
    100 RFM95:INIT
    114 RFM95:INIT:PIN,CS=6,IQP=2,IQN=0
    163 RFM95:PTX:LEVEL=13
    188 TSM:INIT:TSP OK
    208 TSM:INIT:GW MODE
    231 TSM:READY:ID=0,PAR=0,DIS=0
    264 MCO:REG:NOT NEEDED
    1026 GWT:TPC:IP=192.168.178.75
    2058 MCO:BGN:STP
    2076 MCO:BGN:INIT OK,TSP=1
    2260 GWT:TPC:IP=192.168.178.75
    3293 GWT:RMQ:CONNECTING...
    3526 GWT:RMQ:OK
    3545 GWT:TPS:TOPIC=mygateway3-out/0/255/0/0/18,MSG SENT
    3604 TSM:READY:NWD REQ
    3629 RFM95:SWR:SEND,TO=255,SEQ=0,RETRY=0
    0 MCO:BGN:INIT GW,CP=RLNGA---,FQ=8,REL=255,VER=2.3.2
    53 MCO:BGN:BFR
    69 TSM:INIT
    ...
    

    But never mind, I'm very happy with my working gateways now.
    BTW, can someone recommend a reliable source for RFM95 modules? I got mine here: https://nl.aliexpress.com/item/32831799362.html?spm=a2g0s.9042311.0.0.27424c4dgIoZKr


  • Mod

    @willemx I ordered some from https://webshop.ideetron.nl/ in the past, and had good experience with it.
    They seem a local hoperf distributor for the Netherlands.



  • @Yveaux Thanks for the tip, I certainly will order my next RFM modules from ideetron.

    It turned out that my problems were not gone yet. When powered up, the ethernet gateways sometimes worked, and sometimes not. They got stuck waiting for the W5500 ethernet module. After some experimenting I found that the reset procedure of the W5500 is unreliable if the reset pin is left unconnected, leaving the W5500 in some undefined state after power up.
    I solved this by connecting the W5500 reset pin to an unused pin of the Arduino and performing a software controlled reset on power up:

    #define W5500_RESET_PIN     4
    
    void before() {
        pinMode(W5500_RESET_PIN, OUTPUT);
        digitalWrite(W5500_RESET_PIN, LOW);
        delay(10);
        digitalWrite(W5500_RESET_PIN, HIGH);
        delay(1000);
    }
    

    Now the gateways always work when powered up.
    It might be helpful to add this tip to the "Building an ethernet gateway" guide.


  • Mod

    Thanks for the info @willemx I have added a note to https://www.mysensors.org/build/ethernet_gateway
    Feel free to suggest changes if you think the information can be presented in a better way.


Log in to reply
 

Suggested Topics

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts