0

How can i connect and send data between two arduinos using a ENC28J60 ethernet adapters on both of them. Is there any guides or example codes for me to take a look from or any library which i can use to achieve this communication?

I have one arduino connected to an ultrasound sensor and the other to an relay module so that one arduino measures the distance between certain objects and send the distance to the other arduino which then processes it to check if it is within a certain limit if not then turn on the relay. I could have used two esp32 with one in AP mode but the range is not enough and serial communication is not possible as the cables are fragile and the distance is too large and also i couldnt find another way of sending the data.

Open to any suggestions even changing the method of communication? or using of any other ethernet modules?

0

You can use the EthernetENC library. See the examples of Arduino Ethernet library on how to use Ethernet libraries for Arduino.

EthernetClient object wraps a TCP socket. A normal TCP socket is connected to IP address and port. EthernetServer listens on a port. If server is contacted by a remote client socket, it creates a local socket connected with the remote client socket on a free port and returns a EthernetClient object wrapping the socket. Everything you write or print to a EthernetClient is send to that one remote socket.

If the client board creates a EthernetClient and connects it to IP address and port of the EthernetServer on your 'server' board, then you get there a EthernetClient from server.available() and this two EthernetClient objects are connected. What you write/print on one side you read only from the EthernetClient object on the other side.

client socket

   if (client.connect(serverIP, PORT)) {
     client.print("request\n");
     String response = client.readStringUntil('\n');
     Serial.println(response);
     client.stop();
   }

server side

   EthernetClient client = server.available();
   if (client && client.connected()) {
     String request = client.readStringUntil('\n');
     Serial.println(request);
     client.print("response\n");
     client.stop();
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.