I have been searching for the last 3 days for a way to get my ENC28J60 3.3V 25MHz Crystal Ethernet Network Board Module to link up with my Arduino Mega1280...i have tried the 10 - 13 pins and the 50 - 53 pins...i have tried the ethernet, ethershield, ethercard and enc28j60 libraries with no success...most of them fail on DHCP...What have i done wrong...here is a link to the module i have
One possibility might be to change the SPI definitions in enc28j60.c to fit your unique wiring. I would also suggest reinstalling the libraries and/or switch to IDE 1.0 . My enc28j60 doesn't seem to play well with IDE 1.0.1 or rather the libraries don't. I spent 3 days uploading and quadruple checking connections before I decided to start fresh with the older version that I know worked with it a few months back. works for me now...
I got it to work BUT...now i am having a code issue while modifying the light sketch for it...here is what i have:
// A simple web server that turn an LED on or off"
#include "etherShield.h"
#include "ETHER_28J60.h"
int outputPin = 6;
int LED[10] = {13,12,10,9,8,7,6,5,4,3};
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {192, 168, 0, 15}; // IP address for the webserver
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
Serial.begin(9600);
Serial.println("Start Setup");
e.setup(mac, ip, port);
pinMode(outputPin, OUTPUT);
Serial.println("END Setup");
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
Serial.println("Request");
e.print("<h1>Arduino Web Remote</h1>\n");
for(int x = 0; x < 10; x++)
{
//Here is where the issues start
if (strcmp(params, "?led=" + x) == 0)
{
Serial.print("LED HIT!!!");
Serial.println(x);
if(digitalRead(LED[x]) == HIGH)
digitalWrite(outputPin, LOW);
else
digitalWrite(outputPin, HIGH);
}
//Here is where the issues end
if(digitalRead(LED[x]) == HIGH)
{
e.print("<a href='?");
e.print(x);
e.print("'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED");
e.print(x);
e.print(" IS ON</button></a>\n");
}
else
{
e.print("<a href='?");
e.print(x);
e.print("'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED");
e.print(x);
e.print(" IS OFF</button></a>\n");
}
}
e.respond();
}
}
sorry bout that...posted it on the way out the door
it is supposed to display a page with 10 buttons for turning on and off LEDs...it displays everything correctly...it just isn't reading the params right
Showing us what appears in the address bar of the browser after the submit button is pressed, and what the serial output of the Arduino is would be the next step. Now, all we know is that you have a problem and what the problem is, but still no details. Good thing I'm patient. Sometimes. (A little foot tapping sound in the background).
i think the issue is in the if statement...when it iterate...ex:// x = 3...and the param to the page is ?3 and that is exactly what it needs, then it should run thru the if...but it doesn't
I can't recall a single example of an if statement failing to be executed the way it was written. What was executed may not have been what the programmer expected, but it wasn't a failure in the way the if statement was evaluated.
If you don't want to provide evidence to back up your assertions, all we can do is offer sympathy.
I think Nick is on to something. for my web remote I used a series of if. . .else if statements for each button. so when you do string compare on params to check for an exact match like this:
if (strcmp(params, "?led=" + x) == 0)
you might try doing something like this:
if (params = e.serviceRequest())
{
e.print("<h1><a href='/?relay1=off'>Arduino Web Remote</a></h1>"); // **take note of: <a href='/?relay1=off'> that is the important bit that the arduino looks at and decides what do **
e.print("<button type='button' onclick=location.href='?relay1=off'>RELAY1</button>"); // a button for relay1, notice: href='?relay1=off'
e.print("<button type='button' onclick=location.href='?fan=off'>FAN</button>"); // copy for more buttons to control more pins...
...
...
...
if (strcmp(params, "?relay1=on") == 0) // this statement looks at what comes directly after this bit from above: <a href='/... then you setup else if's to control pins
{
digitalWrite(relay1, HIGH); // set your relay high
e.print("<a href='?relay1=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>relay1 IS ON</button></a>");
e.print("
");
}
else if (strcmp(params, "?relay1=off") == 0)
{
digitalWrite(relay1, LOW);
e.print("<a href='?relay1=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>relay1 IS OFF</button></a>");
}
else if (strcmp(params, "?fan=on") == 0)
{
digitalWrite(fanPin, HIGH);
e.print("<a href='?fan=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>FAN IS ON</button></a>");
}
else if (strcmp(params, "?fan=off") == 0)
{
digitalWrite(fanPin, LOW);
e.print("<a href='?fan=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>FAN IS OFF</button></a>");
}
/* copy and paste else if's (2 for each relay- one to turn it on, the other 'else if' turns it off) so for 5 relays that should be one if statement followed
by 9 else if's */
e.respond();
}
if you have a way to do the same thing with a for loop, I would like to see it for my own learning
"?0" is a string, consisting of three chars - '?', '0', and NULL - not a single char.
Perhaps a (re)view of the sprintf() function is in your future. Or, look at the strncmp() function. If you know that the first n characters match, it is trivial to extract the n+1th character and convert it to a number (subtract '0' from the character).
Hi, I tried your code and it doesn't work for me - I think it even crashes the arduino.
I think you are using a mega? I tried it on a uno, I changed the output pins, as the enc module is on pins 10 to 13.
The startup goes ok - but as soon as I try to access the server, things get all weird. Lots of garbage on the serial port, and the page never completes loading. What url do you use to access it?
I try to go to the url - but I figured I needed parameters to get this working. Some examples I found needed parameters to work.
I'm new to ethernet, just trying out different librarys and programs, seeing what will work best for me. So far this library has been the only one that did anything at all.
When I open the serial window, I get the start setup-end setup messages, but when I try to access the webserver things go all weird.
SStart Setup
END Setup
ReqWÉÑSetup
END Setup
ReqWÉÑSetup
END Setup
Re¹WÉÑSetup
END kE?ÉÑSetup
ENDkE?ÉÑSetup
ENDkE?ÉÑSetup
END Setup
Re¹WÉÑSetup
I included my modified code:
#include "etherShield.h"
#include "ETHER_28J60.h"
int LED[8] = {2,3,4,5,6,7,8,9};
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {192, 168, 1, 15}; // IP address for the webserver
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
Serial.begin(9600);
Serial.println("Start Setup");
e.setup(mac, ip, port);
for(int x=0;x<8;x++)
{
pinMode(LED[x],OUTPUT);
digitalWrite(LED[x],LOW);
delay(200);
}
Serial.println("END Setup");
}
void loop()
{
char* params;
char buff[8];
if (params = e.serviceRequest())
{
Serial.println("Request");
e.print("<h1>Arduino Web Remote</h1>\n");
for(int x = 0; x < 10; x++)
{
sprintf(buff, "?%d", x);
Serial.println(buff);
if (strcmp(params, buff) == 0)
{
if(digitalRead(LED[x]) == HIGH)
digitalWrite(LED[x], LOW);
else
digitalWrite(LED[x], HIGH);
}
if(digitalRead(LED[x]) == HIGH)
{
e.print("<a href='?");
e.print(x);
e.print("'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED");
e.print(x);
e.print(" IS ON</button></a>\n");
}
else
{
e.print("<a href='?");
e.print(x);
e.print("'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED");
e.print(x);
e.print(" IS OFF</button></a>\n");
}
}
e.respond();
}
}