Arduino Ethernet code works in IDE version 1.0.5-r2 but not 1.0.6 or 1.6.5

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);   
}
const String strNamePan = "P1=";
const String strNameTilt = "T1=";
const String strNameZoom = "Z1=";
const String strNameColon = ":";

Why are you pissing away resources wrapping a string in a String, ans then declaring that the String can't change?

    Ethernet.begin(mac, ip, gateway, subnet);

I do not believe that the 4 argument begin() method works for anybody.

Can you explain in more detail just what "my code does not work at all" is? Specifically what are you expecting that is not happening.

clanholm:

// Analog Inputs

const int analogInPin0 = A0;  // Joystick Blue Wire - X Axis or Pan
const int analogInPin1 = A1;  // Joystick Yellow Wire - Y Axis or Tilt

These pins will not work for analog input, as they are used for the SD card slot on the Ethernet shield.

pin A0 ==> SD card "write protect"
pin A1 ==> SD card "card present"
Both pins are pulled to HIGH with a resistor on the Ethernet shield and will change their state when a SD card is present (A1) and if it is "write protect" enabled (A0).

You'd better use some different analog pins: A2, A3, A4, A5 are possible to use for analog input with the Ethernet shield.

Or you bent back or clip off A0 and A1 pins before inserting the Ethernet shield, so that these pins get no connection to the Ethernet shield, then you can use them for analog input.

Hi PaulS,

I am very new to this and I am sure that I am not very good at it yet. I guess since it is such a small program I haven't really run into trouble with resources yet. What would I replace the 4 argument begin statement with?

Thanks,

Hi Jurs,

I actually am not using an Arduino Ethernet Shield. I am using the Arduino Ethernet with built in POE. I don't know if that makes a difference or not but the program works absolutely fine as long as I compile and load it with IDE version 1.0.5r2. Anything newer and the board will not accept a connection.

Thanks,

Hi Zoomkat,

By it does not work at all I mean that when I try to connect to it over Ethernet it will not accept a connection. It works fine when I compile and load it with IDE version 1.0.5r2 but any version newer than that it will not accept a connection.

Thanks

clanholm:
Hi Jurs,

I actually am not using an Arduino Ethernet Shield. I am using the Arduino Ethernet with built in POE. I don't know if that makes a difference or not but the program works absolutely fine as long as I compile and load it with IDE version 1.0.5r2. Anything newer and the board will not accept a connection.

I've looked up the "Arduino Ethernet Board" schematics here:

There are no pull-up resistors on A0 and A1 with the board. So contrary to the "Ethernet Shield" there should be no problem while using A0 and A1 for analog input.

Do you have possibly two Arduinos in your network set to the same MAC address? Or to the same IP address?

byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x54, 0xD4};
IPAddress ip(10,1,106,66);

If you have configured a duplicate IP address, it would be enough to fix the sketch and give the device a unique IP address.

If you have managed to use a duplicate MAC address in your LAN, you will have to fix the sketch to a unique MAC address AND will have to restart your network: Pull the router, all switches and possibly all other network devices, then power-on the LAN again.

A couple things.

// change this
    Ethernet.begin(mac, ip, gateway, subnet);
// to this
    Ethernet.begin(mac, ip, gateway, gateway, subnet);

// and change this
    if (client == true)
// to this
    if (client)

I don't see a client.stop() call anywhere.

What app are you using to access the arduino?

Hi Jurs,

I only have one Arduino Ethernet on the network. My entire test system is A Cisco switch, my PC, and the Arduino Ethernet board. The switch is an unmanaged switch and does not have an IP address. My PC has a static IP address of 10.1.106.50. Arduino is 10.1.106.66. The MAC address for my PC is different than the MAC address for the Arduino.

Thanks,

Hi SurferTim,

I will try the changes that you suggested and see what happens. As far as the app that I use for testing, I am just using telnet on a Windows 7 pro machine but I change the port from the standard telnet port 23 to port 41001.

Here is a little background on how I use the Arduino Ethernet board.
I use a system from a company called AMX. They have processors called NetLinx processors. I program the NetLinx processors to control Panasonic IP cameras. I use the Arduino Ethernet boards to connect an analog joystick and put it on the network so that I can use the joystick to Pan, Tilt, and Zoom the Panasonic IP cameras. Currently I have about 6 projects that use this and it works really well. I ran into a problem when I upgraded my IDE from 1.0.5r2 to 1.0.6. When I loaded the sketch into the Arduino I couldn't get my AMX processor to connect to the Arduino. I uninstalled 1.0.6 and reinstalled 1.0.5r2 and loaded the sketch and everything worked fine again. Later on I tried updating the IDE to 1.6.4 and tried again. I had the same problem as 1.0.6. I couldn't connect to the Aurduino. So I put 1.0.5r2 back on and that it what I have been using. It works fine with that version. However I would like to update to the newest IDE eventually.

Thanks,

You shouldn't need to uninstall the IDE, Download the Windows zip file. That should allow you to have more than one IDE version on your PC. I use Linux, and i have a bunch of IDE versions on my PC, and all work fine.

I'm not fond of Windows. I don't have a PC with Windows on it any more.

Hi SurferTim,

You solved my problem.

I made the changes that you suggested and using IDE version 1.6.5 everything works as expected again.

I have just started tinkering with Linux. I have an older Lenovo ThinkkPad laptop that I recently loaded Linux Mint Cinnamon and so far is pretty amazing. It already started off better than Windows because it had all of the drivers for my laptop without me having to load anything separate.

Anyway thanks again for your help.