Reply to topic  [ 44 posts ]  Go to page 1, 2, 3, 4, 5  Next
Ethernet Module (HCARDU0028) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 631
Post Ethernet Module (HCARDU0028)
Image

Order yours here

ENC28J60 Ethernet Module utilizes the new Microchip ENC28J60 Stand-Alone Ethernet Controller IC featuring a host of features to handle most of the network protocol requirements. This Ethernet LAN module connects directly to most microcontrollers.

Features
Ethernet LAN Module for Arduino/AVR/LPC/STM3
ENC28J60 Ethernet chips
Can be easily mounted with the MCU
Network Interface: HR911105A
Supply Voltage: 3.3 V (5V Tolerant DIO)
25Mhz crystal oscillator
Size (L x W x H): Approx. 2.3 x 1.3 x 0.7 inch / 58 x 34 x 17 mm


    PINOUT
    1.....CLK OUT
    2.....INT
    3.....WOL
    4.....SO
    5.....SI
    6.....SCK
    7.....CS
    8.....RES
    9.....+3.3V
    10....GND



Edit:
This post has now been updated to use the newer and currently maintained Arduino etherCard libraries. A new sketch had also been added to provide an example of how to use this new library with your ethernet module. If you are using V1.0 or above of the Arduino software environment, we recommend using this new library and sketch.


Schematic:
Image

Arduino Libraries:
etherCard library
Attachment:
ethercard-master.zip


Out of date pre V1.0 Arduino environment library:
Attachment:
Ethernet_Module_HCARDU0028_libraries.zip


Example Arduino sketch for etherCard library:
Code:
/* FILE:    ENC28J60_Ethernet_Module_Example
   DATE:    10/06/13
   VERSION: 0.1

This is an example of how to use the Hobby Components ENC28J60 Ethernet
module (HCARDU0028).

To use this sketch you will need to download and install the EthernetCard library
available at the following location:

https://github.com/jcw/ethercard

Alternatively, a known working snapshot can be downloaded from the microduino section
of our support forum:

http://forum.hobbycomponents.com/

This example program will serve a basic webpage at the ip address specified below.
As an example of content, the webpage contains the current status of the analogue input
pins.

CONNECTIONS:

ETHERNET MODULE       UNO/NANO
PIN 1  (CLK OUT)      N/A
PIN 2  (INT)          N/A
PIN 3  (WOL)          N/A
PIN 4  (SO)           DIO 12
PIN 5  (SI)           DIO 11
PIN 6  (SCK)          DIO 13
PIN 7  (CS)           DIO 8
PIN 8  (RES)          N/A
PIN 9  (VCC)          +3.3V
PIN 10 (GND)          GND


REVISIONS:

V0.1 Initial version


You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.

*/


/* Include the EtherCard library */
#include <EtherCard.h>

/* The IP address of the module. Make sure this matches the IP
   address range of your network and that it is not in use by any other
   device on it */   
static uint8_t IPaddress[] = { 192,168,1,55 };

/* The gateway IP address of your router */
static uint8_t GatewayIP[] = { 192,168,1,1 };

/* MAC address of the ethernet shield. If you are using this on your
own network then the MAC address below will be fine, but remember if
you use more than one module on your network they will need to be assigned
unique MAC addresses */
static uint8_t MACAddress[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};

/* Create a buffer for send and receive data */
byte Ethernet::buffer[500];
BufferFiller bfill;


void setup()
{
  /* Initialise the ethernet interface */
  if (ether.begin(sizeof Ethernet::buffer, MACAddress) == 0)
  {
    /* If it failed to initialise then do nothing */
    while(1);
  }
  /* Else set up a fixed IP address */
  ether.staticSetup(IPaddress, GatewayIP);
}


/* Main program */
void loop()
{
  /* Get length of recived packet */
  word PacketLength = ether.packetReceive();
 
  /* Has a valid packet been received? If so, then send the web page */
  if (ether.packetLoop(PacketLength)) 
    ether.httpServerReply(ExampleContenet());
}

