Hello Arduino Web Server
May 21, 2015Recently, I developed a new passion for tinkering with IoT (Internet of Things) hardware and gadgets, especially with the Arduino ecosystem.
While most of these latest endeavors involved LEDs and making them blink in one or the other way, I decided to step up my game and add some networking capabilities to my Arduino projects.
The Hardware
On Amazon I found this really cheap (~7 €) Ethernet shield which would play nicely together with an Arduino Nano. It did not come with any instructions on wiring the pins whatsoever, but a quick internet search for ENC28J60 Arduino Wiring quickly yielded the desired information.
So, what it takes are 6 cables to connect following Arduino pins to their counterparts on the Ethernet shield:
Digital Pin 12 –> SO
Digital Pin 11 –> SI
Digital Pin 13 –> SCK
Digital Pin 8 –> CS
3V3 –> VCC
Gnd –> GND
If everything’s wired up correctly, a little LED on the Ethernet shield should light up. Also, the network activity LEDs should start blinking as soon as a network cable is plugged into the shield.
The Software
Now that we have the hardware running, let’s implement a tiny web server that shows a “Hello World” message.
To be able to use the Ethernet shield in our Arduino sketch, we have to import the Ethercard library using these steps:
- Download the zip archive of this library from https://github.com/jcw/ethercard/archive/master.zip.
- Then, choose Sketch | Include Library | Add .ZIP Library … in Arduino Studio and browse to the downloaded archive.
- Restart Arduino Studio and you get a lot of cool samples in File | Examples on how to use the Ethercard library.
I took e.g. the rbbb_server example, which implements a tiny web server and adapted it for my purposes.
Make sure you always adjust the IP address and MAC address constants in these samples!
You can find the full source code for this demo web server on GitHub if you want to play around with it.
But basically it does right now is displaying a "Hello World” message.
And it changes the font color to red if the URL query string requests that.
What’s Next?
This served mainly as a proof of concept for another Arduino project I am currently working on. It involves controlling an RGB LED strip from the network and more and more parts of this project are coming together right now. So stay tuned, folks!