Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Arduino + Ethernet Shield Help (http://www.chiefdelphi.com/forums/showthread.php?t=118069)

jwallace15 09-08-2013 13:08

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by techhelpbb (Post 1286644)
Start with what you know.
Then explore what you don't know.

Put the working example code you just had in your Arduino.
Then connect just one relay to the digital I/O pin 8.

Does that work?

Yes, it works when I connect pin 8 to all of my relays.

techhelpbb 09-08-2013 13:17

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1286649)
Yes, it works when I connect pin 8 to all of my relays.

I am curious if you mean that you connected pin 8 to all of your relays at the same time or just one at a time. However it doesn't really matter you could actually make that work with the boards you and I have.

The good news is that all except the first relay works and you can drive them properly.

The bad news is this is now a programming problem again :D
Post your altered code and let's see where the issue(s) are.

In the mean time, alter your working code to test each pin you want to use to drive relays one at a time. So change the 2 'PinD8' to for example 'PinD6'.

This will at least verify that there's no burnt out pins on your Arduino.
We know what the situation with the relay board is.

jwallace15 09-08-2013 13:23

Re: Arduino + Ethernet Shield Help
 
This is the altered code I wrote earlier that wouldn't load:

Code:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,130 };

const int MAX_PAGENAME_LEN = 8;
char buffer[MAX_PAGENAME_LEN+1];

EthernetServer server(80);

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  delay(2000);
}

void loop()
{
  EthernetClient client = server.available();
  if (client)
  {
    int type = 0;
    while (client.connected())
    {
      if (client.available())
      {
        memset(buffer,0, sizeof(buffer));
        //if(client.find("/"))
          if(client.readBytesUntil('/', buffer,sizeof(buffer)))
          {
            Serial.println(buffer);
            if(strcmp(buffer,"POST ") == 0)
            {
              client.find("\n\r");
              while(client.findUntil("PinD", "\n\r"))
              {
                int pin = client.parseInt();
                int val = client.parseInt();
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
              }
            }
            sendHeader(client,"Post example");
            client.println("<h2>Click buttons to turn the relays on and off.</h2>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD9'");
            client.println(" value='0'><input type='submit' value='Relay 2 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD9'");
            client.println(" value='1'><input type='submit' value='Relay 2 off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
            client.println(" value='0'><input type='submit' value='Relay 3 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD8'");
            client.println(" value='1'><input type='submit' value='Relay 3 off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD7'");
            client.println(" value='0'><input type='submit' value='Relay 4 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD7'");
            client.println(" value='1'><input type='submit' value='Relay 4 off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD6'");
            client.println(" value='0'><input type='submit' value='Relay 5 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD6'");
            client.println(" value='1'><input type='submit' value='Relay 5 off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD5'");
            client.println(" value='0'><input type='submit' value='Relay 6 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD5'");
            client.println(" value='1'><input type='submit' value='Relay 6 off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD3'");
            client.println(" value='0'><input type='submit' value='Relay 7 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD3'");
            client.println(" value='1'><input type='submit' value='Relay 7 off'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD2'");
            client.println(" value='0'><input type='submit' value='Relay 8 on'/></form>");
            client.print(
            "<form action='/' method='POST'><p><input type='hidden' name='PinD2'");
            client.println(" value='1'><input type='submit' value='Relay 8 off'/></form>");
            client.println("</body></html>");
            client.stop();
          }
          break;
        }
      }
      delay(1);
      client.stop();
    }
  }
void sendHeader(EthernetClient client, char *title)
{
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();
  client.print("<html><head><title>");
  client.print(title);
  client.println("</title><body>");
}

I will now test each pin like you said.

I tried deleting all of the lines except for one input/output line and it didn't load. Then I switched back to the original working code that I posted on page 3 and it doesn't work either.

I went into CMD and entered "ping 192.168.1.130" and the request timed out. None of the pings made it back to CMD.

techhelpbb 09-08-2013 13:37

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1286653)
I tried deleting all of the lines except for one input/output line and it didn't load. Then I switched back to the original working code that I posted on page 3 and it doesn't work either.

I went into CMD and entered "ping 192.168.1.130" and the request timed out. None of the pings made it back to CMD.

Turn off the Arduino system.
Turn it back on.
Load the original working code.
Turn off the Arduino system.
Turn it back on.

Try that?

Also if you put an microSD card in the socket remove it.
Your example was written on an older shield that did not have the reader.
If you put a card in the reader it might lock the ethernet interface on you.

jwallace15 09-08-2013 13:55

Re: Arduino + Ethernet Shield Help
 
My ethernet shield is made by sainsmart as well, and the chip on it gets very hot, so I turned it off in hopes that it simply overheated.

Turning it back on now, along with the router/bridge.

Pinged it, and the Arduino replied with all 4 pings.

Now testing the outputs.

The issue with pin 4? When I tested it the LED was lit. Then I turned it on in post example and it lit and the relay fired. When I pressed off the voltage went to 0 instead of hovering around .19. Correction: It still does it.

techhelpbb 09-08-2013 13:58

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1286660)
My ethernet shield is made by sainsmart as well, and the chip on it gets very hot, so I turned it off in hopes that it simply overheated.

Are you saying that pin 4 on your Arduino does or does not work?

Frankly I would avoid using pin 4.
That pin on the Arduino shield with the microSD card reader could shut down your ethernet interface.

jwallace15 09-08-2013 14:09

Re: Arduino + Ethernet Shield Help
 
All of the pins are fine except pin 4. Now for the code...

techhelpbb 09-08-2013 14:18

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1286662)
All of the pins are fine except pin 4. Now for the code...

I just looked at the SainSmart Ethernet Shield schematic and compared it to the Arduino R3 Ethernet Shield schematic. Pin 4 (Pin 0 is the first) is the chip select for the microSD card on both schematics. It doesn't help that on the schematics they start numbering the pins at 1 but on the boards they start numbering the pins at 0. On a Seeed older revision ethernet shield without the microSD interface you can probably use pin 4. Also note that on the Arduino Ethernet Shield pin 4 is actually labeled on the silk screen as SDCS where as on the images of the SainSmart shield I found there is no label warning the end user.

Don't use pin 4 with either shield. You risk sending select to the microSD card and disabling your network interface.

Still the interface shouldn't get hot...maybe a bit warm...so let's continue.

jwallace15 09-08-2013 14:21

Re: Arduino + Ethernet Shield Help
 
Ok. Will not use pin 4.

I don't use a Micro SD card in the ethernet shield anyway.

Back to the programming. I don't see what is wrong with it, in the book it said adding another line with the same code (just a different D#) would work.

Edit: I think I know what I did wrong. I didn't copy a line saying "client.print" on accident.

Yes, that was the problem.

techhelpbb 09-08-2013 14:28

Re: Arduino + Ethernet Shield Help
 
Quote:

Originally Posted by jwallace15 (Post 1286670)
Yes, that was the problem.

Sounds like you got it working.


All times are GMT -5. The time now is 16:48.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi