Wednesday 25 December 2013

Stability Improvments

It's been a while since my last update and lots of progress has been made.  Today I solved a particularly frustrating problem and thought I would share the solution in case it helps somebody else.

Constant WiFi Shield Issues

I enthusiastically started building the control system for the Aquaponics using an Arduino Uno with an official Arduino Wi-Fi shield.  Almost immediately I encountered constant hangs after a period of about 6 hours where if the WiFi shield was being used, even if it was just a trivial example sketch then the Arduino would just hang suddenly.  After lots of reading I discovered a feature called a Watchdog Timer that I was sure was going to solve my problem.  After messing about for a while I got the hang of the watchdog timer and it was working quite nicely.  Time for another go with the WiFi shield.  Nope, still hanging after about 6 hours regardless of what code I was running.  The watchdog timer was unable to reset the board.  I tried upgrading the firmware on the WiFi shield but alas, no improvement.  More Googling revealed this thread which pretty much confirmed my suspicions that the WiFi shield is not ready for serious use where reliability is an issue.

Resort to Wired Ethernet

Ok, I thought after spending a day trying to see if I could fix the issue as the source code for the WiFi shield firmware was available I realized I was well over my head.  I decided that simply working around the problem was the best approach.  I got a wired Ethernet shield and plugged it into an access point acts as a bridge to the WiFi in the flat.

Memory Constraints

This setup worked nicely for a while but as I implemented more and more features and restructured the code to represent a maintainable, expandable code base I started to begin to run very, very close to the available memory limit of 2048 bytes.  The result was that, the closer I began to run to this limit, the less stable and more frequent the resets became.  I suspect this is due to the code trying to allocate a buffer for an incoming message or something and there isn't a large enough amount of continuous free space.  Everything grinds to a halt and we end up resetting, every 30 minutes or so.  The watchdog time was doing it's job nicely.  It's just a shame it had to do it so frequently.

A quick search of MindKits.co.nz revealed a larger Arduino Mega 2560 with 8k of RAM, 4x more than the Uno.  After upgrading to this larger model I noticed that with a decent amount of memory now being free I no longer got the frequent hanging that I was seeing with the Uno.  Things were looking good then after a few hours, disaster, the board hung again requiring manual intervention.  The bug that caused this was trivial to find, an accidental infinite loop when the web server returns a strange response.  What was concerning however was that the watchdog timer failed to reset the Mega.

Mega 2560 Bootloader and the Watchdog Timer

I uploaded a trivial sketch to confirm that the watchdog was working and sure enough when the timer expired, the Arduino would hang rather than reset.

More Googling led to the discovery that the bootloader that ships with the Mega 2560 doesn't support the use of a watchdog timer but can easily be upgraded with an ISP programmer.  In fact the Arduino IDE v1.0.5 comes with a version of the bootloader that supports the watchdog timer.

Great, I thought, I have a USBtinyISP that should do the job nicely.  Wrong again, the USBtinyISP only supports ROMs up to 128K and the Mega 2560 is 256k.  After further Googling, I discovered that I could use the Arduino Uno itself as an ISP programmer and I could use that to in turn flash the watchdog compatible bootloader to the Mega 2560.

However, no amounts of searching could I find a clear guide of how to wire up the Uno to the Mega to make it go so after consulting the pinouts for both shields I was able to match up the following:

To Flash a Mega 2560 Bootloader from an Arduino Uno

  1. Open the Arduino IDE v1.0.5.
  2. Tools -> Board -> Arduino Uno
  3. Set the Serial Port
  4. Open the ArduinoISP example sketch (File -> Examples -> ArduinoISP)
  5. Plug the Uno in with the USB cable
  6. Compile and upload
  7. Unplug the Uno
  8. Wire it up to the Mega 2560 with the wiring table below
    Mega Uno
    GND GND
    5V 5V
    Reset 10
    51 11
    50 12
    52 13
  9. Select Tools -> Board -> Arduino Mega 2560 or Mega ADK
  10. Select Tools -> Programmer -> Arduino as ISP
  11. Plug the USB cable back into the Uno
  12. Select Tools -> Burn Bootloader