/* An example web page which returns the state of the analogue inputs */
static word ExampleContenet()
{
  bfill = ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    /*"Pragma: no-cache\r\n"*/
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"   
    "<big><span style=\"font-weight: bold;\">www.hobbycomponents.com"
    "<br>Microduino Ethernet Example:</span></big><br>"
    "*******************<br>"
    "Analogue Pin A0.....$D<BR>"
    "Analogue Pin A1.....$D<BR>"
    "Analogue Pin A2.....$D<BR>"
    "Analogue Pin A3.....$D<BR>"
    "Analogue Pin A4.....$D<BR>"
    "Analogue Pin A5.....$D<BR>"
    "*******************<br>"),
    /* Read the analogue inputs */
    analogRead(0),analogRead(1),analogRead(2),analogRead(3),analogRead(4),analogRead(5));
  /* Return the current buffer position */
  return bfill.position();
}



Example Arduino sketch for older pre V1.0 library.

Code:
/* FILE:    ARD_Ethernet_Module_HCARDU0028_Example.pde
   DATE:    28/07/12
   VERSION: 0.1

This is an example of how to use the HobbyComponents Arduino module shield
(HCARDU0028). For this example to work you will need to download the appropriate
libraries available at:
http://forum.hobbycomponents.com/viewtopic.php?f=25&t=6

Unzip the libraries and copy them to your Arduino libraries folder.

This program will serve a basic webpage at the ip address specified below which will
allow you change the state of 4 relays. This program is intended to work with arduino
relay modules such as the HobbyComponents 4 channel relay module (HCARDU0025).


CONNECTIONS:

ETHERNET MODULE       ARDUINO BOARD
PIN 1  (CLK OUT)      N/A
PIN 2  (INT)          N/A
PIN 3  (WOL)          N/A
PIN 4  (SO)           DIO 12
PIN 5  (SI)           DIO 11
PIN 6  (SCK)          DIO 13
PIN 7  (CS)           DIO 10
PIN 8  (RES)          N/A
PIN 9  (VCC)          +3.3V
PIN 10 (GND)          GND


You may copy, alter and reuse this code in any way you like but please leave
reference to HobbyComponents.com in your comments if you redistribute this code. */

/* Include both ethernet libraries */
#include "etherShield.h"
#include "ETHER_28J60.h"

#define RELAY1_DIO 2  /* DIO pin used to drive relay 1 */
#define RELAY2_DIO 3  /* DIO pin used to drive relay 2 */
#define RELAY3_DIO 4  /* DIO pin used to drive relay 3 */
#define RELAY4_DIO 5  /* DIO pin used to drive relay 4 */

#define RELAY1_MASK 0 /* Bit mask for storing state of relay 1 */
#define RELAY2_MASK 1 /* Bit mask for storing state of relay 2 */
#define RELAY3_MASK 2 /* Bit mask for storing state of relay 3 */
#define RELAY4_MASK 3 /* Bit mask for storing state of relay 4 */


/* Used to store the current state of the relays */
int RelayState = 0;

/* MAC address of the ethernet shield. If you are using this on your
own network then the MAC address below will be fine, but remember if
you use more than one shield on your network they will need to be assigned
unique MAC addresses */
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; 
                                           
                                           
/* The IP address of the shield. Make sure this matches the IP
   address range of your network and is not in use by any other
   device on it */                                     
   
static uint8_t ip[4] = {192, 168, 1, 55}; 

/* The port number the shield will respond to. Use port 80
   for standard HTTP requests */

static uint16_t port = 80;                                     

ETHER_28J60 e;



/* Initialise the ethernet interface and DIO pins */
void setup()
{
  e.setup(mac, ip, port);
  pinMode(RELAY1_DIO, OUTPUT);
  pinMode(RELAY2_DIO, OUTPUT);
  pinMode(RELAY3_DIO, OUTPUT);
  pinMode(RELAY4_DIO, OUTPUT);
}

