Building an Ethernet Gateway on an Arduino Mega



  • I am trying to utilize all of my available Arduinos as best as I can, and having all sketches being developed on this site for the UNO my Arduino Mega seems to fit best in it's role as an Ethernet Gateway.

    By this I am able to use my available UNO to do some more testing and playing around with the MySensor sketches without the need to modify my sketches like I did to do in the past

    BUT, having that said this also exactly gives away my challenge :
    Getting the Ethernet Gateway Sketch working on my Arduino Mega with a W5100 Ethernet Shield.
    Issue is the pinout of a Mega's SPI interface is different than the UNO.

    So the sketch is working easily on my UNO, but changing the shield and uploading the same sketch to my MEGA results in a non working Ethernet Gateway (debug modes states : check wires)
    (I did uncomment the #define SOFTSPI line in the RF24_Config.h by the way)

    Does anyone know which file / library I need to edit to change these pins ? I am using the W5100 shield not the module so I would prefer the shield installed as a is, and not use any jumper cables.


  • Hero Member



  • @Heinz
    I guess I did not make myself perfectly clear as I allready had this information and my W5100 shield is using these pins from the pin 6 pin header in the middle of the board (check the red circle)
    edited Mega2560_R3_Label-small-v2 (2).png

    So I am wondering if these pins are addressed as the same pin numbers on the MEGA as on the UNO (thus making the sketches compatible).
    I am doubting this as I had some issues with this during building a temp sensor designed for an Uno (or Mini) on the same Mega (check also the first link in my initial post).

    The Radio in the Ethernet Gateway is addressed via SoftSPI, and is referred to use :
    A2 MISO
    A1 MOSI
    A0 SCK
    6 CSN
    5 CE

    My guess us that to address the Analogue and digital pins (A0, A1, A2, 5 and 6 ) on an Arduino Mega I need to change some code / pin referals. to get this working. Now I still get :
    0;0;3;0;9;check wires

    My Radio is currently connected to all these pins (A0, A1, A2, 5 and 6 ) located all on the W5100 shield, so I did not change anything from the UNO configuration (which is working) but it's not working on the Mega 😞

    After finding the Pin alias sheet for the UNO Clearing up the pins 16,15 and 14 referring to A0,A1,and A2 if found another sheet and according to this sheet I changed the following in my RF24_config.h ( As I hoped that according to this sheet A0,A1 and A2 labeled on the MEGA are corresponding with Digital Pins 56, 55 and 54

    // change these pins to your liking
          // Default for Uno
          //const uint8_t SOFT_SPI_MISO_PIN = 16; 
          //const uint8_t SOFT_SPI_MOSI_PIN = 15; 
          //const uint8_t SOFT_SPI_SCK_PIN = 14;  
          //const uint8_t SPI_MODE = 0;
    	  //MEGA CONFIG ?
          const uint8_t SOFT_SPI_MISO_PIN = 56; 
          const uint8_t SOFT_SPI_MOSI_PIN = 55; 
          const uint8_t SOFT_SPI_SCK_PIN = 54;  
          const uint8_t SPI_MODE = 0;
    

    But still no luck ..



  • I am still in the process of fixing this, is there anyone who can explain me why this is not working ?
    According to all the info I could find it that all I/O pins on the UNO are available on the MEGA, only MEGA has more pins available.

    So I still have no idea why this sketch is not working on my Mega but is on my UNO with the exact same EtherShield (as I own only one)



  • sj44k,

    now I got stuck at the exact same location like you. Arduino Mega, Ethernet Shield, Softspi -> "Check wires". Like you I connected the radio to A0/A1/A2 passthru pins on the Ethernet Shield but I am wondering if A0/A1/A2 are the right pins on Mega (since for hardware spi we also have to use other pins on mega).

    I would be very glad to hear from you if you have any new clues.

    So will I if I do, but at the moment I have absolutely no idea.

    Marcus.



  • Heee,

    use 14/15/16 on the mega instead of A0/A1/A2. I did not do too much tests, but I get "gateway startup complete".


  • Hero Member

    Why do you want to connect A0, A1, A2 to the radio?
    The picture above clearly says:
    PIN 50 = MISO
    PIN 51 = MOSI
    PIN 52 = SCK
    I connected to radio to those pins and everything worked well without any modifications!.



  • Because the Ethernet shield breaks SPIs characteristics to be a bus. Once Ethernet shield is plugged onto Arduino, all other devices on SPI bus won't work anymore.

    This is documented at http://www.mysensors.org/build/ethernet_gateway#wiring-things-up and was true for mine: without ethernet shield, radio on 50/51/52 works perfect. With ethernet shield, radio on 50/51/52 won't work. The alternative SoftSpi is documented on the mentioned page, but A0/A1/A2 as written there will only work for classic Arduinos. The question was what to use instead of A0/A1/A2 on Mega, and I think 14/15/16 are the right ones.

    Marcus,



  • @MSchmidke I am going to try this asap and post my findings .. but sir .. could you please share with me (and the rest of the world ) how did you find out about these pins ? I love solutions but I crave to understand WHY 🙂

    But still if this works you deserve my everlasting respect for finding it and sharing !

    @Heinz
    Are you using an Arduino MEGA ? I guess you are not.

    [one hour later]
    Ok figures that you choose 14/15/16 on the mega 🙂 the RF24config.h states :

    `      const uint8_t SOFT_SPI_MISO_PIN = 16; 
          const uint8_t SOFT_SPI_MOSI_PIN = 15; 
          const uint8_t SOFT_SPI_SCK_PIN = 14;  
    

    But having that said I still am not getting a reply on a ping when I ping the ethershield .. so we are close .. but not there yet 🙂

    I do get the

    0;0;3;0;14;Gateway startup complete.
    

    So that's further than I've been so far ..



  • Oh it would have been really simple to find this config file ... but I didn't.

    I investigated the digital read of analog port. On classic Arduino, you can digitalRead(A0), for example. And I wondered what is behind that "A0" - and tadah it's 14 on classic Arduino. So I supposed there will be simply a 14 in SoftSPI code - et voilà it worked.

    What kind of ethernet related code do you have in your loop? I don't think you'll get a ping if you do not poll the Ethernet. But I'm not sure.

    Marcus.



  • I use the ethernet gateway example of this site, and I am absolutely 100% sure it does reply on ping as when I use the same code on my UNO with the same shield, I do get an reply.
    When switching the shield to the MEGA, and placing the pins on 14 15 and 16 nothing happens.

    Do you get a ping ?


  • Contest Winner



  • @BulldogLowell

    :)Hunt for the red october classic 🙂



  • I have a similar issue with Adafruit CC3000 shield and a Mega.
    After much fidling around I finally got it to work.

    The Adafruit shiled is the same size of an Uno but when connected to a Mega it doesn't get the SCK, MOSI and MISO from the 13,11,12 pins, it gets them from the central connector ICSP as showed on the picture on this thread.

    So first step was to connect the wireless module to the ICSP.

    The second issue is the CSN and CE pins, these can't be connected to 10 and 9 since they are used by the shield. I've used 35 and 34.

    Adjust your code like this:

    #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
    #define INCLUSION_MODE_PIN 32 // Digital pin used for inclusion mode button
    #define CE_PIN 35
    #define CS_PIN 34
    MyGateway gw(CE_PIN, CS_PIN, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN, 6, 5, 4);

    Even with this, some times I still get a check wires message, others just a bunch of errors about the version.

    This erratic behaviour led me to think about noise on the wireless receiver, so in goes a 10uF.

    Its stable now.

    On a side note I also changed the CE and CS pin assignments on the sensors...

    #define DIGITAL_INPUT_SENSOR 4 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 1 // Id of the sensor child

    #define CE_PIN 9
    #define CS_PIN 53

    MySensor gw(CE_PIN,CS_PIN);

    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);

    Cheers



  • @barduino
    Can you help me out here, I do not get your remark :
    So first step was to connect the wireless module to the ICSP

    As my Ethershield is using this, how will this work together with the radio and the ethershield connected to the same pins ?
    My guess I am not getting exactly what you mean.



  • @sj44k

    I dont know much about this so I aks for clarification if some of my notes are incorrect.

    Not sure if you have the shield from adafruit. In my shield (WiFi and memory card) it is designed to be on top of an uno R3 (getting the sck mosi miso) from pins 13,12,11 or if on top of a mega (my case) it gets the sck, mosi and miso from those central pins (ICSP i think) and you have to solder some jumpers on the shield it self.

    1428958756089-edited-mega2560_r3_label-small-v2-2.png

    I took this image from your post

    As I understand it sck, mosi and miso are intended to be shared. The problem comes with the SS/CS pin (slave select) which each device should have one.

    In adafruit cc3000 shield this is pin 10 and pin 4 for the sd card. At least pin 10 conflicts with MySensors lib so I had to change this and connect the rf module to other pins (the icsp pins for sck mosi miso and cd pin to 53.

    When I did this I stoped having check wires message. However when I included the code to connect to the wifi on the cc3000 it couldnt still connect.

    I ended up disconnecting the mysensors rf module and tryied it with just the cc3000 code and it was behaving erratically, sometimes it connected others not... Is it damaged, is it power, in the end I just gave up, removed the cc3000 shield and connected the mysensors gw to a computer and used nodejs to call my REST service.

    I'll get back to this some time, it should work....

    The problem of buying a shield is that you cant change the pins to which it is connected to...



  • @sj44k hi, may i ask if you need a NRF24L01 radio module in order to make this Ethernet Gateway work? I'm asking because i understood that for a Serial Gateway you need this module, other way you cannot test it!
    My second question is if you made it i mean if you can read some sensors using the Ethernet W5100 and the Openhab server?
    Thanks.
    Forget the 1st question, i got it...
    Could you please tell me if you made it with Arduino Mega and the Ethernet shield? which are the right pins that needs to be modified in the RF24_Config.h ?



  • everybody in holiday here? nodoby answered on the serial gateway so im asking again here about the ethernet gateway if somebody can tell me/us which are the right pins that needs to be modified to start the ethernet gataway and to test it with openhab?


  • Admin

    @ewgor said:

    NRF24L01

    The NRF or HopeRF RF69 module i central in the MySensors infrastructure as it is centralised around wireless sensors/actuators. Experimental code exist (https://github.com/mysensors/Arduino/tree/gateway-refactoring) which lets you attach sensors to the gateway (serial or ethernet) directly. But this is not documented on the main site yet so you should be comfortable to read up code yourself.

    How to connect ethernet module (and modify configuration) is described on the main site. I haven't personally used a Mega as gateway myself. But I successfully used it as a sensor for the Touch Scene Controller.



  • hy guys,
    i have a mega bord, and wiznet ethernet shield, and i want to use this whith ethernet getway. i try many configs, but nothing work. please help me.



  • @bruno-araripe said:

    hy guys,
    i have a mega bord, and wiznet ethernet shield, and i want to use this whith ethernet getway. i try many configs, but nothing work. please help me.

    Hy,

    I have a same project and same problem.

    please 😓



  • Did someone get the GW with mega and W5100 working????



  • Hello,

    Any update ?


  • Hardware Contributor

    Did you try resetting the board after power on? I guess there are some boards that have issues and need a reset after power on before anything works. See the links in this post: http://forum.mysensors.org/topic/1021/security-introducing-signing-support-to-mysensors/157. The links in that post have a relatively easy fix to implement if it turns out that is the problem.



  • Nope but winter season is starting again so I have some spare time not being "outside" so I will be starting this project back up



  • @barduino said:

    I have a similar issue with Adafruit CC3000 shield and a Mega.
    After much fidling around I finally got it to work.

    The Adafruit shiled is the same size of an Uno but when connected to a Mega it doesn't get the SCK, MOSI and MISO from the 13,11,12 pins, it gets them from the central connector ICSP as showed on the picture on this thread.

    So first step was to connect the wireless module to the ICSP.

    The second issue is the CSN and CE pins, these can't be connected to 10 and 9 since they are used by the shield. I've used 35 and 34.

    Adjust your code like this:

    #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
    #define INCLUSION_MODE_PIN 32 // Digital pin used for inclusion mode button
    #define CE_PIN 35
    #define CS_PIN 34
    MyGateway gw(CE_PIN, CS_PIN, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN, 6, 5, 4);

    Even with this, some times I still get a check wires message, others just a bunch of errors about the version.

    This erratic behaviour led me to think about noise on the wireless receiver, so in goes a 10uF.

    Its stable now.

    On a side note I also changed the CE and CS pin assignments on the sensors...

    #define DIGITAL_INPUT_SENSOR 4 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 1 // Id of the sensor child

    #define CE_PIN 9
    #define CS_PIN 53

    MySensor gw(CE_PIN,CS_PIN);

    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);

    Cheers

    Hi, can you please share your Gateway code. I also having problem with a CC3000 and Arduino Mega. UNO was too small 🙂

    Thanks



  • I'm sorry @flopp

    It did not work on the end, my shield just stopped working even with an example sketch, so I never completed the project.

    What flavor of CC3000 do you have, the shield with the SD card or the small board with just the wifi module?

    Cheers



  • @barduino

    EDIT: NOT SD-card



  • Here the solution to run Arduino Mega and the shield W5100.

    Into the file MyConfig.h, after the line:
    #include <stdint.h>:

    you must add the following lines:

    #if ARDUINO < 100
    	#include <WProgram.h>
    #else
           #include <Arduino.h>
    #endif
    

    Then replace the lines:

    const uint8_t SOFT_SPI_MISO_PIN = 16;
    const uint8_t SOFT_SPI_MOSI_PIN = 15;
    const uint8_t SOFT_SPI_SCK_PIN = 14;
    

    with these:

    const uint8_t SOFT_SPI_MISO_PIN = A2;
    const uint8_t SOFT_SPI_MOSI_PIN = A1;
    const uint8_t SOFT_SPI_SCK_PIN = A0;
    

    Finally enable define SOFTSPI removing the comment (//)

    Compile and load the software and you're done! 😁



  • hello
    i've got the ethernet gateway on the mega that work but after a power loose, the ping of the gateway is ok but no more return on the serial monitor even after reset

    i'm using a external power for the mega and same result with usb power.



  • @spugna85
    Hello, I'm putting the code as you indicated, and connecting the nRF24L01 pins:
    6 CSN
    5 CE
    Pin 50, 51, 52

    and message: 0;0;3;0;9;radio init fail
    I link capacitor in power, I have done everything. And now????
    😧


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 2
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts