Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Ethernet GW WITHOUT radio on Arduino Mega
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Ethernet GW WITHOUT radio on Arduino Mega

Scheduled Pinned Locked Moved Troubleshooting
10 Posts 3 Posters 2.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Sander StolkS Offline
    Sander StolkS Offline
    Sander Stolk
    wrote on last edited by Sander Stolk
    #1

    Fellow board members,

    I've got a Arduino Mega 2560 in my shed which I would like to function as a GW by Ethernet.
    I've got the code right for MYS 2.0 so that is not the problem I think.

    I've got an W5100 Ethernet module connected to the ports 50-53 and 5+ and GND on my Arduino Mega. Fixed IP and valid MAC address. When I debug my Mega it says IP: 0.0.0.0 but when I connect the same module with the same code to a Nano on the ports as advised than debug It says IP: 192.168.1.80 as programmed.

    On what pins do I need to connect my W5100 on my Mega?
    Is it on the middle PIN's? or just the 50-53 pins?
    Do I need some changes in the code? For example SoftSPI enable?

    Again: Nano connected with same code and same module: OK!
    Mega connected with same code and same module: IP 0.0.0.0

    Can somebody point me in the right direction?

    1 Reply Last reply
    0
    • Sander StolkS Offline
      Sander StolkS Offline
      Sander Stolk
      wrote on last edited by
      #2

      This is the code used for both devices:

      #include <SPI.h>
      #define MY_DEBUG
      #define MY_GATEWAY_W5100
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      //Nano  Mega
      //10 SS 53
      //11 MO 51
      //12 MI 50
      //13 SCK  52
      
      #define MY_IP_ADDRESS 192,168,1,80  // If this is disabled, DHCP is used to retrieve address
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xDD
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      
      // Relay 1 Perk en Gras
      // Relay 2 Fontein
      // Relay 3 Relay_3_MS
      // Relay 4 Relay_4_MS
      // PIR   5 PIR Schuur
      // Dista 6 Auto geparkeerd
      // Door  7 Poort
      // Door  8 Schuurdeur
      
      //Adding modules
      #include <Ethernet.h>
      #include <MySensors.h>
      #include <NewPing.h>
      #include <Bounce2.h>
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 4 // Total number of attached relays
      #define RELAY_ON 0  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
      
      // PIR
      #define CHILD_ID_PIR 5   // Id of the sensor child
      
      #define DIGITAL_INPUT_SENSOR_PIR 21   // PIR
      #define INTERRUPT DIGITAL_INPUT_SENSOR_PIR // Usually the interrupt = pin -2 (on uno/nano anyway)
      int oldValueTripped=-1;
      
      // Distance sensor
      #define CHILD_ID_DIST 6
      #define TRIGGER_PIN 12 // Afstandsmeter Trigger
      #define ECHO_PIN 13 // Afstandsmeter Echo
      #define MAX_DISTANCE 300 // Max distance we want to start indicating green (in cm)
      #define PARKED_DISTANCE 130// Distance when "parked signal" should be sent to controller (in cm)
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
      unsigned long sendIntervalDIST = 15000;  // Send park status at maximum every 5 second.
      unsigned long lastSend;
      int oldParkedStatus=-1;
      int skipZero=0;
      
      // Doors
      #define CHILD_ID_GATE 7
      #define CHILD_ID_SD 8
      #define Sheddoor 8 // Schuurdeur
      #define Gate 7 // Poort
      Bounce debouncerGate = Bounce();
      Bounce debouncerSD = Bounce(); 
      int GateoldValue=-1;
      int SDoldValue=-1;
      
      MyMessage msgDIST(CHILD_ID_DIST, V_TRIPPED);
      MyMessage msgPIR(CHILD_ID_PIR, V_TRIPPED);
      MyMessage msgGate(CHILD_ID_GATE,V_TRIPPED);
      MyMessage msgSD(CHILD_ID_SD,V_TRIPPED);
      
      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()
      {
        // PIR
        pinMode(DIGITAL_INPUT_SENSOR_PIR, INPUT);
        // Gate
        pinMode(Gate,INPUT);
        digitalWrite(Gate,HIGH);
        debouncerGate.attach(Gate);
        debouncerGate.interval(5);
        // Sheddoor
        pinMode(Sheddoor,INPUT);
        digitalWrite(Sheddoor,HIGH);
        debouncerSD.attach(Sheddoor);
        debouncerSD.interval(5);
      }
      
      void presentation() {
        // PIR
        present(CHILD_ID_PIR, S_MOTION);
        // Distance
        present(CHILD_ID_DIST, S_DOOR);
        // Gate
        present(CHILD_ID_GATE, S_DOOR);
        // Shed
        present(CHILD_ID_SD, S_DOOR);
        // Relays
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Register all sensors to gw (they will be created as child devices)
              present(sensor, S_BINARY);
          }
      }
      
      void loop() 
      {
        // PIR Get the update value
        int tripped = digitalRead(DIGITAL_INPUT_SENSOR_PIR) == HIGH;
         if (tripped != oldValueTripped) {
           // Send in the new value
           send(msgPIR.set(tripped==HIGH ? 1 : 0 ));
           oldValueTripped = tripped;
        }
      
        // Distance
        unsigned long now = millis();
        unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
        int displayDist = min(fullDist, MAX_DISTANCE);
        if (displayDist == 0 && skipZero<10) {
          // Try to filter zero readings
          skipZero++;
          return;
        }
          // Update parked status
          int parked = displayDist != 0 && displayDist<PARKED_DISTANCE;
          if (parked != oldParkedStatus && now-lastSend > sendIntervalDIST) {
            if (parked){
              send(msgDIST.set(1)); 
              }
            else {
              send(msgDIST.set(0));
            }
            oldParkedStatus = parked;
            lastSend = now;
          }
      
        // Gate
        debouncerGate.update();
        // Get the update value
        int Gatevalue = debouncerGate.read();
       
        if (Gatevalue != GateoldValue) {
           // Send in the new value
           send(msgGate.set(Gatevalue==HIGH ? 1 : 0));
           GateoldValue = Gatevalue;
        }
      
        // Sheddoor
        debouncerSD.update();
        // Get the update value
        int SDvalue = debouncerSD.read();
       
        if (SDvalue != SDoldValue) {
           // Send in the new value
           send(msgSD.set(SDvalue==HIGH ? 1 : 0));
           SDoldValue = SDvalue;
        }
      }
      
      void incomingMessage(const MyMessage &message) {
        if (message.type==V_LIGHT) {
           // Change relay state
           digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           // Store state in eeprom
           saveState(message.sensor, message.getBool());
         } 
      }
      
      
      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #3

        Soft spi I think it's used when you are using w5100 and a radio module on the gateway. I can't help you more because I used the w5100 shield.

        T 1 Reply Last reply
        0
        • gohanG gohan

          Soft spi I think it's used when you are using w5100 and a radio module on the gateway. I can't help you more because I used the w5100 shield.

          T Offline
          T Offline
          TimO
          Hero Member
          wrote on last edited by
          #4

          @gohan softspi is used for the connection to the radio not to the ethernet shield.

          Have you tried an example ethernet sketch or the stock ethernet gateway sketch with radio disabled? To ensure the wiring of the ethernet gateway with the mega is correct?

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #5

            That's what I meant, I didn't explain it well

            1 Reply Last reply
            0
            • Sander StolkS Offline
              Sander StolkS Offline
              Sander Stolk
              wrote on last edited by
              #6

              I also believe it has to be something with the wireing. I will check this tonight when I'm going to try it on the ICSP header.
              And to test it with the default sketch!

              1 Reply Last reply
              0
              • Sander StolkS Offline
                Sander StolkS Offline
                Sander Stolk
                wrote on last edited by Sander Stolk
                #7

                Example sketch is also not working...
                Ditto for the ICSP connection header
                It must be the wires!

                1 Reply Last reply
                0
                • Sander StolkS Offline
                  Sander StolkS Offline
                  Sander Stolk
                  wrote on last edited by
                  #8

                  So here is the deal!
                  You need to set Pin 53 to Output in your sketch and wire from 50-53 instead of 10-13.
                  It's working now

                  1 Reply Last reply
                  0
                  • gohanG Offline
                    gohanG Offline
                    gohan
                    Mod
                    wrote on last edited by
                    #9

                    that was clearly stated in the code and also in the guide

                    //Nano  Mega
                    //10 SS 53
                    //11 MO 51
                    //12 MI 50
                    //13 SCK  52
                    
                    Sander StolkS 1 Reply Last reply
                    0
                    • gohanG gohan

                      that was clearly stated in the code and also in the guide

                      //Nano  Mega
                      //10 SS 53
                      //11 MO 51
                      //12 MI 50
                      //13 SCK  52
                      
                      Sander StolkS Offline
                      Sander StolkS Offline
                      Sander Stolk
                      wrote on last edited by
                      #10

                      @gohan Yes I know but the pinout 53, output not. That was all that was needed eventually .

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      16

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular