Ethernet Sheild Canundrum

Hello

We have been trying to figure out what is happening for a few days now... hoping someone here may have an answer.

We are simply trying to create an interface from our server to the Arduino ethernet shield to turn on a pin.
We have the ethernet shield mounted on an uno.. we've tested the uno buy compiling a code that turns on a pin.... the LED lights up fine.

When we try to compile the code for the shield the light just barely blinks when ever it connects to the server...
We have a web server that we want to essentially control the LED from... the web service will turn the light on or off... the shield should connect and look to see what state it should be in... but that doesn't happen... When we execute the console the code does respond and show what your web server is displaying (on or off) so we know it's connecting fine... but responding to the code is a different story

We've tested all of the pins to see if any of them will function correctly but none do.... any thoughts at all?

Have you checked your rail voltage to make sure you're not browning out the power supply?

The W5100 on the ethernet shield is a a pretty power-hungry little chip.

Also, since this is the programming section, you'll see a lot more responses and get a lot better feedback if you, ya know, post your code so others can take a look at it and see if there's an error in your programming logic.

If you really want any help, you need to post your code, as that is often where issues arise, aka "bad code".

Thanks Zoomkat

here is the last one we tried when we trying to turn on and off all of the pins…

#include <SPI.h>

#include <Ethernet.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>



// Enter a MAC address for your controller below.

// Newer Ethernet shields have a MAC address printed on a sticker on the shield

byte mac[] = {  0x6C,0x62,0x6D,0xEE,0x78,0x9D };
////
IPAddress server(184,172,223,94); 

String response = "";

// Initialize the Ethernet client library

// with the IP address and port of the server

// that you want to connect to (port 80 is default for HTTP):

EthernetClient client;
int flag = 0;
int led = 9;

void setup() {
    Serial.begin(9600);
  pinMode(0,OUTPUT);
  pinMode(1,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(14,OUTPUT);

    // start the Ethernet connection:

    if (Ethernet.begin(mac) == 0) {

      Serial.println("Failed to configure Ethernet using DHCP");

      // no point in carrying on, so do nothing forevermore:

      for(;;)
      ;
    }
    
    delay(1000);

  Serial.println("connecting...");

  // if you get a connection, report back via serial:

  if (client.connect(server, 8080)) {

    Serial.println("connected");

    // Make a HTTP request:

    client.println("GET /seatmateapi/resources/constructionSites/isSiteActiveAndOccupied?macAddress=6C-62-6D-EE-78-9D HTTP/1.0");

    client.println();

  }

  else {

    // kf you didn't get a connection to the server:

    Serial.println("connection failed");

  } 
}



void loop()

{

  if (client.available()) {
    char c;
    c = client.read();
    response += c;
  }

  if (!client.connected()) {

    Serial.print(response);
    Serial.println("\ndisconnecting.");
    client.stop();
    client.connect(server, 8080);
    client.println("GET /seatmateapi/resources/constructionSites/isSiteActiveAndOccupied?macAddress=6C-62-6D-EE-78-9D HTTP/1.0");
    client.println();
    delay(1000);
    if(response.indexOf("INACTIVE") > 0)  {
        //if(flag == 1)  {
          Serial.println("LIGHTS OFF");
          digitalWrite(0, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(1, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(2, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(4, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(6, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(8, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(9, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(10, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(11, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(12, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)
          flag = 0;
        //}
    }
    else  {
        //if(flag == 0)  {
          Serial.println("LIGHTS ON.");
                   digitalWrite(0, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(1, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(2, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(4, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(6, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(8, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(9, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(10, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(11, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(12, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)
          flag = 1;
        //}
    }
    response = "";
  }
}

The problem is your code.

The ethernet shield uses pins 6, 10, 11, 12, and 13 if i remember correctly. You'll need to make sure those pins are not connected to anything and that no user code is manipulating those pins.

ahh that would explain why the light was bright when we just ran to the uno board but when we ran to the shield it was just very dim…

So the “control” code looks correct? again this one that I posted was the last version we tried… we have never been able to control any of the pins using ethernet… the web service works fine as it’s displaying “on” or “off”… but no response on the pins… I don’t think we tried all of the pins individually but we did try to use pin 3… same outcome.

Some simple web page test code for turning on’off pin 5 and positioning a servo. It would be helpful if you modified you post with code to put the code in a code box. Click modify in the post to reopen it, highlight the code and click the # in the post tool bar.

//zoomkat 4-1-12
//simple button GET for servo and pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of " 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("server servo/pin 5 test 1.0"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href=\"/?on\"\">ON</a>"); 
          client.println("<a href=\"/?off\"\">OFF</a>"); 

          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            myservo.write(40);
            digitalWrite(5, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            myservo.write(140);
            digitalWrite(5, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Also, pins 0 and 1 are your serial connection via the USB port. You’re not going to want to mess with those either.

btw, loops are your friend.

#define PIN_COUNT 5
int pins[PIN_COUNT] = {2,3,4,5,7};

for (int i = 0; i< PIN_COUNT; i++)
{
  digitalWrite(pins[i], HIGH);
}

it’s the same as putting digitalWrite 5 times.

For example, this disaster here:

  if(response.indexOf("INACTIVE") > 0)  {
        //if(flag == 1)  {
          Serial.println("LIGHTS OFF");
          digitalWrite(0, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(1, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(2, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(4, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(6, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(8, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(9, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(10, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(11, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(12, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)
          flag = 0;
        //}
    }
    else  {
        //if(flag == 0)  {
          Serial.println("LIGHTS ON.");
                   digitalWrite(0, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(1, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(2, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(4, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(6, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(8, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(9, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(10, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(11, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(12, LOW);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)
          flag = 1;
        //}
    }

Can be re-written as:

#define PIN_COUNT 5
int pins[PIN_COUNT] = {2,3,4,5,7};
 bool inactive  = ( response.indexOf("INACTIVE") == -1);
 for (int i = 0; i < PIN_COUNT; i++)
{
  digitalWrite(pins[i], inactive);
}

Serial.print("LIGHTS ");
Serial.println(inactive ? "ON" : "OFF");

Disclaimer: Haven’t tried to compile or test any of the above.

Hi guys,

Let me make discuss my problem in detail:

Problem:
LED does not turn ON, even though it was clear that we sent a digitalWrite(4, HIGH) clearly.

Scenario:
We developed an arduino client that calls a webservice. The webservice simply replies “ACTIVE” if LED need to be ON
and “INACTIVE” if need to be OFF.

To our surprise, the webservice had clearly responded with “ACTIVE” led, and the arduino code had clearly went to the code section that
says digitalWrite(4,HIGH) but the LED does not lite. we are certain also that the LED works, as we can make it blink using the “blink sample tutorial”

hope you could help guys.

The actual CODE:
#include <SPI.h>

#include <Ethernet.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

// Enter a MAC address for your controller below.

// Newer Ethernet shields have a MAC address printed on a sticker on the shield

byte mac = { 0x6C,0x62,0x6D,0xEE,0x78,0x9D };
////
IPAddress server(XXX,XXX,XXX,XX);

String response = “”;

// Initialize the Ethernet client library

// with the IP address and port of the server

// that you want to connect to (port 80 is default for HTTP):

EthernetClient client;
int flag = 0;
int led = 4;

void setup() {
Serial.begin(9600);
pinMode(4,OUTPUT);

// start the Ethernet connection:

if (Ethernet.begin(mac) == 0) {

Serial.println(“Failed to configure Ethernet using DHCP”);

// no point in carrying on, so do nothing forevermore:

for(;:wink:
;
}

delay(1000);

Serial.println(“connecting…”);

// if you get a connection, report back via serial:

if (client.connect(server, 8080)) {

Serial.println(“connected”);

// Make a HTTP request:

client.println(“GET /linkxxxxxxxxxxx/?xxxxxxx=xxxxx HTTP/1.0”);

client.println();

}

else {

// kf you didn’t get a connection to the server:

Serial.println(“connection failed”);

}
}

void loop()

{

if (client.available()) {
char c;
c = client.read();
response += c;
}

if (!client.connected()) {

Serial.print(response);
Serial.println("\ndisconnecting.");
client.stop();
client.connect(server, 8080);
client.println(“GET /seatmateapi/resources/constructionSites/isSiteActiveAndOccupied?macAddress=6C-62-6D-EE-78-9D HTTP/1.0”);
client.println();
delay(1000);
if(response.indexOf(“INACTIVE”) > 0) {
if(flag == 1) {
Serial.println(“LIGHTS OFF”);
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
flag = 0;
}
}
else {
if(flag == 0) {
Serial.println(“LIGHTS ON.”);
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
flag = 1;
}
}
response = “”;
}
}

The server actual RESPONSE
“ACTIVE”

What is flag doing that is useful? Why do you set the pin LOW in both cases? LOW is generally not how to make a pin HIGH.

Sweet! Thank you everyone! Finally got it working!!!