I wrote a small program for an Arduino Ethernet using Arduino IDE 1.0.5-r2 and it works perfectly fine. I upgraded the IDE to 1.6.5 and my code does not work at all. I don't get any errors when I compile but when I load the sketch into the Arduino Ethernet it doesn't work. I also tried IDE version 1.0.6 and it doesn't work with that version either. I went back to 1.0.5-r2 and it works fine again.
The program looks at 3 analog inputs and acts as a server waiting for a connection on IP port 41001. When it gets a connection it just sends converted values of the 3 analog inputs to the client. It also turns on the on board LED when there is an active connection.
It is easy to test using telnet or putty but use TCP port 41001 instead of port 23.
I tried looking at the various libraries and what might be different between the versions but I am not experienced enough to find the problem.
Any help on how to troubleshoot would be greatly appreciated.
Thank you,
Here is the code:
#include <SPI.h>
#include <Ethernet.h>
// Analog Inputs
const int analogInPin0 = A0; // Joystick Blue Wire - X Axis or Pan
const int analogInPin1 = A1; // Joystick Yellow Wire - Y Axis or Tilt
const int analogInPin2 = A2; // Joystick Green Wire - Z Axis or Zoom
const byte Pan = 0; // Index 0
const byte Tilt = 1; // Index 1
const byte Zoom = 2; // Index 2
const String strNamePan = "P1=";
const String strNameTilt = "T1=";
const String strNameZoom = "Z1=";
const String strNameColon = ":";
int sensorValue[3]; // Value Read From Joystick
int oldValue[3]; // Used To Track Axis Value Change
int outputValue[3]; // Axis Value Scaled Down Value
String strPan = "";
String strTilt = "";
String strZoom = "";
// After 10 seconds of no activity send CR LF to check if client is connected.
int TimerCounter = 0;
long interval = 1000;
long previousMillis = 0;
// Enter a MAC address and IP address for your controller below.
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x54, 0xD4};
IPAddress ip(10,1,106,66);
byte subnet[] = {255, 255, 255, 0};
byte gateway[] = {10, 1, 106, 1};
// Initialize the Ethernet server library
// with the IP address and port you want to use
EthernetServer server(41001);
void setup()
{
// Start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
// initialize pin 9 as output. Pin 9 has built in Yellow LED on the Arduino Ethernet Board
pinMode(9, OUTPUT);
digitalWrite(9, LOW); // set the LED off
}
void loop()
{
EthernetClient client = server.available();
unsigned long currentMillis = millis();
if (client == true)
{
int counter = 0;
digitalWrite(9, HIGH); // set the LED on
// Read The Joystick Analog Input Value:
sensorValue[Pan] = analogRead(analogInPin0);
sensorValue[Tilt] = analogRead(analogInPin1);
sensorValue[Zoom] = analogRead(analogInPin2);
// Scale Analog Input Value of 0-1023 down to 1-11
for(counter=0; counter < 3; counter++)
{
if(sensorValue[counter] < 61)
{
outputValue[counter] = 1;
}
else if((sensorValue[counter] > 60) and (sensorValue[counter] < 121))
{
outputValue[counter] = 2;
}
else if((sensorValue[counter] > 120) and (sensorValue[counter] < 181))
{
outputValue[counter] = 3;
}
else if((sensorValue[counter] > 180) and (sensorValue[counter] < 241))
{
outputValue[counter] = 4;
}
else if((sensorValue[counter] > 240) and (sensorValue[counter] < 301))
{
outputValue[counter] = 5;
}
else if((sensorValue[counter] > 300) and (sensorValue[counter] < 724))
{
outputValue[counter] = 6;
}
else if((sensorValue[counter] > 723) and (sensorValue[counter] < 784))
{
outputValue[counter] = 7;
}
else if((sensorValue[counter] > 783) and (sensorValue[counter] < 844))
{
outputValue[counter] = 8;
}
else if((sensorValue[counter] > 843) and (sensorValue[counter] < 904))
{
outputValue[counter] = 9;
}
else if((sensorValue[counter] > 903) and (sensorValue[counter] < 964))
{
outputValue[counter] = 10;
}
else
{
outputValue[counter] = 11;
}
}
// If Pan Value Has Changed and Communication is Enabled
if (outputValue[Pan] != oldValue[Pan])
{
oldValue[Pan] = outputValue[Pan];
strPan = strNameColon;
strPan += strNamePan;
strPan += outputValue[Pan];
client.println(strPan);
TimerCounter = 0;
}
delay(50);
// If Tilt Value Has Changed
if (outputValue[Tilt] != oldValue[Tilt])
{
oldValue[Tilt] = outputValue[Tilt];
strTilt = strNameColon;
strTilt += strNameTilt;
strTilt += outputValue[Tilt];
client.println(strTilt);
TimerCounter = 0;
}
delay(50);
// If Zoom Value Has Changed
if (outputValue[Zoom] != oldValue[Zoom])
{
oldValue[Zoom] = outputValue[Zoom];
strZoom = strNameColon;
strZoom += strNameZoom;
strZoom += outputValue[Zoom];
client.println(strZoom);
TimerCounter = 0;
}
// Output String To AMX Example ("':P=4',13,10") P=Pan - T=Tilt - Z=Zoom)
// 10 Second Timer - Sends a CR LF to the client after 10 seconds of inactivity to determine if client is still connected.
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
TimerCounter++;
if(TimerCounter > 9)
{
client.println();
TimerCounter = 0;
}
}
}
else
{
digitalWrite(9, LOW); // set the LED off
TimerCounter = 0;
}
delay(100);
}