
[This project is currently in progress 6/09/2010]
This is going to sound like a cliché wishy-washy 'engineer' thing, where there is a problem, and it requires an engineer to dream of a solution and solve it. Basically my Nan needed a way for the plants in her greenhouse to be watered while she goes away on holidays and such like. Instead of keeping it simple, and mindlessly going on the internet and buying a timer driven valve, I chose to make my own irrigation system controller, that can be configured from a computer.
First Ideas
![]()
Deciding on the BitsI already knew I was going to use an Atmel AVR Microcontroller in this project (because they are ever so great!), ideally one that my STK500 development board supports. I chose the ATMega8 because it met this requirement, and has a serial USART and I2C/TWI bus support. Next, I needed to find a Real Time Clock (RTC) module, so that the AVR could keep a track of the current time. I came across this article on ermicro, and decided to use the Maxim DS1307, as I could learn off the code examples given (also, the IC is easy to find on eBay). The PC interface was going to be via USB (due to the the diminishment of 'real' serial ports on modern computers), using a cheap Prolific PL2302 USB-Serial TTL converter lead which I found on eBay. Finally, to get a 5v power supply for the AVR and the RTC, I purchased a 7805 regulator IC, which can be coupled with a few capacitors to create a dead stable voltage rail from my old manky 12v PSU.I spent a while hunting around for a valve. I needed a valve that would accept 'Hozelock' style fittings on both sides, so that a hose pipe could be fed in both ends. In the end, I found a valve that had 1/2" screw fittings on both sides, which could subsequently accept the Hozelock tap connectors. You can have a look on these eBay Search Results
![]() 1/2" Hozelock connector Having a rummage through my cupboard, I came across a nice aluminium enclosure from an abandoned power supply project years ago. It already had a switch mounted and two holes for LEDs drilled. Upon opening the enclosure, I found a Veelman 240v AC to 12v DC power supply PCB kit already assembled! Although the enclosure is a bit on the large side, it'll save a bit of cash, and look nice and shiny after a quick clean.
SchematicThe circuit is actually very simple, really it's just basic I/O connections to all the different subsystemsBuilding the HardwareThe bits for the 5v regulation circuit came through the post, I thought I'd put it together to see if worked. My multimeter gave me a reading of 5.05v on the output, and this value never changed, I didn't get round to testing it with one of my AVRs to see if the output was clean enough to run a microcontroller. The circuit fits conveniently in one corner of the breadboard, close to the supply rails. I didn't need to fit any type of heatsinking to the regulator, as the load current in question was tiny.
As of now, the hardware is being built Configuration Application DevelopmentI decided that C# would be my choice of language when coming to write the configuration application. This is because I wanted to wean myself off VB6 and VB.NET for writing Windows Forms applications, and so I could learn the industry standard .NET language. I chose the .NET framework as my platform, as it is fairly future proof (i.e. Microsoft are most likely to support it for quite a long time), and because there would be a fair chance that my finished application would run on Mono for Linux/Unix. I had immediately ruled out VB6, as it is unlikely the next version of Windows will have official support for the VB6 runtime components (also, the UI controls look 'old' on Windows XP and above).Currently, the configuration application looks as follows when running on Windows 7 x86. Communication with the controller hardware is provided by the standard .NET SerialPort object.
I made a handy little method in my clsComms class that runs through all the avaliable serial ports on the system [by calling System.IO.Ports.SerialPort.GetPortNames()], and attempts to detect the irrigation system controller on each by sending a CMD_PING request. The advantage of running this detection, is so that the end user doesn't have to supply the COM port at which the controller is connected to [which is susceptible to change even when the same USB to Serial lead is plugged into a different USB port]. I suppose someone with a serial printer wouldn't be too happy when they see a sheet of paper with a single 'p' written on it, printed out every time a detection is run on that port.
So far, I have pretty much completed writing my communications class, designing the form, and some other misc bits. Update: Alpha build of the software now complete, everything seems to work fine although the code is very messy. Firmware DevelopmentWhen writing firmware for AVRs, I use my STK500 development board in conjunction with AVR Studio and WinAVR. I use C as my chosen language, primarily because assembly can be very tedious to write software in. For this project, I wasn't really going to make an exception to this, so the same rules applied this time round. I stuck my ATMega8 in the correct socket, and connected both serial ports to my computer, one for programming the AVR, and the other for communicating with the USART on the chip.
An important aspect of the firmware, is the use of the EEPROM. Data relating to the timings, timing validity, serial/hardware ID, and some misc parameters must be stored in non-volatile memory. The serial/hardware ID is totally unnecessary, but adds the 'professional polish'.
So far, an interrupt raises a signal (SIG_UART_RECV), when data is received by the serial USART. The byte is then clawed from the UDR register, and stuck through a big switch statement, where various bits and pieces are done (such as responding to a CMD_PING request, or reading/writing to/from restricted EEPROM address ranges). None of the RTC routines have yet been implemented, due to the fact it hasn't yet turned up in the post. An alpha build of the firmware has now been completed. It's pretty messy but it seems to work. BuildI thought it would be a good idea to put together a working build on stripboard. I was sadly mistaken when I burnt out my microcontroller by soldering it on directly (the USART has ceased to work), because I was too lazy to buy an IC socket. The same fate was probably suffered by the RTC, now that means another £10 worth of components.![]()
|
Online SoundCloud Downloader, NEW!Download tracks posted on SoundCloud for free in high-quality MP3! SoundScrape.netUseful eBay Links |