Hello,
I'm struggling with ethernet communication to receive values from an arduino nano.
Here is the full installation for context :
I'm using an Xbox controller to control some actuators with Processing (pde) and Arduino.
But I need info from other sensors connected by a long Ethernet cable.
Those sensors, just some micro switch to detect contact, are connected to an arduino nano and an ethernet shield ( ENC28J60). I also need an ethernet camera which explains the ethernet switch.
Here's the program on the Arduino nano :
#include <UIPEthernet.h> // ENC28J60
const int Contact1 = 5;
const int Contact3 = 3;
const int Contact2 = 4;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 115); // Address IP Arduino
IPAddress server(192, 168, 1, 100); // Address IP PC
const int port = 8000; // Port
EthernetClient client;
int state1 = 0;
int state2 = 0;
int state3 = 0;
void setup() {
pinMode(Contact1, INPUT_PULLUP);
pinMode(Contact3, INPUT_PULLUP);
pinMode(Contact2, INPUT_PULLUP);
Serial.begin(9600);
Ethernet.begin(mac, ip);
delay(1000);
Serial.println("Connection ...");
if (client.connect(server, port)) {
Serial.println("Connected ! ");
} else {
Serial.println("Connection failed");
}
}
void loop() {
// contacts
state1 = !(digitalRead(Contact1));
state2 = !(digitalRead(Contact3));
state3 = !(digitalRead(Contact2));
Serial.print(state1);
Serial.print(state2);
Serial.println(state3);
if (client.connected()) {
client.print("Contact: "); client.print(state1); client.print(state2); client.println(state3);
} else {
Serial.println("Connection lost");
if (client.connect(server, port)) {
Serial.println("Reconnected !");
}
}
}
My goal is to use the sensors values received by ethernet on my computer on an arduino program to pilot the arduino mega. Is it possible ? Do you have some idea on how to do it ? Maybe it's a trivial problem but I haven't found any answer yet.
Thank you in advance !