/* Main program */
void loop()
{
  char* EthernetData;
 
  /* Has a page request been made? */
  if (EthernetData = e.serviceRequest())
  {

    /* Has the page link for relay 1 been pressed? */
    if (strcmp(EthernetData, "?relay=1") == 0)
    {
      /* If so then change the state of relay 1 */
      if (bitRead(RelayState, RELAY1_MASK))
      {     
        bitClear(RelayState, RELAY1_MASK);
        digitalWrite(RELAY1_DIO, LOW);
      }else
      {
        bitSet(RelayState, RELAY1_MASK);
        digitalWrite(RELAY1_DIO, HIGH);
      }
    }
   
    /* Has the page link for relay 2 been pressed? */
    if (strcmp(EthernetData, "?relay=2") == 0)
    {
      /* If so then change the state of relay 2 */
      if (bitRead(RelayState, RELAY2_MASK))
      {     
        bitClear(RelayState, RELAY2_MASK);
        digitalWrite(RELAY2_DIO, LOW);
      }else
      {
        bitSet(RelayState, RELAY2_MASK);
        digitalWrite(RELAY2_DIO, HIGH);
      }
    }
 
    /* Has the page link for relay 3 been pressed? */
    if (strcmp(EthernetData, "?relay=3") == 0)
    {
      /* If so then change the state of relay 3 */
      if (bitRead(RelayState, RELAY3_MASK))
      {     
        bitClear(RelayState, RELAY3_MASK);
        digitalWrite(RELAY3_DIO, LOW);
      }else
      {
        bitSet(RelayState, RELAY3_MASK);
        digitalWrite(RELAY3_DIO, HIGH);
      }
    }
   
    /* Has the page link for relay 4 been pressed? */
    if (strcmp(EthernetData, "?relay=4") == 0)
    {
      /* If so then change the state of relay 4 */
      if (bitRead(RelayState, RELAY4_MASK))
      {     
        bitClear(RelayState, RELAY4_MASK);
        digitalWrite(RELAY4_DIO, LOW);
      }else
      {
        bitSet(RelayState, RELAY4_MASK);
        digitalWrite(RELAY4_DIO, HIGH);
      }
    }
   
    /* Generate a new page with the current states of the relays */
    iUpdateRelays(RelayState);
   
    /* And send it back to the IP address that made the request */
    e.respond();
  }
}


/* This funtion generates a web page that shows the current state of
   the 4 relays and creates links to allow their states to be toggled.
   It requires a register of type int that holds the current state of
   the relays to be passed to it */

void iUpdateRelays(int RelayState)
{
    e.print("<H1>Web Remote</H1>");
   
    if (bitRead(RelayState, RELAY1_MASK))
    {
      e.print("RELAY 1: <A HREF='?relay=1'>ON</A><br>");
    }else
    {
      e.print("RELAY 1: <A HREF='?relay=1'>OFF</A><br>");
    }
   
    if (bitRead(RelayState, RELAY2_MASK))
    {
      e.print("RELAY 2: <A HREF='?relay=2'>ON</A><br>");
    }else
    {
      e.print("RELAY 2: <A HREF='?relay=2'>OFF</A><br>");
    }
   
    if (bitRead(RelayState, RELAY3_MASK))
    {
      e.print("RELAY 3: <A HREF='?relay=3'>ON</A><br>");
    }else
    {
      e.print("RELAY 3: <A HREF='?relay=3'>OFF</A><br>");
    }
   
    if (bitRead(RelayState, RELAY4_MASK))
    {
      e.print("RELAY 4: <A HREF='?relay=4'>ON</A><br>");
    }else
    {
      e.print("RELAY 4: <A HREF='?relay=4'>OFF</A><br>");
    }
   
}


You do not have the required permissions to view the files attached to this post.


Mon Aug 20, 2012 5:13 pm
Profile

Joined: Tue Aug 21, 2012 10:04 am
Posts: 1
Post Re: Ethernet Module (HCARDU0028)
Hi, thanks for the great info!

just the LINK to the lib is broken.

Also on Your shop page for this product!

Also the order No. for the Ethernet shield and for the relays shield is the same !
"HobbyComponents Arduino ethernet shield (HCARDU0028)"
"HobbyComponents 4 channel relay module (HCARDU0028)"

thx !


