#include <SPI.h>
#include <Ethernet.h>
#include <Encoder.h>
uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 229);
EthernetServer server(3000);
// Create Encoder objects
#define ENCODER_DO_NOT_USE_INTERRUPTS
Encoder encoder1(22, 23);
Encoder encoder2(24, 25);
Encoder encoder3(26, 27);
Encoder encoder4(28, 29);
Encoder encoder5(30, 31);
Encoder encoder6(32, 33);
Encoder encoder7(34, 35);
Encoder encoder8(36, 37);
Encoder encoder9(38, 39);
Encoder encoder10(40, 41);
Encoder encoder11(42, 43);
Encoder encoder12(44, 45);
const int interval = 1000;
unsigned long previousMillis = 0;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.print ("server is at");
Serial.println(Ethernet.localIP());
encoder2.write(2);
encoder1.write(2);
encoder2.write(2);
encoder3.write(2);
encoder4.write(2);
encoder5.write(2);
encoder6.write(2);
encoder7.write(2);
encoder8.write(2);
encoder9.write(2);
encoder10.write(2);
encoder11.write(2);
encoder12.write(2);
}
void loop() {
EthernetClient client = server.available();
// Read the values of the rotary encoders
long encoder1Value = encoder1.read();
long encoder2Value = encoder2.read();
long encoder3Value = encoder3.read();
long encoder4Value = encoder4.read();
long encoder5Value = encoder5.read();
long encoder6Value = encoder6.read();
long encoder7Value = encoder7.read();
long encoder8Value = encoder8.read();
long encoder9Value = encoder9.read();
long encoder10Value = encoder10.read();
long encoder11Value = encoder11.read();
long encoder12Value = encoder12.read();
// Check if the value of any of the encoders is greater than 722 or less than 2
if (encoder1Value > 722) encoder1.write(2);
if (encoder2Value > 722) encoder2.write(2);
if (encoder3Value > 722) encoder3.write(2);
if (encoder4Value > 722) encoder4.write(2);
if (encoder5Value > 722) encoder5.write(2);
if (encoder6Value > 722) encoder6.write(2);
if (encoder7Value > 722) encoder7.write(2);
if (encoder8Value > 722) encoder8.write(2);
if (encoder9Value > 722) encoder9.write(2);
if (encoder10Value > 722) encoder10.write(2);
if (encoder11Value > 722) encoder11.write(2);
if (encoder12Value > 722) encoder12.write(2);
//reverse
if (encoder1Value < 2) encoder1.write(722);
if (encoder2Value < 2) encoder2.write(722);
if (encoder3Value < 2) encoder3.write(722);
if (encoder4Value < 2) encoder4.write(722);
if (encoder5Value < 2) encoder5.write(722);
if (encoder6Value < 2) encoder6.write(722);
if (encoder7Value < 2) encoder7.write(722);
if (encoder8Value < 2) encoder8.write(722);
if (encoder9Value < 2) encoder9.write(722);
if (encoder10Value < 2) encoder10.write(722);
if (encoder11Value < 2) encoder11.write(722);
if (encoder12Value < 2) encoder12.write(722);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
String packet = "Simulator encoder Packet: \nEncoder 1: " + String(encoder1Value/2) + "\nEncoder 2: " + String(encoder2Value/2)
+ "\nEncoder 3: " + String(encoder3Value/2) + "\nEncoder 4: " + String(encoder4Value/2) + "\nEncoder 5: " + String(encoder5Value/2)
+ "\nEncoder 6: " + String(encoder6Value/2)+ "\nEncoder 7: " + String(encoder7Value/2)
+ "\nEncoder 8: " + String(encoder8Value/2)+ "\nEncoder 9: " + String(encoder9Value/2)+ "\nEncoder 10: " + String(encoder10Value/2)
+ "\nEncoder 11: " + String(encoder11Value/2)+ "\nEncoder 12: " + String(encoder12Value/2) + "\nPacket Close";
// Send the message
client.println(packet);
Serial.println(packet);
//Update time
previousMillis = currentMillis;
}
}
so pretty much i need to upload the data from 12 encoders so it can be read by an application. i have 0 experience in networking. i got an ethernet shield today, thought this would work but ive tried changing the mac, ip, and port. tried the built it libraries and tried following tutorials.
i got the sunfounder shield, tried 2 different cables aswell.
im wondering if im missing a step. ive tried reading the data through a python script, and through telnet on cmd. im just at a loss and my brain hurts, if i could get some help or explanation that would be great.
im using an arduino mega 2560