Trouble Programming ENC28J60 with Ethercard

Hello,
I am having trouble creating a sketch for my project. So far the only example sketch that i have been able to access through the internet is the back soon sketch. I have been able to add in a bar that allows the user to input text onto the webpage, but I am unsure of how to send the characters to the arduino board. I would also like the webpage and arduino UNO board to respond to input that the user adds in. Any advice would be greatly appreciated, my problem may be simple for many but I am new to programming. Thanks for the help,
Tyler

TWeiss33:
Hello,
I am having trouble creating a sketch for my project. So far the only example sketch that i have been able to access through the internet is the back soon sketch. I have been able to add in a bar that allows the user to input text onto the webpage, but I am unsure of how to send the characters to the arduino board. I would also like the webpage and arduino UNO board to respond to input that the user adds in. Any advice would be greatly appreciated, my problem may be simple for many but I am new to programming. Thanks for the help,
Tyler

hi, you're following the route that i took as well.
for anything beyond that back soon sketch it gets quite complicated, and for a beginner - not just to programming, but to the whole world of Ethernet and HTTP requests & TCP protocols, etc - it gets very daunting.
the optimal way would've been to start with the Ethernet shield that uses the Wiznet chip (W5100 or W5200) as that uses the "standard" (or more common) Ethernet library that Arduino uses.
the ENC28J60 has a lot more "stuff" that needs to be done, which the W5100 chip has built-in in the hardware.
you do end up learning more though - but it makes the "adventure" that much more difficult.
if you want a client, have a look at the EtherCard example : webClient and if you want a server, the rbbb_server example, BUT if you want interactive pages, also what i was hoping to do, you need to be more familiar with HTTP requests & the protocols like TCP & UDP, etc - it's quite overwhelming !

i would suggest to have a look at this thread;

it is a new library that is built for the ENC28J60 (like the EtherCard) except it tries to translate all the functions so that it's exactly like the "standard" Ethernet library used by the Arduino IDE.

i have just begun "migrating" to it because the general consensus is that the ENC28J60 is not really suitable for someone still starting out, and this new UIPEthernet library should help make the learning easier for beginners, plus that thread is started by the developer of the library himself.

Yes, thank you, that library looks much more simple than the ethercard one. However, I am still encountering a few minor problems. I have moved the CS pin to digital pin 10 (I have tried 8 also) on the Arduino, but every time I type in the IP address (192.168.1.6) I get an error saying the server is taking to long to respond. I did notice in the backsoon sketch on the ethercard library (the only sketch that has been successful for me) that the IP address in the code is not the same one that the UNO prints to the serial monitor. The IP address in the code is 192.168.1.200 which then somehow gets turned into 10.0.0.16 on the serial monitor. When I type the address shown in the code I get the "server is taking to long to respond" error but when i type in the 10.0.0.16 the backsoon webpage comes up just fine.

could you post the code that you are running ?
use the CODE (#) tags above the smileys.

This is the backsoon example sketch that has worked for me. The other UIP sketch i used was the same sketch that was posted on the forum you gave me a link to. Thanks again for the help!

#include <EtherCard.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.
"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}

TWeiss33:
This is the backsoon example sketch that has worked for me. …

yes, the BackSoon sketch is also as far as i’d had success with the EtherCard library - the IP change is actually “normal”, see here;

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

#[color=blue][b]if[/b][/color] STATIC
...
...

i’m dropping using EtherCard (for now) and just trying to learn to use the UIPEthernet library, try the sketch Examples; EchoServer.ino and TcpServer.ino.

you will have to use telnet and not your browser to test the connections though, or just PING from the command line. (DOS prompt)
the eventual IP address that shows is what has been assigned by the router/DHCP server.

retronet_RIMBA1ZO:
the eventual IP address that shows is what has been assigned by the router/DHCP server.

So will I have to go to my router to find the eventual IP address assigned to my enc28j60 module for the sketches in the UIP library, or does the UIP library not set up a new IP address with dhcp or the router?

it's "either or" - if you choose to use DHCP, then the router will determine the IP address for you.
if you're thinking of setting up a server, some cases might call for static IPs, in which case you determine the IP address by setting it up accordingly in the code.

i'm just experimenting with this myself really, haven't tried it extensively but my router sometimes gets "upset" when i determine the IP address and then try other things - ddns-related, ie. setting up a website (of sorts) on the Arduino !

have a look at this page;

infact, the great thing about this UIPEthernet library is that users of the ENC28J60 module can then avail themselves of the resources here on the Arduino website for the Ethernet library which is based on the Wiznet chips (Arduino Ethernet Shield).

have you read through the "mother thread" of the UIPEthernet library ? it's a LOT to wade through, but at least skim through it to give yourself an idea of what sort of questions you can then ask.

retronet_RIMBA1ZO:
have you read through the "mother thread" of the UIPEthernet library ?

I have not seen or heard about the mother thread of a Library, or for this library specifically. Does it come with the library or is it located on a developers website?

TWeiss33:

retronet_RIMBA1ZO:
have you read through the "mother thread" of the UIPEthernet library ?

I have not seen or heard about the mother thread of a Library, or for this library specifically. Does it come with the library or is it located on a developers website?

oh sorry, that was my term for it.
it's actually here on this forum, i gave a link to it before new library UIPEthernet: uIP adapted to Arduino for ENC28J60 - Networking, Protocols, and Devices - Arduino Forum
it should have a link to the source code on github if you want to see all the details about it.

I have problem with UIPEthernet library, until now i can not find solution for it so i use different library such as Ethercard and EtherShield but compiled code size using this library is big. :frowning: