|
|
Recently I made a presentation to the Nanode application development weekend to demonstrate how to send a new sketch to a Nanode. The idea is that the nanode is a network connected device and with a small addition to the ENC28J60 library it would be possible for it to act as a simple TFTP server and accept new code uploads or poll a remote server to check for updated sketches that can be downloaded.
The demonstration on the day conisisted of a Nanode with additional SRAM installed on the empty pads on the underside of the board. The nanode was also converted to run at 3.3V only as this is a requirement for the SRAM chip. The demonstration nanode had a modified bootloader that checked the SRAM for a magic number at the start and a code length. This then triggered the bootloader to reprogram the main flash. The compiled sketch in .hex format was transfered from a laptop to the nanode using a tftp client.
As detailed in the presentation, there are a number of options for delivering the updated code to the nanode, this was a simple proof-of-concept to demonstrate that once a sketch has been transfered to SRAM it is then possible to reprogram the flash with this new image. The actual delivery mechanism is likely to change in the future but the code in the bootloader should not need to change much.
There are still a number of issues to resolve, such as using an optimised bootloader to increase the available code space, add extra checks to make sure malicious code is not sent or recieved by the nanode.
The bootloader is still available from GitHub
More details and code to follow.иконииконописikoniсвети георги
I’ve been playing around with a couple of Nanode boards for a while now after having an early beta version. Check out the link for full details and specs. The latest version has a few options and I am using one in standard form to connect my CurrentCost electricity monitor to my local lan to broadcast updates. The second Nanode has been modified to use 3.3V instead of 5V and to include the 32K SRAM chip on the underside of the board. This then enables the Nanode to have a lot more storage space than is currently available on the Atmega328 and to also be able to work with a MicroSD card without having to include level shifting resistors.
One frustration I have found with the stock bootloader included with the Nanode kits is that there is no indication that anything is happening when you are uploading a new sketch. The first thing I wanted to do was fix this. I’ve based my updates on the Arduino Optiboot boot loader as this has been cut down and optimised for the Arduino by shrinking its code size and increasing the upload speed, amongst other things.
The Optiboot code allows a LED to be flashed upon restart and to be flashed when data is being transfered. As the existing code was configured to use the Arduino LED on digital I/O pin 13, it was a simple matter of changing the defines for the LED pin.
// nanode LED connected to PD6 - I/O 6
#define LED_DDR DDRD
#define LED_PORT PORTD
#define LED_PIN PIND
#define LED PIND6
Make sure that the line #define LED_DATA_FLASH is not commented out too.
Using a modified makefile to compile the code using WinAVR produces a .hex file that can then be burnt into the Atmega328.
To integrate the bootloader into the Arduino IDE its a matter of creating the nanode directory in the sketchbook/hardware/ directory. The directory tree should be like this:
sketchbook
+--hardware
+--nanode
+--bootloaders
| +--nanodev5
+--cores
| +--Arduino
+--boards.txt
The bootloader .hex file is in the nanodev5 directory, the cores/Arduino contains a copy of all the files from arduino-0022hardwarearduinocoresarduino.
The boards.txt would look like this:
# Optiboot Nanode support
# based on Optiboot from http://optiboot.googlecode.com by Peter Knight, 2010
#
# Nanode support by Andrew Lindsay
##############################################################
nanodeatmega328o.name=[Nanode] Nanode V5 w/ ATmega328
nanodeatmega328o.upload.protocol=stk500
nanodeatmega328o.upload.maximum_size=32256
nanodeatmega328o.upload.speed=115200
nanodeatmega328o.bootloader.low_fuses=0xff
nanodeatmega328o.bootloader.high_fuses=0xde
nanodeatmega328o.bootloader.extended_fuses=0x05
nanodeatmega328o.bootloader.path=nanodev5
nanodeatmega328o.bootloader.file=optiboot_nanodev5.hex
nanodeatmega328o.bootloader.unlock_bits=0x3F
nanodeatmega328o.bootloader.lock_bits=0x0F
nanodeatmega328o.build.mcu=atmega328p
nanodeatmega328o.build.f_cpu=16000000L
nanodeatmega328o.build.core=arduino
############################################################
If all is well then you should see a new board, [Nanode] Nanode V5 w/ ATmega328 on the IDE Boards menu.
You should now be able to burn the bootloader from the Arduino IDE using your preferred programmer.
I’ll get round to packaging this up for the benefit of those that dont have te AVR toolchain installed and are not able to compile their own boot loaders. However, you’ll still need a programmer such as the USBTinyISP, in order to burn it into your Atmega328.
Did I mention the extra RAM? What can it be used for? With a modified bootloader it should be possible to upload code to the SRAM and trigger a reset that then causes the bootloader to check for a valid code image and program the sketch as if it had been received through the serial interface. I already have a simple upload sketch that uses TFTP to transfer a .hex file and writes it into the SRAM. More about this later…
икониПравославни икониикони на светци
I had to laugh at this spam that dropped into my junk folder:
I am The Rt Hon David Cameron MP,Prime Minister, First Lord of the Treasury
and Minister for the Civil Service British Government. This letter is to officially inform you that (ATM Card Number 7302 7168 0041 0640) has been
accredited with your favor. Your Personal Identification Number is 1090.The VISA Card Value is £2,000,000.00(Two Million, Great British Pounds
Sterling).Contact Rt Hon William Hague MP.First Secretary of State for Foreign and Commonwealth Affairs
Email; primeminster@live.co.uk
Tel: ;+447045727044
If anyone falls for this then they are obviously dumber than the originator of the email!
After seeing the work done by Jason Gullicksonism on RESTduino – Arduino for the rest of us and code at https://github.com/jjg/RESTduino I decided to port the sketch to use my ENC28J60 EtherShield library. This is now available at https://github.com/thiseldo/EtherShield_RESTduino and includes an updated demo.
A perfect platform for this code is the Nanode, it provides Arduino functionality combined with an integrated ENC28J60 ethernet all on a single board.
The demo uses a common cathode RGB LED (can be easily modified for common anode) with blue to digital 3, red to digital 5 and green to digital 6. The demo is based on the slider UI demo from the jQuery site. This shows 3 sliders and a square of colour, the sliders change the colour of the square. This also sends an request to the Arduino to update the appriopriate colour value.
To use, just point your web browser at the Nanode, for example http://192.168.1.177/3/HIGH will set pin 3 high. Replacing HIGH with a value in the range 0-255 on a PWM enabled pin will set the PWM value.
http://192.168.1.177/3 will return the status of pin 3 as JSON {“3″:”HIGH”}
Using http://192.168.1.177/a0 will return the analog value of A0 as JSON {“a0″:”123″}
With these calls you should then be able to interface your Nanode or arduino with ENC28J60 based ethernet board with web pages and other apps that can send http requests and receive simple JSON responses.
Full credit to Jason Gullicksonism for the original code, ideas and documentation.
This article describes a simple application to demonstrate the ENC28J60 EtherShield library. It can be run on a plain Arduino or clone and an ethernet shield based on the ENC28J60 ethernet chip (Note: This is not the same as the official ethernet shield). An alternative is to use the Nanode, wiki site at Hackspace which combines the arduino and the EtherShield into a single compatible board. It also demonstrates the network capability of the board and the control functionality included in the Pachube dashboard application.
For this project you will need:
- Arduino or clone and ENC28J60 based ethernet shield or a Nanode
- Pachube account and master api-key
- RGB LED and 3 current limiting resistors, value depends on specification of LED
- Internet connection with router running DHCP server
RGB LEDs
RGB LEDs are available in the UK from:
Oomlout. I received one of these LEDs as a sample in an order and can say it is a good bright LED with a cloudy lens which helps blend the colours.
Earthshine Electronics. I’ve not tried these, but for a pack of 10 they are a bargain!
There are two types of RGB LED, one with a common cathode (negative) and the other with a common anode (positive). Both will work with the example provided the correct option is selected at the top of the example code. If this is set incorrectly then when you expect the LED to be on, it will be off and vice-versa.
Similar RGB LEDs should be readily available in whatever country you reside in.
Setting up Pachube feed
For the demo we are using the Pachube dashboard to create a set of three knobs that control the datastreams in a feed. The datastreams and feed are created in your account when the dashboard is created. The steps are described in detail below and shown in the screen captures.
- Login to www.pachube.com
- Click on the link my api keys. Take a copy of your master API key as you need it in the app.
- Visit the Pachube dashboard app page at http://apps.pachube.com/dashboard/create.php
- Enter 0 for number of switches and 3 for number of dials then paste your master API key in to the box.
- Open the link that says Then click here when you are ready! in another browser window or tab
- you should then see the results with 2 links, one to the dashboard and another for the stream.
- To make things look nice, we should edit the stream first. As per the screenshot below, set the stream names in the Tags fields to Red, Green and Blue then click the Save Feed button.
- Go back to the results tab and open the dashboard URL in another window or tab. It should now have the dials labelled Red, Green and Blue
|
|
|
|
| Get your master API key |
Create the app, select 3 dials |
All created |
|
|
|
|
| Update the feed names |
Access the dashboard |
|
Running the example code
After installing the EtherCard library, launch the Arduino IDE, copy and paste the sketch from https://github.com/thiseldo/EtherCardExamples/tree/master/EtherCard_PachubeRGB. The parts to change are:
- Set the type of RGB LED, use #define COMMON_ANODE for common anode LEDs and #undef COMMON_ANODE for common cathode LEDS
- Set BLUEPIN, REDPIN and GREENPIN to the correct PWM ports used for your LED, defaults are 3, 5 and 6
- Define your Pachube master API key in the HOSTNAME variable. Replace the XXXXXXXXXX part with your API key
- Define the feed number to use in the HTTPPATH. Replace the NNNNN part with your feed number
Upload the sketch to your Arduino or Nanode, plug in the ethernet and away it should go. Initially the LED is Red, then amber while it is allocating an IP address, then green when it is ready to request Pachube data.
Select your browser window with the Pachube dashboard, point your mouse at the end of one of the knobs and drag it round, the value should change on the dashboard. After a few seconds you should also start to see the RGB LED change colour.
|
|
|
| Nanode working RGB LED |
Close up view of RGB LED and current limiting resistors |
This is only an example, however, with suitable code it could be reading a Pachube feed that monitors your electricity usage and changes colour according to how much is being used, i.e. green for low and red for high power usage.
The long awaited update to the EtherShield library is now available, the changes in this release include:
- DHCP support – Now your project can find its own IP address, dns server and gateway addresses
- Fixed length problems in main ip code where packet lengths were being passed as bytes not words so as a result incorrect packet lengths were being seen
- New examples added for DHCP test and Pachube RGB LED demo using DHCP
Find it on Github at https://github.com/thiseldo/EtherShield
This site is now available in mobile format. Just access it from your phone browser. It comes in as text with minimal graphics.
Give it a try, just scan the code to access the site from your mobile phone!

