Category Archives: my projects

A (Horrible) Method of Hard Resetting an Arduino

Ethernet ArduinoLast year I worked on a little home project involving an Arduino Ethernet board. It all worked perfectly except that my program would hang after a few days operation. The time to failure wasn’t consistent, sometimes it failed after only a couple of hours, often it took a week. But sooner or later it would stop sending data across the network and require a hard reset. Adding logging told me only that it was the network code that was stuck.

It turns out that this is a common problem with the Arduino Ethernet hardware. The fancy pants W5100 TCP/IP chip just goes on strike and needs to be reset. Using the Arduino’s watchdog interrupt to software reset the CPU isn’t enough, the W5100 needs to reset as well.

Reading the schematic provided a clue. The W5100′s reset line is connected to the normal Arduino reset line (via a small reset controller IC), so resetting the Arduino by pulling the RESET line low resets the network chip as well.

There is a right way to do this that involves a bunch of extra circuitry, and a wrong way that involves a piece of wire.

Photo of Arduino showing a wire soldered to the reset pin
Connecting the reset pin to one of the Arduino’s digital IO pins is not recommended. The CPU requires that the reset line is help low for a certain amount of time to reset correctly and it can’t hold the line low and reset simultaneously. That wouldn’t make sense. Except that when I tried it the CPU reset every time and took the network chip with it. There is a capacitor between the RESET pin and GRD that I think helps out here, but my electronics is very weak.

I am still making use of the watchdog interrupt but instead of letting it reset the CPU, I handle the interrupt and bring the RESET line low using the digital IO pin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <avr/wdt.h>
 
#define RESET_IO_PIN 3
 
void setup()
{
	//  Some people recommend setting the IO pin to HIGH on start up
	//  but it is better to leave it floating as INPUT. Pulling it HIGH interferes 
	//  with the normal reset mechanism, and the pin is held HIGH by a pull-up   						  
	//  resister anyway
	//  digitalWrite( RESET_IO_PIN, HIGH );
	//  pinMode( RESET_IO_PIN, OUTPUT );
 
	noInterrupts();
	wdt_reset();
	// these cryptic lines set the watchdog timer control register
	// to trigger an interrupt (not reset) after 8 seconds. The normal
	// Arduino function assumes you want to reset, so we can't use it here.
	// See the ATmega328P Datasheet section 10.9.2 for the gory details
	MCUSR &= ~(1<<WDRF);
	WDTCSR |= (1<<WDCE) | (1<<WDE);
	WDTCSR = (1<<WDP0) | (1<<WDP3) | (1<<WDIE); /* 8.0 seconds */
	interrupts();
}
 
ISR(WDT_vect)
{
	// The watchdog timer has fired, pull the pin low
	digitalWrite( RESET_IO_PIN, LOW );
	pinMode( RESET_IO_PIN, OUTPUT );
}
 
 
void loop()
{
	wdt_reset();
	// do some stuff here, if you don't call wdt_reset() more frequently
	// than 8 seconds the Arduino will reset
}

I spent weeks trying to figure out what was going on, hopefully this post will help somebody in the same situation.

Blog Updates

I’ve been doing some general tidying up of the WordPress installation running this blog. This includes some new plugins that revamp the commenting system. I was getting increasing amounts of spam comments and the old anti-spam plugin just wasn’t helping against what appeared to be manually entered spam comments.

Let me know if you see anything that looks (unintentionally) weird.

279 New Zealand Blogs

For the last few years Ken Perrott at Open Parachute has been compiling a monthly ranking of New Zealand blogs. His list has the pleasing side-effect of being a good way to discover random blogs you would not otherwise come across.

I decided it wasn’t visual enough:

Small montage of 279 blogs(click to view montage)

This little project used Paparazzi! to grab the websites, ImageMagick to wrangle the images, a few lines of Python, and an evening’s work.

Home Made Creme Eggs

Ever read a recipe and know that it is your destiny to try it? I saw this fantastic method for making creme eggs on food52.com and was obsessed. It is a bit more fiddly and time-intensive than most things I make but the results are impressive even if mine look nothing like the photos on the web site.

The process of making creme eggs

My ingredient list was slightly adapted for metric measurements and local supplies:

½ cup of golden syrup
85g of softened butter
Tiny pinch of salt
1tsp Vanilla essence
2⅔ cups of icing sugar
Bag of dark chocolate bits
Yellow Food Colouring
Coconut Flavouring
Toothpicks and Potatoes

It took about 3 hours from start to finish but a lot of that time was waiting for the mixture to cool down in the freezer to a workable consistency. I completely messed up tempering the chocolate, but that just makes them slightly harder to eat.

The Very Hungry Caterpillars

Two monarch caterpillars munching on a swan plantI have written before about how much I like monarch butterflies. Their caterpillars are also very cool, huge with bright yellow/white/black stripes to let everyone know they mean business. This year I decided I should do more to attract monarchs to my property, so I purchased two large swan plant saplings but didn’t quite get around to planting them. Before I knew it the plants were colonised by caterpillars who proceeded to eat both down to the stems in a matter of weeks.

I know that the caterpillars are storing up energy for the wonder than is metamorphosis, but eating two whole plants seems a bit greedy.

Today I went out to find the last two caterpillars (I don’t know what happened to the others, nothing eats them so perhaps they just left looking for other food) rapidly consuming the last edible fragment of the last plant. Peak Swan Plant was long passed and the caterpillars had doomed themselves with their wasteful overuse of resources. I had to rush out to buy another three plants just to keep them alive. These are turning into very expensive pets.

In other garden news, these Arctotis flowers are very photogenic…
Bright yellow arctotis flower