Project:Nanode/Applications: Difference between revisions
From London Hackspace Wiki
→EtherShield Library and Examples
| Line 95: | Line 95: | ||
===EtherShield Library and Examples=== | ===EtherShield Library and Examples=== | ||
Once you have built your Nanode and got the red flashing LED which shows that all is well with the ATmega328 microcontroller and it's bootloader programme, it is now time to test the rest of the system, which includes the ENC28J60 ethernet controller and its interface through the magjack connector to the ethernet port. | |||
Conveniently, Andrew Lindsay, has provided some simple example to accompany his Ethershield Library. It is common practice amongst Arduino libraries to provide accompanying tried and tested code examples, which are loaded as part of the library folder. | |||
First you need to download and install the EtherShield library from GitHub | First you need to download and install the EtherShield library from GitHub | ||
https://github.com/thiseldo/EtherShield | https://github.com/thiseldo/EtherShield | ||
Make sure you have Arduino 0021 or better still 0022 installed. | Make sure you have Arduino 0021 or better still 0022 installed, and press the download button. This will download the library as a .tar or .zip format into a temporary folder. Unzip the contents of this zip and put it in a folder named "Ethershield" within the Arduino/libraries folder. | ||
(Remove any previous version of Ethershield library - as this causes code compilation problems). | (Remove any previous version of Ethershield library - as this causes code compilation problems). | ||
When you restart the Arduino IDE, it will find this new library and add it into the Examples on the Files menu. | |||
'''DHCP Test''' | |||
Open Arduino IDE and select File/Examples/Ethershield/EtherShield_DHCPTest | |||
Scroll down the code until you find the lines | |||
Serial.println("Init ENC28J60"); | |||
es.ES_enc28j60Init(mymac); | |||
As this routine is used for several hardware implementations that use the ENC28J60, we have to make one small change to suit the Nanode. Nanode uses Digital 8 to select the ENC28J60 - so change this code to | |||
Serial.println("Init ENC28J60"); | |||
es.ES_enc28j60Init(mymac,8); | |||
Press the save button from the tool bar - a downward pointing arrow to save this change for later. | |||
Now make sure that you have the correct serial port connected from Tools/Serial Port and that the Board type has been selected as Arduino Duemilanove or Nano w/ATmega 328 - the second option down the list. | |||
You may now compile and upload the code to the Nanode using the Upload button (right pointing arrow) | |||
After several seconds the Arduino IDE will respond | |||
Binary sketch size: 9976 bytes (of a 30720 byte maximum) | |||
The actual number of bytes may vary if you use Arduino 21 - as there has been some code optimisation in Arduino 22 | |||
Wait for the IDE to respond with Done Uplading. | |||
The Arduino code normally starts up about 2 seconds after the end of the download. | |||
Now we open up the Serial Monitor (Monitor Icon on Toolbar - rightmost button) | |||
This opens up a serial terminal window so that we can look at the debug output from the program. | |||
In the bottom right hand corner of this monitor window is a selection box allowing you to select different baud rates. The default is 9600 baud. Change this to 19200 baud - as this is the rate as defined in the current EtherShield_DHCPTest programme in the line in the Setup() code: | |||
Serial.begin(19200); | |||
Make sure that you have connected your Nanode to your router or hub | |||
Opening the serial monitor automatically resets the Nanode, so after 2 seconds you should see the following serial debug text: | |||
DHCP Client test | |||
54:55:58:12:34:56 | |||
Init ENC28J60 | |||
Init done | |||
ENC28J60 version 7 | |||
Sending initial DHCP Discover | |||
My IP: 192.168.0.6 | |||
Netmask: 255.255.255.0 | |||
DNS IP: 192.168.0.1 | |||
GW IP: 192.168.0.1 | |||
These lines of text are produced as simple Serial.print or Serial.println (followed by newline character) statements - such as | |||
Serial.println("DHCP Client test"); | |||
54:55:58:12:34:56 is a made up MAC address - a throwback from the original Tuxgraphics code where 54:55:58: is ASCII for TUX | |||
Then we initialise the ENC28J60 IC, over it's SPI bus. If this is successful we will get | |||
ENC28J60 version 7 (or some other non-zero version number) | |||
If you get ENC28J60 version 0 - this means that the ATmega has failed to make contact with the ENC28J60 - and this is often a soldering fault on the PCB. If you have an ohm-meter, make sure that pin 14 of the ATmega (Digital 8) has good continuity with pin 9 of the ENC28J60 - AND that it is not shorted to 0V, +5V, +3V3 or any other nearby signal which would prevent it from switching cleanly between levels. Dig 8 comes very close to the 3V3 connector on the "Wireless" connector - an easy place to get a solder short. | |||
Note: | Note: | ||