The process will take about 2 minutes and in my case resulted in the following error message.

avrdude: verification error, first mismatch at byte 0x1e000
         0xff != 0x0d
avrdude: verification error; content mismatch

This didn't matter and my watchdog now works perfectly.

More Coming

I'll be posting more updates shortly explaining progress in other areas of the project.  It is getting closer and closer to the point where it's ready for fish.



















Wednesday 3 April 2013

Grow Beds, Gravel and Siphons

It's been a while since I've updated this.  I've been too busy attending weddings, teaching Brazilian Jiu Jitsu and getting ready for another trip to Brazil.  While the bloging has been slack, I have managed to make time however for some meaningful progress on the system itself.

One of the trickiest parts of this operation so far has been the construction of the grow beds.  After much research I ended up making them out of plywood and lining them with Fireston Pond Gard EPDM rubber.

Frame made of plywood
Lined with EPDM rubber 
Very happy with how it all fits together
The next part was to build the siphons that will take the water from the grow beds back to the fish tank.  This involved various prototypes and failures before I got them working correctly.
It took several attempts to get the bulkhead to seal
Media screen to keep the gravel out
Bell siphon
Complete with gravel.  Second pipe is to gauge the water level.
I ordered a 12v pump and converted an old ATX computer power supply that I had around the house to power it and the other electronics.  To keep this all out of harms way I built a little shelf under one of the beds.  Soon I will tidy up this mess of wires and put the micro-controller in there as well to run everything.



System complete and cycling
Now that the system is complete I have left the pump to cycle water from the fish tank (no fish yet) up to the grow beds and the back to the fish tank via the siphons.  This will further rinse the gravel and give me a chance test the reliability of the setup.  The next step will be to build a swirl filter to remove any uneaten fish food and other waste on it's way from the tank to the grow beds.

Monday 21 January 2013

The Next Step

Aquaponics

After getting to the point where I can eat out of the garden on a daily basis I've decided to move on and have a go at an aquaponics setup.  Aquaponics is where you use both fish and plants in a symbiotic relationship to produce more of each other.  I feed the fish, the fish excrete ammonia into the water and then I run this water through ebb and flow grow-beds.  Bacteria grow in the gravel in the grow-beds to to assist with nitrification which is the conversion of ammonia to nitrite then in turn to nitrate.  The plants then consume the nitrate and the now less-toxic water is returned to the fish.

The end result is after a lot of setup effort you have edible fish and edible plants that grow like crazy. I will be monitoring this system using Arduino micro-controllers and an Android app that I'm going to write.

It's a pretty simple system

First I need a raised greenhouse to grown the plants in that is higher than the fish tank. This is so I only have to pump water up to the grow beds and gravity can return it to the tank.
Frame getting constructed
Big mission to get everything home!
Building the base
I've been bolting it all together rather than nailing it so that when I eventually move out of this flat I can unbolt it for transport.
Trying to work out how we get the greenhouse on now
Finished base with tomato plants
Tomatoes
In the mean-time I have just put some very wind battered tomatoes in there for some shelter.  In the next few days I will build the grow beds.  I have also ordered a 1000 litre IBC tank - this will be the fish tank for the prototype.
Fish tank... 1000 Litres
I will be posting updates as I make more progress.

Wednesday 16 January 2013

Food Everywhere!

A year ago I started the long process of organising my backyard.  This was initially only due to the fact that the lease agreement stated that I had to maintain the grounds.  In the meantime I'd got much more interested in nutrition than I previously had been and as a result my food bill has gone up dramatically.  This led me to wonder just how much food I could grow around my flat and how much money it could save me.

After a bit of trial and error and a few failures we now eat something out of the garden every day.

 Spinach
 Kale
 More Spinach, Parsley, Coriander etc
 Tomatos etc











There are plenty more ways I can grow more food and I intend on using all of them.  Now my goal has changed from just trying to grow some food to actually seeing how much might be able to be produced from my flat.  Watch this space.

Monday 2 July 2012

Aussie Carbon Tax - A Kiwi's Perspective

Bluewaters Coal Power Station - WA
This week my Facebook news feed has contained some of my Australian friends ranting.  Their frustration at the moment is regarding the carbon tax that the Gillard government has just put into place.

