Project:Nanode/Applications: Difference between revisions
m (→IPv6 and uIP) |
|||
(144 intermediate revisions by 34 users not shown) | |||
Line 1: | Line 1: | ||
===Nanode Applications=== | |||
Nanode is an Arduino like 8 bit microcontroller board with integrated Ethernet connectivity. | |||
It has 6 analogue sensing channels and 6 spare digital I/O lines. | |||
It can be used for a variety of web connected applications including remote control and monitoring, as a smart sensor, home automation, as a Tweeting device, and for publishing small amounts of data to the web. | |||
The existing software allows it to be set up as an I/O webserver - a device which sends the state of its analogue and digital I/O to a web page - and which can be controlled from that webpage. | |||
However it is not restricted to just that role, it can act as a publisher device and send data to an intermediary open data service such as Pachube, and it can act as a web connected I/O device, which subscribes to a Pachube data feed and acts according to the data received from that feed - for example setting its I/O, updating a display or controlling some actuator device. | |||
By using Pachube's API as a smart intermediary, much of the burden of serving an interractive webpage is eliminated from the Nanode. | |||
A final application, uses an interpreted language called [http://bitlash.net/wiki/start Bitlash] which allows scripts to be written and stored in EEprom on the microcontroller or on an external SD card. We are developing a Telnet aopplication which would allow a Nanode running bitlash to be remotely reconfigured to run a different script. | |||
Nanode has a lot in common with the Tuxgraphics Web Server - in fact the Tuxgraphics TCP/IP stack was ported to Arduino, and thence onto Nanode. | |||
Here's an [http://tuxgraphics.org/electronics/200905/embedded-tcp-ip-stack.shtml article] with a lot of the background information to how the stack works and how it serves small web pages efficiently. | |||
==Before You Start== | |||
You now have a flashing red LED which shows that the bootloader and Blinky program is running on the microcontroller , and are keen to connect to the internet. If you are unfamiliar with Arduino, you might wish to visit the extensive reference and examples pages linked to the main [http://www.arduino.cc/ Arduino Homepage] site. | |||
Nanode is essentially just an Arduino with ethernet connectivity added - so anything that you can do on Arduino, you should be able to do with Nanode. | |||
The easiest way for newcomers to access Nanode is to use the Integrated Design Environment (IDE) provided with Arduino. However, more experienced C coders may wish to use the open source GCC C compiler directly with AVRdude or the toolset provided by Atmel in AVR Studio. | |||
In short - there are several ways to skin the cat called Nanode. | |||
Note there are some slight differences, the LED on Nanode is on Digital 6 rather than Digital 13 on Arduino and it lights when digital 6 is set LOW - so its sense is inverted - more on why this is later. | |||
Nanode uses an ethernet library which was written specifically to drive the ENC28J60 ethernet controller. | |||
This device is used on several similar designs, and it must be noted that the library needs to be tailored so that it correctly addresses the ENC28J60 via digital pin 8, and not pin 10 as used in some ENC28J60 based ethernet shields. | |||
To do this look at the DHCP test sketch and identify the line | |||
es.ES_enc28j60Init(mymac); | |||
for Nanode version 5 users this should be changed to: | |||
es.ES_enc28j60Init(mymac,8); | |||
Pin 8 is the pin used by the microcontroller to select the ENC28J60 for the SPI bus and if you don't add this, the MCU won't be able to communicate with the ENC28J60. | |||
If you forget to do this, when you first power up there will be a message | |||
ENC28J60 Version 0 | |||
This will appear as ENC28J60 Version 7 after the change has been made and you will know that all is well. | |||
We are in the process of creating a Nanode specific library that defaults to pin 8, so this change will not be needed in the future. | |||
==Nanode and Pachube - Upgrade to a Free Pachube Pro Account== | |||
Nanode owners who have bought Nanodes through the London Hackspace may contact Pachube to receive a free Pro Account. | |||
Pachube have been very supportive of the Nanode Project with this generous gesture to get a lot more Nanodes using Pachube and developing interesting applications. Contact Ed Borden at the email address below to collect your free Pro user account. | |||
From Ed Borden, Pachube, New York. | |||
"We are really excited about this project here at Pachube. We want to | |||
give our full support to anyone who has the gumption to take this | |||
thing and pull it along to the next level. I don't care if you | |||
haven't tested the first run yet! :) Full steam ahead! | |||
For any of you guys on this list who bought a Nanode from Ken and want | |||
to connect it up to Pachube, drop me a line with your username and | |||
I'll upgrade your account to Pro. And when you do something awesome | |||
that you want the world to know about, tell us about it!" | |||
edborden at pachube dot com | |||
==Testing Nanode== | ==Testing Nanode== | ||
The ATmega328 microcontroller supplied with the kit has a specially modified version of the Arduino bootloader pre-programmed into it. | The ATmega328 microcontroller supplied with the kit has a specially modified version of the Arduino bootloader pre-programmed into it, together with an initial program to flash the red LED. | ||
Arduino usually has a LED wired to | Arduino usually has a LED wired to digital pin 13, but in Nanode, digital 13 is in almost constant use as the SPI Clock so in the Nanode bootloader the LED flashing function has been altered so that it flashes the red LED which is wired to digital pin 6. | ||
If all is well with your Nanode board the red LED should start flashing about 2 seconds after the power (from USB or FTDI cable) has been applied. | |||
If all is well with your Nanode board | |||
If it does not flash, check for faults such as missing soldered joints or the LED incorrectly inserted. | If it does not flash, check for faults such as missing soldered joints or the LED incorrectly inserted. | ||
==Applications== | ==Applications== | ||
===Quick Tutorial=== | |||
Read this and the following EtherShield Examples sections to familiarise yourself with the basic operations of the Arduino IDE: programming, compiling and uploading code to the Nanode. | |||
'''Note that EtherShield is spelt with a capital E and a capital S. You may get compilation problems if you deviate from this spelling.''' | |||
The first couple of examples will help you confirm that your hardware is fully functional and that you can get a DHCP address and serve a simple webpage from your Nanode. | |||
1. Download and Install Arduino Environment | |||
http://arduino.cc/en/Main/Software | |||
*Windows users: open the arduino-0022 folder and run Arduino.exe | |||
*Mac users: mount the dmg and drag arduino into Applications folder | |||
*Ubuntu users (tested on 10.10): sudo apt-get install arduino | |||
2. Select the Appropriate Board Type | |||
In the Arduino application menu Tools/Board select "Arduino Duemilanove or Nano w/ ATmega328" | |||
3. Download FTDI (or SiLabs) Cable Drivers | |||
3a. NOTE: The US-based version from Wicked Device tends to come with a cable that uses a chip from Silicon Labs instead of FTDI. Drivers for OSX or Windows (Linux doesn't need them) can be downloaded directly from [http://http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx Silicon Labs]. [http://wiki.xinchejian.com/wiki/Nanode,_USB_FTDI,_OSX10.7 Here's] a nice writeup that explains it all. | |||
Plug in the FTDI programming cable. | |||
*Windows users: when prompted to install drivers, point the installer to the arduino-0022/drivers directory | |||
*Mac users: mount the arduino installation dmg and double click on the FTDI install package at the bottom of the window | |||
*Linux users: if you are using a recent version of Ubuntu or Debian, the FTDI cable should be plug and play; type: | |||
dmesg | grep "ttyUSB*" | |||
into terminal and hit return. The response may look something like this: | |||
[ 7440.284623] usb 2-2: FTDI USB Serial Device converter now attached to ttyUSB0 | |||
or | |||
[ 8002.670918] usb 2-2: cp210x converter now attached to ttyUSB0 | |||
since ttyUSB0 is mentioned this indicates that the device mount point is /dev/ttyUSB0 | |||
4. Select the Appropriate Serial Port | |||
In the Arduino application menu Tools/Serial Port select the appropriate device, e.g., "/dev/tty.usbserial-A400f2he" on a Mac or "/dev/ttyUSB0" on Linux. | |||
5. Download EtherShield Libraries | |||
Download here: https://github.com/thiseldo/EtherShield | |||
Change the downloaded folder name to "EtherShield" and place in Arduino libraries folder: | |||
*Mac users: make a folder called "libraries" in Documents\Arduino\ then place the EtherShield folder into the newly created libraries folder. | |||
*Windows users: place the EtherShield folder into arduino-0022\libraries\ | |||
*Linux users: place the EtherShield folder into arduino-0022/libraries/ (or /usr/share/arduino/libraries/ ?) | |||
6. Download the NanodeMAC Library | |||
Download here: https://github.com/thiseldo/NanodeMAC | |||
If you're using an operating system with a case-sensitive filesystem (e.g., Linux) then edit NanodeMAC.cpp to delete (or comment out) the line: | |||
#include <wprogram.h> | |||
This is required because the correct name of the file is "WProgram.h" (in arduino-0022/hardware/arduino/cores/arduino/). There's no need to keep or correct this line as the file has already been included by NanodeMAC.h (which has already been corrected for case in the git repository). | |||
Place in the Arduino libraries folder as for EtherShield, above. | |||
Be sure to set the baud rate at 19200. | |||
===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 its bootloader program, 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 | |||
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). | |||
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 program 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 its 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. | |||
Assuming that the ENC28J60 initialises correctly, it will flash the yellow and green LEDs on the ethernet connector - simultaneously 3 times at about one second intervals. This confirms that the ENC28J60 has been initialised. | |||
The code then performs a DHCP discover - sending a DHCP request to the router. If this DHCP request is answered, it then populates the various IP arrays for myIP, gwIP, DNS_IP etc and prints them out to the serial terminal as follows. | |||
My IP: 192.168.0.6 | |||
Netmask: 255.255.255.0 | |||
DNS IP: 192.168.0.1 | |||
GW IP: 192.168.0.1 | |||
You have now completed the testing phase of the Nanode and can move onto some real applications. | |||
'''EtherShield_Webserver''' | |||
Rename Ethershield_webserver.pde to EtherShield_webserver.pde then re-start IDE. | |||
Now from the Files/EtherShield/Examples load the EtherShield_webserver sketch. | |||
Once again edit the initialisation line from (mymac) to (mymac,8) | |||
es.ES_enc28j60Init(mymac); | |||
es.ES_enc28j60Init(mymac,8); | |||
Also edit this line to match the IP address from the DHCP test | |||
static uint8_t myip[4] = { 192,168,0,6}; | |||
Now compile and upload the code to the Nanode board | |||
If successful you should first get the compilation report message: | |||
Binary sketch size: 6422 bytes (of a 30720 byte maximum) | |||
And "Done Uploading" | |||
Now open a new window of your browser and point it to the IP Address as defined by My IP in the last example | |||
My IP: 192.168.0.6 | |||
So open up http://192.168.0.6/ | |||
And your Nanode should serve its first webpage. It doesn't do much, but does have a clickable link to Andy Lindsay's blog page. | |||
Now, edit the code and change every reference to Arduino in the print_webpage function to Nanode | |||
// prepare the webpage by writing the data to the tcp send buffer | |||
uint16_t print_webpage(uint8_t *buf) | |||
Now re-compile and upload and refresh your browser window - you should see the text changes you made in the code reflected in the served page. | |||
'''Analogue Inputs''' | |||
It's quite straight forward to add the analogue readings from sensors to the web page. | |||
We first have to read the ADC input, convert the resulting number to ASCII, and put that number into a string. Then we copy those strings into the buffer which makes up the tcp sending buffer. | |||
Here's the code to read analogue 0 | |||
Remember to include the string library and the standard libray | |||
#include <stdlib.h> | |||
#include <string.h> | |||
// Read the 6 analogue inputs in turn, convert the ADC result to ASCII and put into numstr | |||
// Then copy from RAM, the numstr and put into the tcp send buffer to send to the web page | |||
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<br> A0: ")); | |||
itoa(analogRead(0),numstr,10); // convert integer to string | |||
plen=es.ES_fill_tcp_data(buf,plen,numstr); | |||
The complete code can be cut and pasted from this [https://gist.github.com/1164579 Github Gist] | |||
Github Gists are a good way of sharing small code projects with others. Just google Github Gist, where it opens a new form, paste in your code and it gives you a Gist number. Then share the URL of that Gist with your group. | |||
Note: | |||
To get the EtherShield examples to work you will have to edit the enc28j60 init function to read. | |||
ES_enc28j60Init(mymac,8); | |||
In the analogue webserver example in the Gist this can be found on line 93. | |||
===Further Applications=== | |||
EtherShield simpleClient examples for Pachube and Emoncms: [https://github.com/openenergymonitor/sketchbook/tree/master/EtherShield_simpleClient github] | |||
===Powering Down the ENC28J60 - when not used=== | |||
Most of the power consumed on the Nanode is in the line drivers of the ENC28J60 ethernet controller - even if it is transmitting or not! | |||
Here's someone's notes about putting the ENC28J60 into sleep mode so it doesn't use so much power. | |||
http://blog.derouineau.fr/2011/07/putting-enc28j60-ethernet-controler-in-sleep-mode/ | |||
User softhook - Christian Nold has tried this and reports that it works well. | |||
===Programming without an FTDI cable=== | |||
If you don't have an FTDI cable and don't want to use the USB programming method, it's possible to use a standard Arduino as an FTDI cable (because it has an FTDI serial chip on it). | |||
Paul has written a very thorough guide at [http://openenergymonitor.org/emon/node/235 Open Energy Monitor] | |||
===Programming with a CP2102 module=== | |||
[[File:Arduino-cp2102.jpg| an example of a CP2102 module. Warning: wiring may be different depending on board revision, read the text below.]] | |||
USB to UART, (CP2102 module) | |||
Look for a green or blue-coloured circuit board with a USB connector at one end and 6 pins at the other end. | |||
This device enables your desktop or laptop machine to communicate with the Shrimp, for example to send new programs to it with the free Arduino IDE, or to exchange other information with a program when it’s running on the Shrimp. | |||
For the latest Baite CP2102 modules, (with DTR as sixth pin on the front) attach the rainbow wires from the 9pin header to the CP2102’s labelled pins like… | |||
Red -> 5V | |||
Orange -> RXD | |||
Yellow -> TXD | |||
Green -> GND | |||
Brown -> DTR | |||
For older Baite CP2102 modules (with DTR pin labelled on the back) exchange TX and RX to be like… | |||
Orange -> TXD | |||
Yellow -> RXD | |||
===Programming with a PL2303 cable=== | |||
There are cheaper cables available than the FTDI. Many generic serial cables use the Prolific PL2303 chip, but these usually have RS232 converters and a 9-pin D-type connector. | |||
However, some mobile phone programming cables have the PL2303 with TTL (or, possibly, 3v3) connections. These are available for as little as 3 Euro on Dealextreme or eBay. | |||
Zoobab has successfully used a clone of Nokia CA-42 cable to program his nanode. [https://hackerspace.be/Get_to_know_Nanode#Flash_with_Nokia_CA42_.28PL2303.29 See his description here] | |||
Artag bought a different CA-42 cable and found it had a moulded plug rather than the clipped one that Zoobab got. This makes it harder to open up and access the extra pins (though they are there if you strip the plastic away), so try to find out which sort they're selling before you buy. | |||
==Simple Applications== | |||
Here's some ideas to get you started with your Nanode. Feel free to add your favourite applications to this section. Wherever possible provide a link to relevant external information, code examples or a link to a GitHub Gist which can be quickly cut and pasted into a new code sketch. | |||
===Nanode Basics=== | |||
Nanode is very similar to the Arduino - in fact anything that you can do on an Arduino can be done, almost without modification, on the Nanode. The Nanode provides the familiar Arduino shield connectors - so you can plug a wide range of shield and protoboards straight into the top of the Nanode. | |||
With a shield in place, Nanode provides a second row of connectors on each long edge of the PCB - these connectors have been tailored to suit the needs of a variety of hardware devices. | |||
Nanode can be fitted with a row of connector pins on the top edge of the pcb, so that it can be plugged into a standard breadboard. Unlike the Arduino, all of the available I/O, both analogue and digital and power can be accessed from this single in line (SIL) connector - making connection to a breadboard simple, quick and easy. | |||
===Lighting The Red LED=== | |||
Nanode comes with a version of the LED Blink program already loaded into the ATmega328 microcontroller, done along with the bootloader. When you power up your Nanode for the first time - if all is well, the red LED will begin flashing. | |||
The LED is driven by digital pin 6 - whereas on the Arduino it is pin 13. Another difference is that the sense of the LED is inverted, you need to make the digital output pin LOW in order to bring the LED on. These changes are because the way in which Nanode handles its local serial port - and this will be explained in a later section. | |||
The LED was moved from 13, because pin 13 is in almost constant use by the SPI bus which talks to the ethernet controller. | |||
===Connecting a RGB LED=== | |||
An RGB LED is a cheap and effective way of signalling changing environmental measurements or "moods". By fading the individual LEDs you can create a very large range of subtle colours. Using simple ramping up and down of Blue Green and Red will produce a display that could indicate temperture or power consumption starting at blue, fading through green and then through orange into red. | |||
Use the PWM channels on digital 3, digital 5 and digital 6 to drive the red, green and blue anodes. The common cathode connects to 0V | |||
Remember to use a current limiting resistor of at least 100 ohms in series with each LED. A ping pong ball or other semi-opaque plastic globe forms an attractive mood light. Cheap LED lamps available from Homebase for £2.50 each in a number of novelty shapes - globe, cube, heart and star. | |||
===Connecting a Radio Control Servo === | |||
Use the servo/display connector adjacent to the 5V regulator. Plug the 3 wire servo cable directly into the end three pins of the connector - noting that the red +ve supply to the servo goes on the left. | |||
===Connecting a "Modern Device" LCD serial Display Controller === | |||
Use the servo/display connector adjacent to the 5V regulator. Plug the 3 wire display cable directly into the end three pins of the connector - noting that the red +ve supply to the servo goes on the left. | |||
Use the software serial library on digital 4 to send serial text and commands to the display. | |||
===Using Arduino Shields=== | |||
You can plug Arduino shields into the Nanode provided that you consider the following points: | |||
Nanode uses digital 8,11,12 and 13 to control the ENC28J60 ethernet controller. | |||
Nanode uses digitals 7,9,10 to a certain extent depending on what hardware options have been fitted. | |||
https://github.com/thiseldo/EtherShield | You may need to use "stackable headers" to lengthen the pins of your shield, so that it has clearance over the Magjack connector - available from [http://www.coolcomponents.co.uk/catalog/product_info.php?manufacturers_id=&products_id=347 Cool Components] | ||
===Connecting to 1 Wire Sensors=== | |||
You can connect to a variety of 1 wire devices including temperature and humidity sensors | |||
Use the Arduino 1 wire library for example sketches | |||
Note that Digital 2 is used for the interrupt input from the wireless module - if fitted. Please use Digital 3 for Onewire to avoid any signal conflict. | |||
===Connecting to Thermistor Temperature Sensors=== | |||
Thermistors are a low cost temperature sensor available in a wide range of shapes and sizes to suit your application. For example if you wish to monitor your heating system, you might use the clip on pipe sensors from Rapid Electronics. | |||
Thermistors are generally built into a potential divider circuit using a resistor of similar value to that of the thermistor - eg 10K for a thermistor which has a resistance of 10K at 25 degrees C. The thermistor should be put in the upper arm of the potential divider so when the temperature rises, its resistance drops and so the voltage at the mid-point of the divider rises. | |||
This voltage is read using one of the analogue inputs, but the input has to be linearised and scaled so that it reads correctly in degrees C. Fortunately the code to do this is available on the [http://www.arduino.cc/playground/ComponentLib/Thermistor Arduino Playground.] and a more advanced example which uses the [http://www.arduino.cc/playground/ComponentLib/Thermistor2 Steinhart-Hart Linearisation Equation] | |||
===Using the Local Serial Bus=== | |||
For some applications, several Nanodes need to be connected together as a distributed monitoring and control network and be controlled by a master device, possibly connected to the internet. | |||
The Nanode Local Serial Bus was devised as an economical way of doing this, without having the cost and complexity of the ethernet controller and mag-jack on every board. | |||
The local bus can use inexpensive 4 core telephone cable to distribute power and communications between each board in the network. A power supply voltage of 12V is recommended. | |||
Each board takes its power from the bus, which can be up to 500mA maximum for standard 26 gauge telephone wire. This means that slave boards can power small electromechanical devices such as relays, motors, servos and solenoids using the bus power. | |||
Communications over the bus is done using 5V signal levels and from testing we found that 9600 baud worked well at distances of up to 300m of cable. | |||
The allocated Master device has ultimate control over the bus, and sends out packets of serial data to which the slaves respond, possibly returning their data to the Master. | |||
For this to work - we need a system of bus arbitration, such that there is only one device talking on the bus at any time. In the Nanode, this bus control is done using a pair of tristate buffers, which are left over from the four in the 74HC125 device - where only two were used for the ethernet controller glue logic. | |||
Let us assume that all slaves are listening to the bus - in otherwords their Rx pin is electrically connected to the Transmit line of the Master device via the bus. The master will address a slave by sending a packet of data which contains the (destination) address of that node. When a slave sees its own address come up, it decodes the packet of data, which is usually a command allowing the slave to access the bus, and transmit its data back to the master. | |||
To do this, the slave must enable its Transmit tristate buffer by lowering digital 6. This allows the slave to send data to the bus, where the master, will receive it. By lowering pin 6, the Red LED will also be turned on, and this gives a visual indication that that slave has been selected and that it is accessing the bus. This is the reason that the LED is on pin 6. | |||
The slave sends its data to the master and then releases the bus - by raising pin 6 and the LED will turn off. | |||
Trystan Lea of openenergymonitor.org has written a comprehensive library to allow a master slave network to be set up. See his documentation here about [http://openenergymonitor.org/emon/network Networked Arduinos] | |||
For a very similar project of a wired serial bus which uses the RS485 physical layer see [http://openenergymonitor.org/emon/node/160 Rob Gray's project]. [http://busnet.robgray.com/ Busnet Project]. This will be relevant if the Nanode is to be used as a DMX lighting controller. | |||
===Webserver Application (Dave Ingram)=== | |||
Dave's code is in his Github repository | |||
https://github.com/dingram/Nanode/ | |||
====Webserver Application with Live Analogue Thermistor Served on Webpage(samthetechie and lambda25)==== | |||
This code is derived from Dave's example and an arduino playground example shows a live sensor reading from Analogue 0 on the webpage upon page refresh. The trick to getting this to work was to use dtostrf() instead of sprintf() for the float to string conversion. | |||
*Code: https://github.com/Nanode/Webserver-Live-Thermistor-Reading | |||
*Screenshot | |||
[[File:Webserver_Live_Thermistor.png|frameless|500px]] | |||
*Photo | |||
[[File:Photo_Live_Thermistor.jpg|frameless|500px]] | |||
====Connecting to your nanode from behind a router==== | |||
So far In the above screen shot we are reaching the nanode on the local network directly with its IP address. However, the purpose of this project was to have a remote sensor that you could get to from anywhere. In this case you need to do some basic port forwarding from your external IP (that of your router usually) and the internal IP of the nanode on your local network. | |||
If you aren't familiar with "port forwarding" it is best to google or wiki it, whilst the basic principle is the same, the exact procedure depends on your router. | |||
The General procedure is as follows: | |||
*Connect The nanode to power, Ethernet and the sensor board (in our case a simple thermistor circuit) | |||
*Wait for it to get an IP (for DHCP) or just for it to connect (if you have assigned a static IP in your sketch) | |||
*Connect to your router and find the IP address of your nanode | |||
*Find your External IP by googling "my IP address" | |||
*Make a Port forward from your external IP eg 45.69.124.22 choosing any port you like eg port 5000 to the nanodes IP on port 80 eg 192.168.1.12:80 | |||
And that's it, now you should be able to type your external IP and the chosen Port into your browser (eg.45.69.124.22:5000) and be directed to the webpage served by the nanode, from anywhere :D | |||
Keep in mind that if your external IP Changes or your router assigns a new IP to the Nanode (as happens with DHCP), you won't be able to reach it. That is why it is best to set up a static IP in both cases if you intend on having a more permanent set up. If you don't have a static external IP, you can use a dynamic DNS service such as [http://www.dyndns.com/services/dns/dyndns/ DynDns.com] or [http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html No-IP] to get a fixed hostname (e.g. myhome.dyndns.com) that always redirects to your external IP address. | |||
===USB Bootstrap loader=== | |||
The template for the USB boot loader is [http://www.obdev.at/products/vusb/usbasploader.html USBaspLoader]. It needs to be built using these [[Project:Nanode/Applications/Bootstrap config files|config files]]. | |||
There are some caveats. Read the notes. | |||
===MAC address=== | |||
The Nanode has a surface-mount chip soldered to the underside of the board containing a unique MAC address. | |||
Code to read this chip is available on github: see [https://github.com/sde1000/NanodeUNIO NanodeUNIO] | |||
To use this code, download it to the sketchbook/libraries folder and start the Arduino IDE. Choose File->Examples->NanodeUNIO->NanodeMAC and upload the sketch to your Nanode. Open up the Serial Monitor. It should print the MAC address in the Serial Monitor box. If you get gobbledygook back or it trips your serial port off-line, see if the baud rate in the corner of the Serial Monitor corresponds to the Serial.begin value in the NanodeMAC sketch and change it in the sketch if necessary. Serial.begin(9600) should work. (Try it with the "HelloWorld sketch also.) | |||
Once you have successfully read your MAC address, you can enter it next to your Nanode serial number in [http://wiki.hackspace.org.uk/wiki/Pledges/Nanodes/Details#The_Complete_List The Complete List]. | |||
If you did not have your tiny MAC chip soldered to the back of the pcb during the Nanode Weekend - this can be done at a later date at the space. Ken is next available to do this at London Hackspace on evening of 14th June. You will need a time machine set to this date in 2011. | |||
===RFM12 Wireless Module=== | |||
Wireless connectivity can be added to the Nanode using the [http://jeelabs.com/products/rfm12b-board Jeelabs RFM12B wireless board]. Schematic can be viewed [http://jeelabs.net/attachments/846/jlpcb-511.pdf here]. No need to solder in the 3.3V regulator or capacitors the board will gets its 3.3V power from the Nanode. | |||
For compatibility with the [http://OpenEnergyMonitor.org/emon/emontx emonTx] from OpenEnegyMonitor.org ensure the 433Mhz RFM12B module is used (this frequency can be used worldwide). JeeLabs use 868Mhz which can only be used in Europe. | |||
RFM12B modules can be bought in the UK from [http://uk.rs-online.com/web/p/radio-telemetry-data-modules/6666757/ RS], [http://www.rapidonline.com/Electrical-Power/Security-Warning-Device/AM-FM-System-Modules/FM-RF-ALPHA-Modules/122236/kw/alpha Rapid] or [http://uk.farnell.com/rf-solutions/alpha-trx433s/module-transceiver-trx433s/dp/1718689 Farnell]. | |||
The JeeLabs RFM12B board plugs into a special port on top the Nanode. This port is different to the Arduino header just below it. An extra 8 pin female header will need to be soldered in. See image below: | |||
[[File:Nanode RFM12 port.png|300px|thumb|center|Photo showing location on of RFM12B wireless port on the Nanode]] | |||
[[File:JeeNode RFM12B.jpg|300px|thumb|center|JeeLabs RFM12B wireless breakout board. For connecting to the nanode there is no need to solder in the 3.3V voltage regulator or the capacitors. The RFM12B will get is 3.3V power from the Nanode's 3.3V voltage regulator. ]] | |||
Update 24/10/11 by Glyn Hudson ([openenergymonitor.org]): | |||
'''There is an error on the Nanode 5 board layout. That stops the Ethernet and RFM12B being used at the same time. See below for explanation and solution:''' | |||
'''Explanation:''' | |||
The INT/IRQ signal from the RFM12B socket is mistakenly OR'ed with the INT from the ENC28J60 Ethernet Chip before going into the 74125 Tri-state buffer which acts as a 3.3-5V level converter. | |||
If the ENC28J60 sets its interrupt line high, then the low going RFM12 interrupts will be pulled up by this high signal so they might only get down to 1.5V which is too high to register as a logic 0. The 10K resistor R13 also pulls the INT line high. This stops the RFM12B working at the same time as the ENC28J60. | |||
'''Solution:''' | |||
The solution is to lift pin 4 of the ENC28J60 out of its socket and not solder in/remove R13 (the 10K resistor, one resistor down from the 1 ohm ferrite). This disconnects the ENC28J60's INT line (which is not used) from the circuit and removes the resistor which was pulling the line high. | |||
[[File:Nanode RFM12B mods.jpg|300px|thumb|center|Modifications: Notice pin 4 of ENC28J60 lifted up and the 10K resistor R13 not soldered in]] | |||
No additional wire link is needed as first though. | |||
RFM12 example with DHCP and DNS and posting data via Ethernet to Pachube and emoncms by [http://OpenEnergyMonitor.org OpenEnergyMonitor]: [https://github.com/openenergymonitor/sketchbook/tree/master/EtherShield_simpleClient_RF12 download from github] | |||
===Bitlash=== | |||
Bitlash is a interpreted command shell (language) which runs on the Arduino. It takes 14K of program memory, but allows programs to be written from a serial terminal and stored as functions in the EEprom on the ATmega328. It is reminiscent of the early 1980s home computers which executed BASIC directly from power-up. | |||
Bitlash could be used to write simple scripts to automate sensing functions, datalogging or other applications running on Nanode. There is an opportunity to be able to reprogram a Nanode remotely, and have it perfor different tasks. | |||
Bitlash can incorporate any of the Arduino library functions, making it simple to combine Bitlash with existing C-code. | |||
More infomation here [http://bitlash.net/wiki/start Bitlash Wikki] | |||
===SPI Serial SRAM=== | |||
On the underside of the Nanode 5 pcb is a footprint to accept a SPI memory deviice. This can be EEprom, data flash, SRAM or FRAM (ferroelectric memory). | |||
I have done some test code for the very cheap (£1.20) 23K256 spi SRAM which is a 32K byte device. | |||
You can find my test code on the following Github Gist | |||
https://gist.github.com/1020771 | |||
There is also an Arduino library to support this device - find it [http://www.arduino.cc/playground/Main/SpiRAM here] | |||
If you intend to run the SPI SRAM, you will need to modify the way the board is powered - so that everything runs off 3.3V. See below for details. | |||
===Running the board on just 3V3=== | |||
Nanode 5 uses both 5V and 3V3 to run the on-board devices. This has been done mainly as a convenience so that it is compatible with Arduino and Arduino shields which generally use 5V. | |||
However, there are an increasing amount of low power devices which only need 3V3, such as the on board ENC28J60 ethernet controller and the spi memory device on the underside of the pcb - so advanced users may wish to modify their boards to run solely on 3V3 - particularly if they are to access the spi SRAM. | |||
First you have to identify where 5V is produced or enters the pcb. Either the red wire of the FTDI cable, the USB jack or the 5V 7805 regulator. Having identified these sources you need to isolate them or in the case of the regulator modify so that they produce 3V3. | |||
One way would be to remove the existing 5V 7805 regulator and replace it with a 3V3 regulator, and then cut the pin on the FTDI connector that feeds 5V to the pcb and wire a link from this severed pin to the new input of the newly added 3V3 regulator. For completeness you would also need to cut the 5V input track that comes from the USB socket. | |||
Once you are feeding the 5V into the new 3V3 regulator, you need to connect this 3V3 to the existing 5V rail. The easiest way is a wire link which connects pins 2 and 3 of the Arduino shield "power" connector. | |||
A pictorial guide to this modification will be provided later. | |||
===RESTduino=== | |||
RESTduino provides a way to directly control the Nanode hardware from a client - server session. The commands that you want to run on the Nanode are encoded into the URL. For example turn I/O pins on and off or read an analogue temperature sensor. | |||
We hope to combine RESTduino with the bitlash command interpreter to make an interactive way of running scripts on Nanode and editing them remotely. | |||
[https://github.com/thiseldo/EtherShield_RESTduino Here's] what Andy Lindsay says about RESTduino and how to run it on your Nanode. | |||
EtherShield RESTduino | |||
** IMPORTANT NOTE ** | |||
This version of RESTduino is for ENC28J60 based ethernet shields only, not the Official Arduino Ethernet Shield, these use the wizznet chips, it is very heavily based on the original RESTduino by Jason Gullickson, full details at: http://jasongullickson.posterous.com/restduino-arduino-hacking-for-the-rest-of-us. Full thanks and credit go to Jason for the original code and ideas. I have taken his work and massaged it into an application that works with the ENC28J60 based ethernet shields. | |||
I've also updated the demo to use 3 sliders to change the colours on a RGB LED. | |||
This should also be compatible with the Nanode boards described at http://nanode.eu | |||
RESTduino is a simple sketch to provide a REST-like interface to the Arduino via the Ethernet Shield. The idea is to allow developers familiar with interacting with REST services with a way to control physical devices using the Arduino (without having to write any Arduino code). | |||
Of course some flexibility is traded for this convenience; only basic operations are currently supported: | |||
* Digital pin I/O (HIGH, LOW and PWM) | |||
* Analog pin input | |||
Later versions of the sketch may provide additional functionality (servo control, etc.) however if you need more than just basic pin control you're probably better off learning the basics of programming the Arduino and offloading some of your processing to the board itself. | |||
Getting Started | |||
--------------- | |||
First you'll need an Arduino, a ENC28J60-based Ethernet shield and the Arduino development tools; here's some links to get you started: | |||
* Arduino Uno (adafruit): http://www.adafruit.com/index.php?main_page=product_info&cPath=17&products_id=50 | |||
* EtherShield (nuelectronics): http://www.nuelectronics.com/estore/index.php?main_page=product_info&products_id=4 | |||
* Arduino development tools: http://www.arduino.cc/en/Main/Software | |||
Or you could use the Nanode, http://nanode.eu which combines both the Arduino functionality and the EtherShield on one board. If you use a Nanode then you will additionally need the FTDI programming lead. | |||
For testing you'll want some hardware to connect to the Arduino, the demo uses a common cathode RGB LED connected to pins 3, 5 and 6. Connecting single LEDs between the pins and ground will also work. | |||
Load up the sketch (EtherShield_RESTduino.pde) and modify the following lines to match your setup: | |||
static uint8_t mymac[6] = { 0x54,0x55,0x58,0x10,0x20,0x35}; | |||
This line sets the MAC address of your ethernet board; | |||
static uint8_t myip[4] = { 192,168,1,177}; | |||
The next line you'll need to modify is this one which sets the IP address; set it to something valid for your network. | |||
Now you should be ready to upload the code to your Arduino. Once the upload is complete you can open the "Serial Monitor" to get some debug info from the sketch. | |||
Now you're ready to start talking REST to your Arduino/Nanode! | |||
To turn on the LED attached to pin #3 (currently case sensitive!): | |||
http://192.168.1.177/3/HIGH | |||
This will set the pin to the HIGH state and the LED should light. Next try this: | |||
http://192.168.1.177/3/100 | |||
This will use PWM to illuminate the LED at around 50% brightness (valid PWM values are 0-255). | |||
Now if we connect a switch to pin #2 we can read the digital (on/off) value using this URL: | |||
http://192.168.1.177/2 | |||
This returns a tiny chunk of JSON containing the pin requested and its current value: | |||
{"2":"LOW"} | |||
Analog reads are similar; reading the value of Analog pin #1 looks like this: | |||
http://192.168.1.177/a1 | |||
...and return the same JSON formatted result as above: | |||
{"a1":"432"} | |||
Javascript/jQuery Demo | |||
---------------------- | |||
A simple example of how to interface with RESTduino via jQuery is included as DemoApp2.html. | |||
This page displays 3 slider controls (via jQuery UI) which when adjusted will set the PWM value of Pin #3, #5 and #6 to the value selected by the slider. These then change the appropriate colour on the RGB LED. | |||
If you look at line 32 you can see where the REST URL (you'll need to adjust this for the IP address of your device) is constructed based on the selected value of the slider and on lines 53, 63 and 73 an AJAX request is executed passing the URL constructed above to the Arduino. | |||
===Combining Bitlash and RESTduino to make a simple Scriptable Device=== | |||
Bitlash is a simple interpreted script language which runs on Nanode or Arduino. It allows you to define new functions, store them to EEprom memory and to control the I/O port pins with a few simple commands typed over the serial port. It's a little reminiscent of the late 70's early 80's home-computers that from power-up ran an interpreted basic. It's better than Basic because it ties in with the Arduino libraries and function calls, and you can mix your C code with Bitlash running in the background - it just seems such a cool idea as an interface to a simple microcontroller. | |||
Bitlash has a Telnet example, so that you can Telnet into it remotely and edit scripts to control different things. Well you could - if our TCP/IP stack supported a Telnet Client. Unfortunately it doesn't, so we have to find another way of getting our command line data up to the Nanode. | |||
One neat way of doing this is to embed the command line at the end of the URL you send to your Nanode server, and then persuade the Nanode to send you something useful back. | |||
Suppose your Nanode is at IP Address 192.168.0.105 and has the means to serve a simple web page assembled from HTML and text in a small text buffer. Lets call this page page_one | |||
HTTP allows for subfolders, so if your page was in a subfolder called password, you could type | |||
http://192.168.0.105/password/page_one and it would serve the page. | |||
If however you don't spell password correctly, the device will return with a 404 error - page not found. This simple mechanisms allows very crude password control over what is served - important if you don't want everyone tinkering with your Nanodes. | |||
I've been looking at the RESTduino example - and it is quite simple to see how the code parses through the URL looking for backslashes and stripping out the parameters contained between them. | |||
The command buffer is set to 50 characters - but I am sure we could extend this to get a good line length - say 127 chars. | |||
So a merge between REST and bitlash would just have to have the REST command line buffer deposited into the bitlash command line buffer (make them one and the same) and bitlash will execute the commands included in the URL. | |||
There is then another string buffer called the Client line - and this is used to send text back to the client. Again bitlash would populate this with the output response from the executed command and send it back. | |||
So let's assume there's a Nanode lurking at IP Address 192.168.0.105 | |||
Bitlash sends its ">" prompt to the Client line | |||
The user then wants to get the Nanode to print the answer to the sum 2 + 2 so the User types into the URL window of their browser | |||
http://192.168.0.105/bl/PRINT 2+2 <CR> | |||
The REST code, parses the URL from its command buffer until it finds the first backslash after the IP address where it encounters /bl and so it knows what next is going to be a bitlash command rather than a REST command | |||
/bl/PRINT 2+2 <CR> | |||
it then takes the PRINT 2+2 up to the final <CR> and puts that into the Bitlash command input | |||
Bitlash parses and executes this command and prints 4 back into the Client's Line, followed by a newline and its > prompt. | |||
To make this nice and elegant we would just need a bit of processing code or Python, which accepts lines of text commands and precedes them with the http://192.168.0.105/bl/ header. | |||
===IPv6 and uIP=== | |||
uIP is an alternative TCP/IP stack written for resource limited micro-controllers. | |||
Guenther Hoelzl has combined uIP plus the ENC28J60 library from Guido Socher, to make an IPV6 implementation - which will run on any Arduino like device with ENC28J60 ethernet controller - including Nanode of course. | |||
http://sites.google.com/site/ghoelzl/ipv6ethershield/ipv6_telnet_server | |||
1st August - Stephen Early [http://twitter.com/sde1000 @sde1000] reports that he has successfully ported uIP to his Nanode and it responds to pings and DHCP now working! - Good work Stephen - we look forward to further developments along these lines. | |||
Stephen's NanodeUIP repository: http://github.com/sde1000/NanodeUIP | |||
25th July 2016 - While the rest of the world has moved on to other things, [https://twitter.com/njh @njh] has written a minimal IPv6-only library for Nanode/Arduino, called EtherSia: | |||
https://github.com/njh/ethersia | |||
It uses less programme memory and RAM than uIP/Contiki. | |||
=== Jee Labs EtherCard Library === | |||
The Jee Labs [http://jeelabs.net/projects/cafe/wiki/EtherCard EtherCard Library] works on Nanode with no modifications whatsoever. It even uses pin 8 for SPI chip select. Examples and details on [http://maniacbug.wordpress.com/2011/08/07/nanode/ maniacbug's blog]. | |||
===Tuxgraphics I/O Web Server=== | |||
Tuxgraphics were the first company to produce a board based on the combination of the ATmega and the ENC28J60. In fact, most of the library was written originally by Guido Socher and Pascal Stang working for Tuxgraphics. | |||
Whilst the original library has been updated and modified by others, much of the basic ENC28J60 low level driver code has remained and is common across any device using the ENC28J60. | |||
The Tuxgraphics web server is not a normal web server. It is an IO-web server. It reads sensor values or IO-pins and it controls digital output lines or relays. It is as well possible to have analog output lines providing arbitary voltages between 0V and 3.3V by using a R2R-ladder DAC. | |||
Sometimes you want to have more digital output pins than the microcontroller you are using provides. You can either switch to a bigger microcontroller chip or use a 74hc595 port expander. This article focuses on the 74hc595. Using multiple 74hc595 chips you could in theory have an infinite amount of output lines on a single ethernet board. | |||
The advantage of the 74hc595 is that you save on wires if you want to have the 8 additional output pins in a different place. There is a serial connection between microcontroller and 74hc595. The cable length of that connection should however not be more than a metre (3ft). | |||
The 74hc595 chips can be chained to provide 16 bit output ports or more without occupying any further output lines on the atmage. | |||
For another article on IO-web servers which provide digital and analog input lines together with digital output lines see "Using the tuxgraphics embedded web server to control scientific equipment". | |||
Here is the file [http://tuxgraphics.org/common/src2/article09041/ download area] | |||
===LCD control=== | |||
Rafael connected a 44780 LCD to his nanode, and provided it with a web interface - see his [http://blog.rafaeltorrales.info/2011/10/09/nanode-dhcp-webserver-and-lcd-display/ blog entry] | |||
===Temperature to Pachube === | |||
Based on Victor Aprea [http://wickeddevice.com wickeddevice] code to send Nanode's data to Pachube, here is a tutorial to send thermistor's temperature to pachube: [http://blog.rafaeltorrales.info/2011/10/14/nanode-and-pachube-for-the-rest-of-us/ Nanode and Pachube for the rest of us. ] | |||
===Nanode’s DHCP Starvation Attack === | |||
Is not an attack, but just to test your dhcp server's capabilities. Also includes a lame (but working) version of an udp flood. | |||
[http://blog.rafaeltorrales.info/2011/10/21/nanodes-dhcp-starvation-attack/ Nanode’s DHCP Starvation Attack] | |||
===Streaming Internet Radio=== | |||
Nanode is great for streaming internet radio using a VS1053 MP3 decoder and the uIP TCP/IP stack. | |||
More details at [http://maniacbug.wordpress.com/2011/12/30/arduino-on-ice-internet-radio-via-shoutcast/ Arduino on Ice: Internet Radio via Shoutcast] | |||
<center>http://farm8.staticflickr.com/7165/6600655547_3b6f91af24.jpg</center> | |||
===NanodeUIP Web Server=== | |||
Here's another take on a web server for Nanode, allowing control and monitoring of a Nanode with a mobile-optimized interface. See all the details at [http://maniacbug.wordpress.com/2012/01/28/webserver/ Control and Monitor Arduino Over the Web Using ENC28J60]. | |||
<center>http://farm8.staticflickr.com/7142/6774605587_af9f0cec58.jpg</center> | |||
== Simple hack to cool the 7805 == | |||
Found it necessary to cool the 7805 when the device is fed by a 7.5V DC wallwart. | |||
[[File:nanonde-7805-bare.jpg]] | |||
[[File:nanonde-7805-with-plate.jpg]] | |||
A simple heatsink does the trick - and by sheer co-incidence it can be folded over the elco's. | |||
Another Heatsink | |||
[[File:Paste.JPG|200px]] |
Latest revision as of 18:07, 25 July 2016
Nanode Applications
Nanode is an Arduino like 8 bit microcontroller board with integrated Ethernet connectivity.
It has 6 analogue sensing channels and 6 spare digital I/O lines.
It can be used for a variety of web connected applications including remote control and monitoring, as a smart sensor, home automation, as a Tweeting device, and for publishing small amounts of data to the web.
The existing software allows it to be set up as an I/O webserver - a device which sends the state of its analogue and digital I/O to a web page - and which can be controlled from that webpage.
However it is not restricted to just that role, it can act as a publisher device and send data to an intermediary open data service such as Pachube, and it can act as a web connected I/O device, which subscribes to a Pachube data feed and acts according to the data received from that feed - for example setting its I/O, updating a display or controlling some actuator device.
By using Pachube's API as a smart intermediary, much of the burden of serving an interractive webpage is eliminated from the Nanode.
A final application, uses an interpreted language called Bitlash which allows scripts to be written and stored in EEprom on the microcontroller or on an external SD card. We are developing a Telnet aopplication which would allow a Nanode running bitlash to be remotely reconfigured to run a different script.
Nanode has a lot in common with the Tuxgraphics Web Server - in fact the Tuxgraphics TCP/IP stack was ported to Arduino, and thence onto Nanode.
Here's an article with a lot of the background information to how the stack works and how it serves small web pages efficiently.
Before You Start
You now have a flashing red LED which shows that the bootloader and Blinky program is running on the microcontroller , and are keen to connect to the internet. If you are unfamiliar with Arduino, you might wish to visit the extensive reference and examples pages linked to the main Arduino Homepage site.
Nanode is essentially just an Arduino with ethernet connectivity added - so anything that you can do on Arduino, you should be able to do with Nanode.
The easiest way for newcomers to access Nanode is to use the Integrated Design Environment (IDE) provided with Arduino. However, more experienced C coders may wish to use the open source GCC C compiler directly with AVRdude or the toolset provided by Atmel in AVR Studio.
In short - there are several ways to skin the cat called Nanode.
Note there are some slight differences, the LED on Nanode is on Digital 6 rather than Digital 13 on Arduino and it lights when digital 6 is set LOW - so its sense is inverted - more on why this is later.
Nanode uses an ethernet library which was written specifically to drive the ENC28J60 ethernet controller.
This device is used on several similar designs, and it must be noted that the library needs to be tailored so that it correctly addresses the ENC28J60 via digital pin 8, and not pin 10 as used in some ENC28J60 based ethernet shields.
To do this look at the DHCP test sketch and identify the line
es.ES_enc28j60Init(mymac);
for Nanode version 5 users this should be changed to:
es.ES_enc28j60Init(mymac,8);
Pin 8 is the pin used by the microcontroller to select the ENC28J60 for the SPI bus and if you don't add this, the MCU won't be able to communicate with the ENC28J60.
If you forget to do this, when you first power up there will be a message
ENC28J60 Version 0
This will appear as ENC28J60 Version 7 after the change has been made and you will know that all is well.
We are in the process of creating a Nanode specific library that defaults to pin 8, so this change will not be needed in the future.
Nanode and Pachube - Upgrade to a Free Pachube Pro Account
Nanode owners who have bought Nanodes through the London Hackspace may contact Pachube to receive a free Pro Account.
Pachube have been very supportive of the Nanode Project with this generous gesture to get a lot more Nanodes using Pachube and developing interesting applications. Contact Ed Borden at the email address below to collect your free Pro user account.
From Ed Borden, Pachube, New York.
"We are really excited about this project here at Pachube. We want to give our full support to anyone who has the gumption to take this thing and pull it along to the next level. I don't care if you haven't tested the first run yet! :) Full steam ahead!
For any of you guys on this list who bought a Nanode from Ken and want to connect it up to Pachube, drop me a line with your username and I'll upgrade your account to Pro. And when you do something awesome that you want the world to know about, tell us about it!"
edborden at pachube dot com
Testing Nanode
The ATmega328 microcontroller supplied with the kit has a specially modified version of the Arduino bootloader pre-programmed into it, together with an initial program to flash the red LED.
Arduino usually has a LED wired to digital pin 13, but in Nanode, digital 13 is in almost constant use as the SPI Clock so in the Nanode bootloader the LED flashing function has been altered so that it flashes the red LED which is wired to digital pin 6.
If all is well with your Nanode board the red LED should start flashing about 2 seconds after the power (from USB or FTDI cable) has been applied.
If it does not flash, check for faults such as missing soldered joints or the LED incorrectly inserted.
Applications
Quick Tutorial
Read this and the following EtherShield Examples sections to familiarise yourself with the basic operations of the Arduino IDE: programming, compiling and uploading code to the Nanode.
Note that EtherShield is spelt with a capital E and a capital S. You may get compilation problems if you deviate from this spelling.
The first couple of examples will help you confirm that your hardware is fully functional and that you can get a DHCP address and serve a simple webpage from your Nanode.
1. Download and Install Arduino Environment
http://arduino.cc/en/Main/Software
- Windows users: open the arduino-0022 folder and run Arduino.exe
- Mac users: mount the dmg and drag arduino into Applications folder
- Ubuntu users (tested on 10.10): sudo apt-get install arduino
2. Select the Appropriate Board Type
In the Arduino application menu Tools/Board select "Arduino Duemilanove or Nano w/ ATmega328"
3. Download FTDI (or SiLabs) Cable Drivers
3a. NOTE: The US-based version from Wicked Device tends to come with a cable that uses a chip from Silicon Labs instead of FTDI. Drivers for OSX or Windows (Linux doesn't need them) can be downloaded directly from Silicon Labs. Here's a nice writeup that explains it all.
Plug in the FTDI programming cable.
- Windows users: when prompted to install drivers, point the installer to the arduino-0022/drivers directory
- Mac users: mount the arduino installation dmg and double click on the FTDI install package at the bottom of the window
- Linux users: if you are using a recent version of Ubuntu or Debian, the FTDI cable should be plug and play; type:
dmesg | grep "ttyUSB*"
into terminal and hit return. The response may look something like this:
[ 7440.284623] usb 2-2: FTDI USB Serial Device converter now attached to ttyUSB0
or
[ 8002.670918] usb 2-2: cp210x converter now attached to ttyUSB0
since ttyUSB0 is mentioned this indicates that the device mount point is /dev/ttyUSB0
4. Select the Appropriate Serial Port
In the Arduino application menu Tools/Serial Port select the appropriate device, e.g., "/dev/tty.usbserial-A400f2he" on a Mac or "/dev/ttyUSB0" on Linux.
5. Download EtherShield Libraries
Download here: https://github.com/thiseldo/EtherShield
Change the downloaded folder name to "EtherShield" and place in Arduino libraries folder:
- Mac users: make a folder called "libraries" in Documents\Arduino\ then place the EtherShield folder into the newly created libraries folder.
- Windows users: place the EtherShield folder into arduino-0022\libraries\
- Linux users: place the EtherShield folder into arduino-0022/libraries/ (or /usr/share/arduino/libraries/ ?)
6. Download the NanodeMAC Library
Download here: https://github.com/thiseldo/NanodeMAC
If you're using an operating system with a case-sensitive filesystem (e.g., Linux) then edit NanodeMAC.cpp to delete (or comment out) the line:
#include <wprogram.h>
This is required because the correct name of the file is "WProgram.h" (in arduino-0022/hardware/arduino/cores/arduino/). There's no need to keep or correct this line as the file has already been included by NanodeMAC.h (which has already been corrected for case in the git repository).
Place in the Arduino libraries folder as for EtherShield, above.
Be sure to set the baud rate at 19200.
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 its bootloader program, 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
https://github.com/thiseldo/EtherShield
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).
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 program 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 its 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.
Assuming that the ENC28J60 initialises correctly, it will flash the yellow and green LEDs on the ethernet connector - simultaneously 3 times at about one second intervals. This confirms that the ENC28J60 has been initialised.
The code then performs a DHCP discover - sending a DHCP request to the router. If this DHCP request is answered, it then populates the various IP arrays for myIP, gwIP, DNS_IP etc and prints them out to the serial terminal as follows.
My IP: 192.168.0.6 Netmask: 255.255.255.0 DNS IP: 192.168.0.1 GW IP: 192.168.0.1
You have now completed the testing phase of the Nanode and can move onto some real applications.
EtherShield_Webserver
Rename Ethershield_webserver.pde to EtherShield_webserver.pde then re-start IDE.
Now from the Files/EtherShield/Examples load the EtherShield_webserver sketch.
Once again edit the initialisation line from (mymac) to (mymac,8)
es.ES_enc28j60Init(mymac);
es.ES_enc28j60Init(mymac,8);
Also edit this line to match the IP address from the DHCP test
static uint8_t myip[4] = { 192,168,0,6};
Now compile and upload the code to the Nanode board
If successful you should first get the compilation report message:
Binary sketch size: 6422 bytes (of a 30720 byte maximum)
And "Done Uploading"
Now open a new window of your browser and point it to the IP Address as defined by My IP in the last example
My IP: 192.168.0.6
So open up http://192.168.0.6/
And your Nanode should serve its first webpage. It doesn't do much, but does have a clickable link to Andy Lindsay's blog page.
Now, edit the code and change every reference to Arduino in the print_webpage function to Nanode
// prepare the webpage by writing the data to the tcp send buffer uint16_t print_webpage(uint8_t *buf)
Now re-compile and upload and refresh your browser window - you should see the text changes you made in the code reflected in the served page.
Analogue Inputs
It's quite straight forward to add the analogue readings from sensors to the web page.
We first have to read the ADC input, convert the resulting number to ASCII, and put that number into a string. Then we copy those strings into the buffer which makes up the tcp sending buffer.
Here's the code to read analogue 0
Remember to include the string library and the standard libray
#include <stdlib.h> #include <string.h>
// Read the 6 analogue inputs in turn, convert the ADC result to ASCII and put into numstr // Then copy from RAM, the numstr and put into the tcp send buffer to send to the web page plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
A0: ")); itoa(analogRead(0),numstr,10); // convert integer to string plen=es.ES_fill_tcp_data(buf,plen,numstr);
The complete code can be cut and pasted from this Github Gist
Github Gists are a good way of sharing small code projects with others. Just google Github Gist, where it opens a new form, paste in your code and it gives you a Gist number. Then share the URL of that Gist with your group.
Note:
To get the EtherShield examples to work you will have to edit the enc28j60 init function to read.
ES_enc28j60Init(mymac,8);
In the analogue webserver example in the Gist this can be found on line 93.
Further Applications
EtherShield simpleClient examples for Pachube and Emoncms: github
Powering Down the ENC28J60 - when not used
Most of the power consumed on the Nanode is in the line drivers of the ENC28J60 ethernet controller - even if it is transmitting or not!
Here's someone's notes about putting the ENC28J60 into sleep mode so it doesn't use so much power.
http://blog.derouineau.fr/2011/07/putting-enc28j60-ethernet-controler-in-sleep-mode/
User softhook - Christian Nold has tried this and reports that it works well.
Programming without an FTDI cable
If you don't have an FTDI cable and don't want to use the USB programming method, it's possible to use a standard Arduino as an FTDI cable (because it has an FTDI serial chip on it).
Paul has written a very thorough guide at Open Energy Monitor
Programming with a CP2102 module
USB to UART, (CP2102 module)
Look for a green or blue-coloured circuit board with a USB connector at one end and 6 pins at the other end.
This device enables your desktop or laptop machine to communicate with the Shrimp, for example to send new programs to it with the free Arduino IDE, or to exchange other information with a program when it’s running on the Shrimp. For the latest Baite CP2102 modules, (with DTR as sixth pin on the front) attach the rainbow wires from the 9pin header to the CP2102’s labelled pins like…
Red -> 5V Orange -> RXD Yellow -> TXD Green -> GND Brown -> DTR
For older Baite CP2102 modules (with DTR pin labelled on the back) exchange TX and RX to be like…
Orange -> TXD Yellow -> RXD
Programming with a PL2303 cable
There are cheaper cables available than the FTDI. Many generic serial cables use the Prolific PL2303 chip, but these usually have RS232 converters and a 9-pin D-type connector.
However, some mobile phone programming cables have the PL2303 with TTL (or, possibly, 3v3) connections. These are available for as little as 3 Euro on Dealextreme or eBay.
Zoobab has successfully used a clone of Nokia CA-42 cable to program his nanode. See his description here
Artag bought a different CA-42 cable and found it had a moulded plug rather than the clipped one that Zoobab got. This makes it harder to open up and access the extra pins (though they are there if you strip the plastic away), so try to find out which sort they're selling before you buy.
Simple Applications
Here's some ideas to get you started with your Nanode. Feel free to add your favourite applications to this section. Wherever possible provide a link to relevant external information, code examples or a link to a GitHub Gist which can be quickly cut and pasted into a new code sketch.
Nanode Basics
Nanode is very similar to the Arduino - in fact anything that you can do on an Arduino can be done, almost without modification, on the Nanode. The Nanode provides the familiar Arduino shield connectors - so you can plug a wide range of shield and protoboards straight into the top of the Nanode.
With a shield in place, Nanode provides a second row of connectors on each long edge of the PCB - these connectors have been tailored to suit the needs of a variety of hardware devices.
Nanode can be fitted with a row of connector pins on the top edge of the pcb, so that it can be plugged into a standard breadboard. Unlike the Arduino, all of the available I/O, both analogue and digital and power can be accessed from this single in line (SIL) connector - making connection to a breadboard simple, quick and easy.
Lighting The Red LED
Nanode comes with a version of the LED Blink program already loaded into the ATmega328 microcontroller, done along with the bootloader. When you power up your Nanode for the first time - if all is well, the red LED will begin flashing.
The LED is driven by digital pin 6 - whereas on the Arduino it is pin 13. Another difference is that the sense of the LED is inverted, you need to make the digital output pin LOW in order to bring the LED on. These changes are because the way in which Nanode handles its local serial port - and this will be explained in a later section.
The LED was moved from 13, because pin 13 is in almost constant use by the SPI bus which talks to the ethernet controller.
Connecting a RGB LED
An RGB LED is a cheap and effective way of signalling changing environmental measurements or "moods". By fading the individual LEDs you can create a very large range of subtle colours. Using simple ramping up and down of Blue Green and Red will produce a display that could indicate temperture or power consumption starting at blue, fading through green and then through orange into red.
Use the PWM channels on digital 3, digital 5 and digital 6 to drive the red, green and blue anodes. The common cathode connects to 0V
Remember to use a current limiting resistor of at least 100 ohms in series with each LED. A ping pong ball or other semi-opaque plastic globe forms an attractive mood light. Cheap LED lamps available from Homebase for £2.50 each in a number of novelty shapes - globe, cube, heart and star.
Connecting a Radio Control Servo
Use the servo/display connector adjacent to the 5V regulator. Plug the 3 wire servo cable directly into the end three pins of the connector - noting that the red +ve supply to the servo goes on the left.
Connecting a "Modern Device" LCD serial Display Controller
Use the servo/display connector adjacent to the 5V regulator. Plug the 3 wire display cable directly into the end three pins of the connector - noting that the red +ve supply to the servo goes on the left.
Use the software serial library on digital 4 to send serial text and commands to the display.
Using Arduino Shields
You can plug Arduino shields into the Nanode provided that you consider the following points:
Nanode uses digital 8,11,12 and 13 to control the ENC28J60 ethernet controller.
Nanode uses digitals 7,9,10 to a certain extent depending on what hardware options have been fitted.
You may need to use "stackable headers" to lengthen the pins of your shield, so that it has clearance over the Magjack connector - available from Cool Components
Connecting to 1 Wire Sensors
You can connect to a variety of 1 wire devices including temperature and humidity sensors
Use the Arduino 1 wire library for example sketches
Note that Digital 2 is used for the interrupt input from the wireless module - if fitted. Please use Digital 3 for Onewire to avoid any signal conflict.
Connecting to Thermistor Temperature Sensors
Thermistors are a low cost temperature sensor available in a wide range of shapes and sizes to suit your application. For example if you wish to monitor your heating system, you might use the clip on pipe sensors from Rapid Electronics.
Thermistors are generally built into a potential divider circuit using a resistor of similar value to that of the thermistor - eg 10K for a thermistor which has a resistance of 10K at 25 degrees C. The thermistor should be put in the upper arm of the potential divider so when the temperature rises, its resistance drops and so the voltage at the mid-point of the divider rises.
This voltage is read using one of the analogue inputs, but the input has to be linearised and scaled so that it reads correctly in degrees C. Fortunately the code to do this is available on the Arduino Playground. and a more advanced example which uses the Steinhart-Hart Linearisation Equation
Using the Local Serial Bus
For some applications, several Nanodes need to be connected together as a distributed monitoring and control network and be controlled by a master device, possibly connected to the internet.
The Nanode Local Serial Bus was devised as an economical way of doing this, without having the cost and complexity of the ethernet controller and mag-jack on every board.
The local bus can use inexpensive 4 core telephone cable to distribute power and communications between each board in the network. A power supply voltage of 12V is recommended.
Each board takes its power from the bus, which can be up to 500mA maximum for standard 26 gauge telephone wire. This means that slave boards can power small electromechanical devices such as relays, motors, servos and solenoids using the bus power.
Communications over the bus is done using 5V signal levels and from testing we found that 9600 baud worked well at distances of up to 300m of cable.
The allocated Master device has ultimate control over the bus, and sends out packets of serial data to which the slaves respond, possibly returning their data to the Master.
For this to work - we need a system of bus arbitration, such that there is only one device talking on the bus at any time. In the Nanode, this bus control is done using a pair of tristate buffers, which are left over from the four in the 74HC125 device - where only two were used for the ethernet controller glue logic.
Let us assume that all slaves are listening to the bus - in otherwords their Rx pin is electrically connected to the Transmit line of the Master device via the bus. The master will address a slave by sending a packet of data which contains the (destination) address of that node. When a slave sees its own address come up, it decodes the packet of data, which is usually a command allowing the slave to access the bus, and transmit its data back to the master.
To do this, the slave must enable its Transmit tristate buffer by lowering digital 6. This allows the slave to send data to the bus, where the master, will receive it. By lowering pin 6, the Red LED will also be turned on, and this gives a visual indication that that slave has been selected and that it is accessing the bus. This is the reason that the LED is on pin 6.
The slave sends its data to the master and then releases the bus - by raising pin 6 and the LED will turn off.
Trystan Lea of openenergymonitor.org has written a comprehensive library to allow a master slave network to be set up. See his documentation here about Networked Arduinos
For a very similar project of a wired serial bus which uses the RS485 physical layer see Rob Gray's project. Busnet Project. This will be relevant if the Nanode is to be used as a DMX lighting controller.
Webserver Application (Dave Ingram)
Dave's code is in his Github repository
https://github.com/dingram/Nanode/
Webserver Application with Live Analogue Thermistor Served on Webpage(samthetechie and lambda25)
This code is derived from Dave's example and an arduino playground example shows a live sensor reading from Analogue 0 on the webpage upon page refresh. The trick to getting this to work was to use dtostrf() instead of sprintf() for the float to string conversion.
- Code: https://github.com/Nanode/Webserver-Live-Thermistor-Reading
- Screenshot
- Photo
Connecting to your nanode from behind a router
So far In the above screen shot we are reaching the nanode on the local network directly with its IP address. However, the purpose of this project was to have a remote sensor that you could get to from anywhere. In this case you need to do some basic port forwarding from your external IP (that of your router usually) and the internal IP of the nanode on your local network.
If you aren't familiar with "port forwarding" it is best to google or wiki it, whilst the basic principle is the same, the exact procedure depends on your router.
The General procedure is as follows:
- Connect The nanode to power, Ethernet and the sensor board (in our case a simple thermistor circuit)
- Wait for it to get an IP (for DHCP) or just for it to connect (if you have assigned a static IP in your sketch)
- Connect to your router and find the IP address of your nanode
- Find your External IP by googling "my IP address"
- Make a Port forward from your external IP eg 45.69.124.22 choosing any port you like eg port 5000 to the nanodes IP on port 80 eg 192.168.1.12:80
And that's it, now you should be able to type your external IP and the chosen Port into your browser (eg.45.69.124.22:5000) and be directed to the webpage served by the nanode, from anywhere :D
Keep in mind that if your external IP Changes or your router assigns a new IP to the Nanode (as happens with DHCP), you won't be able to reach it. That is why it is best to set up a static IP in both cases if you intend on having a more permanent set up. If you don't have a static external IP, you can use a dynamic DNS service such as DynDns.com or No-IP to get a fixed hostname (e.g. myhome.dyndns.com) that always redirects to your external IP address.
USB Bootstrap loader
The template for the USB boot loader is USBaspLoader. It needs to be built using these config files.
There are some caveats. Read the notes.
MAC address
The Nanode has a surface-mount chip soldered to the underside of the board containing a unique MAC address.
Code to read this chip is available on github: see NanodeUNIO
To use this code, download it to the sketchbook/libraries folder and start the Arduino IDE. Choose File->Examples->NanodeUNIO->NanodeMAC and upload the sketch to your Nanode. Open up the Serial Monitor. It should print the MAC address in the Serial Monitor box. If you get gobbledygook back or it trips your serial port off-line, see if the baud rate in the corner of the Serial Monitor corresponds to the Serial.begin value in the NanodeMAC sketch and change it in the sketch if necessary. Serial.begin(9600) should work. (Try it with the "HelloWorld sketch also.)
Once you have successfully read your MAC address, you can enter it next to your Nanode serial number in The Complete List.
If you did not have your tiny MAC chip soldered to the back of the pcb during the Nanode Weekend - this can be done at a later date at the space. Ken is next available to do this at London Hackspace on evening of 14th June. You will need a time machine set to this date in 2011.
RFM12 Wireless Module
Wireless connectivity can be added to the Nanode using the Jeelabs RFM12B wireless board. Schematic can be viewed here. No need to solder in the 3.3V regulator or capacitors the board will gets its 3.3V power from the Nanode.
For compatibility with the emonTx from OpenEnegyMonitor.org ensure the 433Mhz RFM12B module is used (this frequency can be used worldwide). JeeLabs use 868Mhz which can only be used in Europe.
RFM12B modules can be bought in the UK from RS, Rapid or Farnell.
The JeeLabs RFM12B board plugs into a special port on top the Nanode. This port is different to the Arduino header just below it. An extra 8 pin female header will need to be soldered in. See image below:
Update 24/10/11 by Glyn Hudson ([openenergymonitor.org]):
There is an error on the Nanode 5 board layout. That stops the Ethernet and RFM12B being used at the same time. See below for explanation and solution:
Explanation:
The INT/IRQ signal from the RFM12B socket is mistakenly OR'ed with the INT from the ENC28J60 Ethernet Chip before going into the 74125 Tri-state buffer which acts as a 3.3-5V level converter.
If the ENC28J60 sets its interrupt line high, then the low going RFM12 interrupts will be pulled up by this high signal so they might only get down to 1.5V which is too high to register as a logic 0. The 10K resistor R13 also pulls the INT line high. This stops the RFM12B working at the same time as the ENC28J60.
Solution:
The solution is to lift pin 4 of the ENC28J60 out of its socket and not solder in/remove R13 (the 10K resistor, one resistor down from the 1 ohm ferrite). This disconnects the ENC28J60's INT line (which is not used) from the circuit and removes the resistor which was pulling the line high.
No additional wire link is needed as first though.
RFM12 example with DHCP and DNS and posting data via Ethernet to Pachube and emoncms by OpenEnergyMonitor: download from github
Bitlash
Bitlash is a interpreted command shell (language) which runs on the Arduino. It takes 14K of program memory, but allows programs to be written from a serial terminal and stored as functions in the EEprom on the ATmega328. It is reminiscent of the early 1980s home computers which executed BASIC directly from power-up.
Bitlash could be used to write simple scripts to automate sensing functions, datalogging or other applications running on Nanode. There is an opportunity to be able to reprogram a Nanode remotely, and have it perfor different tasks.
Bitlash can incorporate any of the Arduino library functions, making it simple to combine Bitlash with existing C-code.
More infomation here Bitlash Wikki
SPI Serial SRAM
On the underside of the Nanode 5 pcb is a footprint to accept a SPI memory deviice. This can be EEprom, data flash, SRAM or FRAM (ferroelectric memory).
I have done some test code for the very cheap (£1.20) 23K256 spi SRAM which is a 32K byte device.
You can find my test code on the following Github Gist
https://gist.github.com/1020771
There is also an Arduino library to support this device - find it here
If you intend to run the SPI SRAM, you will need to modify the way the board is powered - so that everything runs off 3.3V. See below for details.
Running the board on just 3V3
Nanode 5 uses both 5V and 3V3 to run the on-board devices. This has been done mainly as a convenience so that it is compatible with Arduino and Arduino shields which generally use 5V.
However, there are an increasing amount of low power devices which only need 3V3, such as the on board ENC28J60 ethernet controller and the spi memory device on the underside of the pcb - so advanced users may wish to modify their boards to run solely on 3V3 - particularly if they are to access the spi SRAM.
First you have to identify where 5V is produced or enters the pcb. Either the red wire of the FTDI cable, the USB jack or the 5V 7805 regulator. Having identified these sources you need to isolate them or in the case of the regulator modify so that they produce 3V3.
One way would be to remove the existing 5V 7805 regulator and replace it with a 3V3 regulator, and then cut the pin on the FTDI connector that feeds 5V to the pcb and wire a link from this severed pin to the new input of the newly added 3V3 regulator. For completeness you would also need to cut the 5V input track that comes from the USB socket.
Once you are feeding the 5V into the new 3V3 regulator, you need to connect this 3V3 to the existing 5V rail. The easiest way is a wire link which connects pins 2 and 3 of the Arduino shield "power" connector.
A pictorial guide to this modification will be provided later.
RESTduino
RESTduino provides a way to directly control the Nanode hardware from a client - server session. The commands that you want to run on the Nanode are encoded into the URL. For example turn I/O pins on and off or read an analogue temperature sensor.
We hope to combine RESTduino with the bitlash command interpreter to make an interactive way of running scripts on Nanode and editing them remotely.
Here's what Andy Lindsay says about RESTduino and how to run it on your Nanode.
EtherShield RESTduino
- IMPORTANT NOTE **
This version of RESTduino is for ENC28J60 based ethernet shields only, not the Official Arduino Ethernet Shield, these use the wizznet chips, it is very heavily based on the original RESTduino by Jason Gullickson, full details at: http://jasongullickson.posterous.com/restduino-arduino-hacking-for-the-rest-of-us. Full thanks and credit go to Jason for the original code and ideas. I have taken his work and massaged it into an application that works with the ENC28J60 based ethernet shields.
I've also updated the demo to use 3 sliders to change the colours on a RGB LED.
This should also be compatible with the Nanode boards described at http://nanode.eu
RESTduino is a simple sketch to provide a REST-like interface to the Arduino via the Ethernet Shield. The idea is to allow developers familiar with interacting with REST services with a way to control physical devices using the Arduino (without having to write any Arduino code).
Of course some flexibility is traded for this convenience; only basic operations are currently supported:
- Digital pin I/O (HIGH, LOW and PWM)
- Analog pin input
Later versions of the sketch may provide additional functionality (servo control, etc.) however if you need more than just basic pin control you're probably better off learning the basics of programming the Arduino and offloading some of your processing to the board itself.
Getting Started
First you'll need an Arduino, a ENC28J60-based Ethernet shield and the Arduino development tools; here's some links to get you started:
- Arduino Uno (adafruit): http://www.adafruit.com/index.php?main_page=product_info&cPath=17&products_id=50
- EtherShield (nuelectronics): http://www.nuelectronics.com/estore/index.php?main_page=product_info&products_id=4
- Arduino development tools: http://www.arduino.cc/en/Main/Software
Or you could use the Nanode, http://nanode.eu which combines both the Arduino functionality and the EtherShield on one board. If you use a Nanode then you will additionally need the FTDI programming lead.
For testing you'll want some hardware to connect to the Arduino, the demo uses a common cathode RGB LED connected to pins 3, 5 and 6. Connecting single LEDs between the pins and ground will also work.
Load up the sketch (EtherShield_RESTduino.pde) and modify the following lines to match your setup:
static uint8_t mymac[6] = { 0x54,0x55,0x58,0x10,0x20,0x35};
This line sets the MAC address of your ethernet board;
static uint8_t myip[4] = { 192,168,1,177};
The next line you'll need to modify is this one which sets the IP address; set it to something valid for your network.
Now you should be ready to upload the code to your Arduino. Once the upload is complete you can open the "Serial Monitor" to get some debug info from the sketch.
Now you're ready to start talking REST to your Arduino/Nanode!
To turn on the LED attached to pin #3 (currently case sensitive!):
This will set the pin to the HIGH state and the LED should light. Next try this:
This will use PWM to illuminate the LED at around 50% brightness (valid PWM values are 0-255).
Now if we connect a switch to pin #2 we can read the digital (on/off) value using this URL:
This returns a tiny chunk of JSON containing the pin requested and its current value:
{"2":"LOW"}
Analog reads are similar; reading the value of Analog pin #1 looks like this:
...and return the same JSON formatted result as above:
{"a1":"432"}
Javascript/jQuery Demo
A simple example of how to interface with RESTduino via jQuery is included as DemoApp2.html.
This page displays 3 slider controls (via jQuery UI) which when adjusted will set the PWM value of Pin #3, #5 and #6 to the value selected by the slider. These then change the appropriate colour on the RGB LED.
If you look at line 32 you can see where the REST URL (you'll need to adjust this for the IP address of your device) is constructed based on the selected value of the slider and on lines 53, 63 and 73 an AJAX request is executed passing the URL constructed above to the Arduino.
Combining Bitlash and RESTduino to make a simple Scriptable Device
Bitlash is a simple interpreted script language which runs on Nanode or Arduino. It allows you to define new functions, store them to EEprom memory and to control the I/O port pins with a few simple commands typed over the serial port. It's a little reminiscent of the late 70's early 80's home-computers that from power-up ran an interpreted basic. It's better than Basic because it ties in with the Arduino libraries and function calls, and you can mix your C code with Bitlash running in the background - it just seems such a cool idea as an interface to a simple microcontroller.
Bitlash has a Telnet example, so that you can Telnet into it remotely and edit scripts to control different things. Well you could - if our TCP/IP stack supported a Telnet Client. Unfortunately it doesn't, so we have to find another way of getting our command line data up to the Nanode.
One neat way of doing this is to embed the command line at the end of the URL you send to your Nanode server, and then persuade the Nanode to send you something useful back.
Suppose your Nanode is at IP Address 192.168.0.105 and has the means to serve a simple web page assembled from HTML and text in a small text buffer. Lets call this page page_one
HTTP allows for subfolders, so if your page was in a subfolder called password, you could type
http://192.168.0.105/password/page_one and it would serve the page.
If however you don't spell password correctly, the device will return with a 404 error - page not found. This simple mechanisms allows very crude password control over what is served - important if you don't want everyone tinkering with your Nanodes.
I've been looking at the RESTduino example - and it is quite simple to see how the code parses through the URL looking for backslashes and stripping out the parameters contained between them.
The command buffer is set to 50 characters - but I am sure we could extend this to get a good line length - say 127 chars.
So a merge between REST and bitlash would just have to have the REST command line buffer deposited into the bitlash command line buffer (make them one and the same) and bitlash will execute the commands included in the URL.
There is then another string buffer called the Client line - and this is used to send text back to the client. Again bitlash would populate this with the output response from the executed command and send it back.
So let's assume there's a Nanode lurking at IP Address 192.168.0.105
Bitlash sends its ">" prompt to the Client line
The user then wants to get the Nanode to print the answer to the sum 2 + 2 so the User types into the URL window of their browser
http://192.168.0.105/bl/PRINT 2+2 <CR>
The REST code, parses the URL from its command buffer until it finds the first backslash after the IP address where it encounters /bl and so it knows what next is going to be a bitlash command rather than a REST command
/bl/PRINT 2+2 <CR>
it then takes the PRINT 2+2 up to the final <CR> and puts that into the Bitlash command input
Bitlash parses and executes this command and prints 4 back into the Client's Line, followed by a newline and its > prompt.
To make this nice and elegant we would just need a bit of processing code or Python, which accepts lines of text commands and precedes them with the http://192.168.0.105/bl/ header.
IPv6 and uIP
uIP is an alternative TCP/IP stack written for resource limited micro-controllers.
Guenther Hoelzl has combined uIP plus the ENC28J60 library from Guido Socher, to make an IPV6 implementation - which will run on any Arduino like device with ENC28J60 ethernet controller - including Nanode of course.
http://sites.google.com/site/ghoelzl/ipv6ethershield/ipv6_telnet_server
1st August - Stephen Early @sde1000 reports that he has successfully ported uIP to his Nanode and it responds to pings and DHCP now working! - Good work Stephen - we look forward to further developments along these lines.
Stephen's NanodeUIP repository: http://github.com/sde1000/NanodeUIP
25th July 2016 - While the rest of the world has moved on to other things, @njh has written a minimal IPv6-only library for Nanode/Arduino, called EtherSia:
https://github.com/njh/ethersia
It uses less programme memory and RAM than uIP/Contiki.
Jee Labs EtherCard Library
The Jee Labs EtherCard Library works on Nanode with no modifications whatsoever. It even uses pin 8 for SPI chip select. Examples and details on maniacbug's blog.
Tuxgraphics I/O Web Server
Tuxgraphics were the first company to produce a board based on the combination of the ATmega and the ENC28J60. In fact, most of the library was written originally by Guido Socher and Pascal Stang working for Tuxgraphics.
Whilst the original library has been updated and modified by others, much of the basic ENC28J60 low level driver code has remained and is common across any device using the ENC28J60.
The Tuxgraphics web server is not a normal web server. It is an IO-web server. It reads sensor values or IO-pins and it controls digital output lines or relays. It is as well possible to have analog output lines providing arbitary voltages between 0V and 3.3V by using a R2R-ladder DAC.
Sometimes you want to have more digital output pins than the microcontroller you are using provides. You can either switch to a bigger microcontroller chip or use a 74hc595 port expander. This article focuses on the 74hc595. Using multiple 74hc595 chips you could in theory have an infinite amount of output lines on a single ethernet board.
The advantage of the 74hc595 is that you save on wires if you want to have the 8 additional output pins in a different place. There is a serial connection between microcontroller and 74hc595. The cable length of that connection should however not be more than a metre (3ft).
The 74hc595 chips can be chained to provide 16 bit output ports or more without occupying any further output lines on the atmage.
For another article on IO-web servers which provide digital and analog input lines together with digital output lines see "Using the tuxgraphics embedded web server to control scientific equipment".
Here is the file download area
LCD control
Rafael connected a 44780 LCD to his nanode, and provided it with a web interface - see his blog entry
Temperature to Pachube
Based on Victor Aprea wickeddevice code to send Nanode's data to Pachube, here is a tutorial to send thermistor's temperature to pachube: Nanode and Pachube for the rest of us.
Nanode’s DHCP Starvation Attack
Is not an attack, but just to test your dhcp server's capabilities. Also includes a lame (but working) version of an udp flood. Nanode’s DHCP Starvation Attack
Streaming Internet Radio
Nanode is great for streaming internet radio using a VS1053 MP3 decoder and the uIP TCP/IP stack.
More details at Arduino on Ice: Internet Radio via Shoutcast
NanodeUIP Web Server
Here's another take on a web server for Nanode, allowing control and monitoring of a Nanode with a mobile-optimized interface. See all the details at Control and Monitor Arduino Over the Web Using ENC28J60.
Simple hack to cool the 7805
Found it necessary to cool the 7805 when the device is fed by a 7.5V DC wallwart.
A simple heatsink does the trick - and by sheer co-incidence it can be folded over the elco's.