SparkFun Forums 

Where electronics enthusiasts find answers.

Everything pertaining to the service, the phant project which powers it, and user projects which talk to the service.
By WaggaBob
Hi everyone!
I'm trying to break from the norm here by making my first post on these forums an answer rather than a question :D I saw these very cheap ethernet modules (Australian $8) which are know as ENC28j60. Way cheaper than the usual ethernet shields or adaptors I've seen so I grabbed one to muck around with. It's taken several days of fiddling but it's now posting happily to "". Below are some short snippets that might help someone else looking to use these modules, it's the stuff I wish I found a week ago when I googled "ENC28j60, phant" etc.

There are two libraries, Ethercard and UIPEthernet. I tried UIPEthernet, it's quite big and didn't seem to be quite the "drop in replacement" for the official Arduino ethernet library that it's claimed to be. So I tried using Ethercard... wow that's tricky to get sending data to Sparkfun! I ended up going back to UiPEthernet and it's now working but taking up a lot of memory.

Wiring - the CS pin goes to d8 if using the ethercard library but d10 if you use UIPEthernet!

I reduced my serial speed to 9600 otherwise I just got rubbish on the serial monitor. I think this was the problem with UIPEthernet at first.

And finally here is the code below, I've taken out a bunch of comments to try and keep the sketch size down (it's about 93%). I'm using a waterproof temperature sensor on the Dallas One-Wire system for the PC power supply temp and a DHT11 temperatiuree/humidity sensor for the room.
Code: Select all
#include <SPI.h> // Required to use Ethernet
#include <UIPEthernet.h> // The UIPEthernet library includes the client
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

#define DHTPIN 3     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11

// Enter a MAC address for your controller below.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server(54,86,132,254);
EthernetClient client;

const String publicKey = "aGLo40WVjwS33J9EAqmy";
const String privateKey = "---insert your private key here---";
const byte NUM_FIELDS = 3;
const String fieldNames[NUM_FIELDS] = {"pc_temp", "room_temp", "room_humidity"};
String fieldData[NUM_FIELDS];

float heat;

void setup()
  sensors.begin(); // Start up the library
  setupEthernet(); // Set Up Ethernet
  Serial.println(F("=========== Ready to Post ==========="));

void loop()
    // Get temperature from One-wire sensor

    // Get room temperature and humidity from DHT11
    //roomTemp = dht.readTemperature();
    //humid = dht.readHumidity();
    // Gather data:
    fieldData[0] = heat;
    fieldData[1] = dht.readTemperature();
    fieldData[2] = dht.readHumidity();
    Serial.println("Data to post:");
    for (int i=0; i<NUM_FIELDS; i++)
      Serial.print(" = ");
    postData(); // the postData() function does all the work, check it out below.


void postData()
  // Make a TCP connection to remote host
  if (client.connect(server, 80))
    // Post the data! Request should look a little something like:
    // GET /input/publicKey?private_key=privateKey&temp=24 HTTP/1.1\n
    // Host:\n
    // Connection: close\n
    // \n
    client.print("GET /input/");
    for (int i=0; i<NUM_FIELDS; i++)
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println("Connection: close");
    Serial.println(F("Connection failed"));

  // Check for a response from the server, and route it
  // out the serial port.
  while (client.connected())
    if ( client.available() )
      char c =;

void setupEthernet()
  Serial.println("Setting up Ethernet...");
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    // Ethernet.begin(mac, ip);
  Serial.print("My IP address: ");
  // give the Ethernet shield a second to initialize:

void sensorReqTemp()
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  sensors.requestTemperatures(); // Send the command to get temperatures
  heat = (sensors.getTempCByIndex(0));
  // Serial.println(heat); // Why "byIndex"? 
  // You can have more than one IC on the same bus. 
  // 0 refers to the first IC on the wire
Hope that helps!
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]