Their comments range from general complaining about the price of things going up to plain climate change denial.  I used to be a fairly staunch climate change denier but then I read about it in depth and unfortunately, the evidence is overwhelming.  All of this prompted me to do some reading about what the Australian Carbon Tax really is and how it will really affect people.

The gist of it is that the worst polluters will be made to pay $23 per tonne of carbon emitted, the price will be dictated until July 2015 when it will be switched to a cap-and-trade market based price.

The list of the worst polluters is expected to cover about 60% of Australia's carbon emissions.  The main culprits are power generation, mines, heavy industry and landfill methane.  The result of this is that household bills are expected to rise by about $10 per week and construction cost rises are expected to be at the lower end of the 0.7% to 1.8% range predicted by building companies.

So, whats happening with the money then?  Well, the tax-free threshold has risen from $6,000 to $18,200 and will rise to $19,400 next year.  The changes mean all those earning less than $80,000 will receive a tax cut.

The delusional Larry Pickering goes so far as to call this Marxist and is an advocate of Abbots alternative direct action plan to combat climate change.  A plan not supported by Australian economists.

This criticism of modest wealth redistribution is what really confuses me.  When wealth is distributed more evenly, everything gets better in a given society.  I'm not talking about communism - we all know that would suck.  What I'm talking about is taking steps to prevent the levels of inequality that America is experiencing at the moment and is reaping social havoc.

The TED talk below illustrates my point very nicely.


So, what the Aussies have is a tax that will encourage the worst polluters to evolve or disappear which will make the country nicer to live in (who wants to live around pollution?) while increasing income equality which will also make the country nicer to live in.

I would happily put up with a similar measure here in NZ.  It's a shame that the Key government is going down the direct opposite path by granting oil exploration rights to overseas companies and selling our power companies.  The sale of our power companies becomes a big problem when we sign the Pacific Free Trade Agreement.  When we have done that and overseas investors try to mine more and more lignite in Southland, those investors will be able to sue us (the New Zealand tax payers) for lost profit in the event that we ever actually take decent measures to curb climate change.

To me the Aussie Carbon Tax is at worst just a bad tasting good medicine that will improve Australia and the rest of the world.

Sunday 4 December 2011

Operation Oven

This week I came across the following TED Talk where the speaker talks about growing plants inside her New York city apartment using a hydroponic system made out of recycled coke bottles.  I really wanted to make one of these systems because it looked cool but then I looked out the window and saw this area outside that gets all day sun, growing an impressive amount of rubbish and I thought "you really should start there."



Meanwhile about 3 months ago the oven in the flat stopped working with the digital display choosing to display gibberish and it refusing to turn on.  My flat itself is awesome and really cheap and I want to maintain a good relationship with the landlord on the theory that if I keep him happy I believe he will just leave me alone and continue to forget to charge me market rates for the place.

However one of the terms of the tenancy agreement is that I have to maintain the grounds and that hasn't really ever happened.  As a result the place is a disgrace with what once might have been a cool garden now a mess.  I have been meaning to do something about it and the landlord has been hinting but until today it has been put in the todo pile.  If I want to hit him up for a new oven then I may as well do my end of the deal.

The first step is to get rid of the existing abomination.

 Now I can finally start to see what I'm dealing with.


Nek Minnit

The eventual goal for this small area is to grow some food.  If I am going to be maintaining grounds then I'm going to be using it to make food that I can eat rather than planting and weeding pretty flowers.

Over the next few days I'll reveal my next steps for this area...

In the meantime, with Wikipedia telling me that putting food scraps in landfills creates methane problems and that methane is a greenhouse gas 72 times stronger than CO2, my continuing to throw away food waste is really only driven by lazyness.  Since I'm trying to be less of a piece of shit these days I've started composting.  We used to do this in Dunedin when we had to pay for rubbish bags but since moving to Auckland this had stopped.  With recycling and composting you really start to notice that the amount of rubbish you send to the landfill plummets.

Compost is also awesome for growing things and can contain heaps of nutrients that plants love to eat.  In a few months I'll be able to start feeding plants my waste then I can eat the plants... cunning.