Arduino and Ethernet Module

Using the Deek-Robot NANO Ethernet Shield V1.0 and the UIPEthernet library, it is possible to add Ethernet capabilities to an Arduino microcontroller. The process is outlined in this excellent article: https://www.tweaking4all.com/hardware/arduino/arduino-enc28j60-ethernet/

A webpage served by the Arduino microcontroller gives you the opportunity to provide a nice, modern user interface to the users of your arduino project from any connected device be it a mobile device such as a smartphone or a desktop PC. You can connect hardware to the arduino which you can then control based on button clicks to the web page you serve to the local network via the Arduino web page. Besides webpages, the Arduino can now provide a REST-API which you could consume from a Angular-Application. REST-APIs allow you to seamlessly integrate the Arduino-Project into existing web applications.

This post documents the individual steps I took to follow the article on tweaking4all.

I used an Arduino UNO, the Deek-Robot NANO Ethernet Shield V1.0 (contains a ENC28J60 chip), Arduino IDE 1.8.9 and the UIPEthernet Sketch from the article on tweaking4all.

First, you have to install the UIPEthernet library into your Arduino IDE. The UIPEthernet library is needed, because the ENC28J60 does not work with the standard Ethernet libraries that ship with the Arduino IDE. The Arduino IDE allows the installation of libraries from Zip-Files. The Zip-File for the UIPEthernet library is conveniently retrieved by downloading the master branch of the Github Repository as a zip file: https://github.com/UIPEthernet/UIPEthernet > Clone or Download > Download zip. Once the zip file is contained on your harddrive, you can import it via the Arduino IDE’s installation feature: In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At the top of the drop down list, select the option to “Add .ZIP Library”. If the installation worked, the Arduino IDE will output: Library added to your libraries. Check “include library” menu.

Secondly, wire up the Deek-Robot board to your arduino. The page tweaking4all has a nice image on which pins have to be connected to which pins on the Arduino UNO. You need ground and 5V. My board did not die on 5V so I figure it is true that the Deek-Robot board contains a voltage converter that changes 5V to 3.3V. You have to connect the pins D10, D11, D12, D13 on the Deek-Robot board to the pins 10, 11, 12, 13 on the Arduino board in the same order (D10 is connected to 10, D11 is connected to 11, …). Also, connect a Ethernet cable between the Deek-Robot board and your home network.

Thirdly, you have to set up your router in your home network. Normally, every mac address that connects to the router gets a dynamic IP-Address assigned via DHCP which is a protocol that temporarily leases IP-Addresses to devices. Because DHCP’s use case is to connect a device that only consumes services on the network, the IP-Address is dynamic and not known before the device is connected. Without retrieving the devices IP from the device itself or from your router, you have no way to connect to the device to consume its services. The Arduino sketch contains a mac Address and a fixed IP-Address because we want to connect to the Arduino via a known IP-Address. To prevent DHCP from assigning a dynamic address, a rule is added to the router that assigns a fixed IP-Address to the mac-Address from the sketch. Weather your router is able to add rules and how to add a rule, I can not tell you because I do not know all the routers. Consult your router’s manual to add a rule. Add such a rule, then update the Sketch to contain the mac- and the IP-Address specified in the rule.

As a fourth step, you can now paste the sketch for the UIPEthernet library with correct mac and IP-Address set from tweaking4all into your Arduino IDE, connect your Arduino and Upload the sketch.

Once the sketch has been succesfully uploaded, open the IP address and port 80 in a web browser on a machine that is connected to your home network. Before connecting via the browser, you can open a serial terminal to the arduino. The Arduino will output information about a established connection into the serial terminal. Your browser will execute a GET-Request towards the Arduino Server and it will retrieve the small HelloWorld HTML-page that the sketch predefines. After serving the page, the connection is terminated by the Arduino server.

That is it! Basically if you know how to connect the board, install the library, set up a DHCP rule and after reading the article on tweaking4all, you can make your Arduino available in your home network. A downside of this approach is that the Deek-Robot board uses pins 10, 11, 12, 13 on your arduino. They are blocked for other boards. The next steps would be to figure out how to serve more resources than just the hello world webpage! How would you serve several pages connected to each other via hyperlinks for example? How do you server static resources such as CSS, JS and image files? Nevertheless, connecting the Arduino to the Ethernet network, enables your Arduino projects from your smartphone! A lot is possible. Have fun with your projects and thank you for reading this article.

Leave a Reply