I’ve created a small library to dump received ethernet packets to the serial port. Pull the code from Github at https://github.com/thiseldo/EthPacketDump for more.
See the README file for how to use it.
ИкониikoniИдея за подаръкикони
If you’ve used an Arduino board for a while and have projects built up using it then you may want to use a much cheaper board in your final application and keep the Arduino for development purposes. There are a number of soultions that could involve making our own minimal hardware using strip board, its cheap but can look ugly, or you can got for a minimal board such as the Xino Basic from Ciseco. See range in their eBay shop. The basic kit just needs the Atmega168 or Atmega328, 2 capacitors and a crystal to be fully functional. These extra parts are also available from their store if you don’t already have them yourself. In the end I purchased 2 of the Xino basic kits and two ProtoX prototype boards. I already had a pare of spare ATMega168 that could be used.
Main Features
The pcb supplied in the kit of parts is a good quality part with smooth edges, a good finish and through hole plated. The boards also have a number of unique and useful features:
- Site mounted reset button – no more fiddling about when a shield is fitted on top
- small prototype area including space for a 6 pin surface mount device.
- All the connectors have corresponding solder holes to wire into the prototype area.
- Single LED for power indication, no LED on digital pin 13.
- No FTDI but a connector is provided so a FTDI cable can be used or even hooked up to another Arduino for programming
- No voltage regulator, must be fed by either 5V or 3.3V but not both. A 3.3V regulator may be added on prototype area if a 3.3V supply is needed for a shield.
- The prototype shields include a number of different size smd pads on the top and underside.
- Includes headers so regular Arduino compatible shields can be plugged in, for example ethernet sheild.
Buidling the boards
Building the boards was straightforward as no instructions were provided. At the time of writing this, the suppliers website did not include details of these particular boards. When building, the usual process is to populate and solder the components that are closes to the board first. In this case it as a pair of resistors, then the capacitors, crystal, socket, header sockets and pins with the reset button being last. The following photographs show the sequence.
|
|
|
|
| All 4 kits in their bags |
Xino Basic kit |
Bare PCB |
|
|
|
|
| Resistors and low components first |
Additional components not included in the kit |
Crystal and capacitors |
|
|
|
|
| Board complete |
Underside |
ProtoX prototype shield components |
|
|
|
|
| Decoupling capacitors added |
Underside with pins soldered in. Note smd area. |
The two boards together showing right angle reset switch |
Suggestions for changes to the boards
These are not for the manufacture or design of the board, but how the end-user would put them together differently by using different components. The main changes and updates would be for the ProtoX shield.
- If you plan on stacking other shields then replacing the header pins with stackable headers would be the best solution, headers are available here: 8 pin and 6 pin headers. Please note I have no connection with this supplier, other than being a customer.
- If you plan on using the ProtoX shield above an ethernet shield (original or ENC28J60 based) then the standard headers are too short due to the size of the RJ45 socket. Replacing the headers with longer headers will then overcome this problem as described here
Programming
There are a number of ways to program the Atmega168/328, these are:
- Use a FTDI cable connect to USB and program as if it was a proper Arduino
- Pull chip out and insert into a proper Arduino for programming and development. insert into Xino board when development complete.
- Use the FTDI part of a regular Arduino to program the board. This involves removing the Atmega chip then joining wires between the GND, 5V, Reset, TX and RX on the 2 boards. Then program as normal. The connections are shown here:
Conclusions
This is a cheap solution to those wanting to move a project from an Arduino to a more permanent solution. At around £8.20 you can have a functioning board that would replace your Arduino providing you are not using the FTDI part for communications with your PC. The PCBs are well made and of a reasonable quality, I’m no expert here, this is just my opinion.
This is highly recommended kit for anyone wishing to make a project more permanent for little cost, thereby releasing their more expensive Arduino for other development duties.
After the EtherShield library moving to Github, I have now moved 2 more libraries here. These are the Nokia 3110 LCD display and the H1632 LED Matrix library. Full list of repositories are here: https://github.com/thiseldo
Enjoy!
|
|