Tue Aug 21, 2012 10:11 am
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 631
Post Re: Ethernet Module (HCARDU0028)
Oops! A few cut and paste errors I think. Thanks for pointing them out, we will have them all corrected today. Including the link to the libraries.


Tue Aug 21, 2012 2:07 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 631
Post Re: Ethernet Module (HCARDU0028)
Should be fixed now!


Tue Aug 21, 2012 7:42 pm
Profile

Joined: Thu Jun 06, 2013 4:20 pm
Posts: 13
Post Re: Ethernet Module (HCARDU0028)
Hi all

Ordered this from you guys recently, it's arrived today - woohoo!

Got a slight problem though.. I've downloaded your libraries / samples and I'm seeing this when verifying all of them:
Image

There are no .h files in that archive to be found anywhere. I'm also seeing several undelcared type errors.

How do I use this then if your own code doesn't do it?

I can see there are lots of cpp files but I don't program in cpp or even have a compiler for it. With the number of errors in the arduino code that are reported I'm not sure I'd even want to try compiling the cpp code either :shock:

Where do I get these files from?:
etherShield.h
ETHER_28J60.h


Thu Jun 06, 2013 6:09 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 631
Post Re: Ethernet Module (HCARDU0028)
Hi,

I have checked the attached zip file containing the libraries and both .h files you mention do seem to be there. When you unzip the download you should see two folders:

ETHER_28J60
etherShield

The ETHER_28J60.h file is in the top level of the ETHER_28J60 folder and the etherShield.h is in the top level of the etherShield folder. You need to copy these two folders to your (assuming you are using windows) C:\Users\username\Documents\Arduino\libraries folder for the example code to work.

Andrew


Thu Jun 06, 2013 7:00 pm
Profile

Joined: Thu Jun 06, 2013 4:20 pm
Posts: 13
Post Re: Ethernet Module (HCARDU0028)
Hi Andrew,

Ok I see where they are (no idea how I missed those but I was also influenced by the error messages).

Anyway yes they are indeed there as you say however since copying the folders back into my libraries folder and starting arduino 1.0.1 again, I open the EchoParams sketch and hit verify and get this lot :( :

Quote:
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:18:55: error: WConstants.h: No such file or directory
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c: In function 'enc28j60ReadOp':
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:46: error: 'LOW' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:46: error: (Each undeclared identifier is reported only once
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:46: error: for each function it appears in.)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:60: error: 'HIGH' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c: In function 'enc28j60WriteOp':
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:66: error: 'LOW' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:73: error: 'HIGH' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c: In function 'enc28j60ReadBuffer':
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:78: error: 'LOW' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:92: error: 'HIGH' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c: In function 'enc28j60WriteBuffer':
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:97: error: 'LOW' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:109: error: 'HIGH' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c: In function 'enc28j60Init':
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:163: error: 'OUTPUT' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:164: error: 'HIGH' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:170: error: 'INPUT' undeclared (first use in this function)
C:\Users\<user>\Desktop\arduino-1.0.1\libraries\etherShield\enc28j60.c:173: error: 'LOW' undeclared (first use in this function)


EEK!


Thu Jun 06, 2013 7:22 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 631
Post Re: Ethernet Module (HCARDU0028)
Bare with me and I'll sent one up now...


Thu Jun 06, 2013 7:44 pm
Profile

Joined: Thu Jun 06, 2013 4:20 pm
Posts: 13
Post Re: Ethernet Module (HCARDU0028)
Ok mate thanks :)

Also I realise what I did wrong the first time - I copied out the four folders from the examples folder instead of the two folders higher up (sorry about that - feel very stupid!).

I've just done a search in my entire arduino directory for *.h and there is no WConstants.h file to be found and thats the first error!

I'm using arduino 1.0.1 if thats any help?


Thu Jun 06, 2013 7:48 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 631
Post Re: Ethernet Module (HCARDU0028)
The sketch and libraries compile ok for me (V1.0.4 of the sdk).

The errors you are getting are very odd, can you just check if the blink application (File->Examples->Basics->Blink) will compile ok ?


Thu Jun 06, 2013 8:03 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 44 posts ]  Go to page 1, 2, 3, 4, 5  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD