Wednesday 30 October 2013

Tank connections and 80 micron mesh ordered

To join the tanks I ordered 4 Overflow Tank Connectors 22mm

This has a 22mm thread on it, which is the same as the one that a washing machine uses.

So I ordered some 80 micron stainless steel mesh

after seeing some filters built into 22mm washers for washing machines.

Consequently I have also got some 22mm connection tubing

Tuesday 29 October 2013

Growing tanks acquired

I got a couple of plastic containers to use as growing tanks for an ebb & flow setup from Wilkos. It says £5 there, it said £ on the shelf in the store but at the till they were £3.99

The plan is to pump water from a store into one of them through 10mm pipe and have a 22mm overflow connector feed the second one and another 22mm overflow exit that one and return the water to the store. This means that the containers won't overflow.

A second overflow connector in the bottom of each one container will feed into the solenoid valve I ordered yesterday. This will be activated for the drain cycle to make sure that the water stock is completely removed. The water removed in the drain cycle is filtered through an 80 micron passed into the recycling phase where nutrients and pH are set to appropriate levels and other processing such as uv exposure for removing biological pathogens such as pythium can take place.

Separating the flood store from the recycling phase means that the pH and ppm probes can be utilised across multiple growing areas. The probes are the most expensive parts of the system so this reduces costs when scaled. The UV can also be used across growing areas.

The tanks and connectors in the "grow room"

Monday 28 October 2013

First controlled flow.

I got my first reading from the flow meter. The instructions reminded me to use the pull up resistor. The code is a bit basic.

Octave code for plot
times = [ 66.192 67.180 68.180 69.180 70.180 71.180 71.280 72.180 72.280 73.380 75.180 75.480 76.180 76.580 77.180 77.680 78.080 78.780 79.080 79.880 80.080 80.980 81.800 82.080];
ticks = [ 34 101 105 750 833 836 846 847 862 921 923 942 944 964 967 1018 1021 1072 1075 1132 1137 1196 1200 1266 ] ;
plot(times, ticks);

This isn't the best data but it's late and I want to go to bed. It's supposed to start with a low flow and then get to a steady state, this is to prevent the flow meter being overwhelmed. I'm sure at this flow rate that there is no real danger of that but it was the right idea to start with.
The k-factor is 1120, that is 1120 ticks per litre. Next time I shall see about measuring amounts.

Solenoid valve ordered

I have ordered a normally closed, 240V solenoid valve with 10mm pipe connections - datasheet

The device was £19.99; ex VAT but eventually cost me £31.08 included VAT and delivery.

Sunday 27 October 2013

Making danger

Putting yesterday's bits together. I have the relay gaffer taped into a pop bottle and the pump sitting in a 25 litre bucket. I have checked that the pump runs from energising the relay. All good.

Time to write to code for the NXP. First off for sensor testing purposes is to get the TCP / IP running. The simple UDP sender already found a checksum bug in the supplied library. Oh well, at least the packets still show up in Wireshark. Let's hope TCPSERVER on Linux will ignore it.

Off to Wickes / B&Q now to find some plumbing bits.

Saturday 26 October 2013

Ready to get my feet wet

I bought a 12v relay from Maplin that will switch 240v to power the pump I have with a 10mm outlet. I have wired it all up and tested the switching action. Success. I've put pins on the flow meter (snipped LED legs) and made signal cables for the relay with more pins from an old Nokia power supply that had an inline step-up adapter.

Luckily I had a 3 pin mains socket, they wanted over £ for one in Maplin. Mine still has the 99p sticker from Wilkos.

That means I'm ready to start pumping some water.

Thursday 24 October 2013

Toodle Pip

The PVC tubing has arrived. It is 10mm inside diameter. I should have measured the darn pumps because although they look the same size they are, in fact, 8.5mm diameter. So I ordered some 8mm / 10mm tube which will be here next week. Good news is that it fitted the flow meters, which is the specification I took the measurement from. OOh, I happen to have a 600 L/H submersible pump with a 10mm fitting so I can commence the flow meter testing.

Thursday 17 October 2013

Tuesday 15 October 2013

Plumbing

The flow meter is specced at 3/8" push on fitting so that's a good place to start because the pumps have no specification given.

Having looked it it, it might make sense to think about some clips but lets not spend cash needlessly for now, wait for normal cables ties to fail.

The flow meter also says that it should have a pre-filter for 80 microns, that is 0.08mm. "Mesh 200" is 0.075mm so this size is the most appropriate.
I have found some mesh on ebay which is £2.99 per 15cm x 15cm sheet but there are also various inline ones, a fuel filter for instance but that's £17.99

Monday 14 October 2013

Direct Pump Control Circuits

My going with dumb pump design it means more pins being used on the NXP. However we still have plenty to play with. P5-P30 on the LPC1768 and P5-P36 on the LPC11U24. The LPC1768 has three UART serial connections so I shall reserve two of those for the sensors. So to keep it to common PINS for some reason, P17-20 used for the flow restricted pumps and P5-P7 for the peristaltic pumps.

The peristaltic

The flow controlled

I made a start on the code at http://mbed.org/

For a quick test, I used this code

#include "mbed.h"

DigitalOut myled(LED1);

DigitalOut a1(p5);

int main() {
    while(1) {
        myled = 1;
        a1 = 1;
        wait(0.5);
        myled = 0;
        a1 = 0;
        wait(0.5);
    }
}

to strobe the motor.

The results were satisfying

Sunday 13 October 2013

Peristaltic Pumps

This is a quick knock up circuit I did on http://circuits.io/

The AT-Tiny uses three wires RX, TX & GND to communicate with the controller. The protocol will say which pump 1-4 and how many mL and the At-Tiny will take care of the rest. Just keep the Enable lines up, no need to for anything else as we're not changing direction or anything. I've left off the possible 4th pump as I haven't got one.

Regular pumps with flow meter

Because of varying head heights of the water storage, return from recycling, etc. issues I have chosen to use a flow meter to regulate water input. The idea being that all water input pumps can be pumping together and shut off once the required amount has been delivered. The flow meter introduces an additional complexity because the flow meter instructions say that the water speed should rise gradually and that air should be prevented from enterting the system. My pumps will be submersed so I'm not sure that will be an issue. For this discussuion that's not really an issue because that is a software problem likely to be quite simple by just modualting the control line.

The flow meter produces 1120 pulses per litre and takes a TTL supply voltage.

This circuit activates either pump, watches the flow pulses and then kills all pumps when the required flow is complete.

Smacked in the KISSer

The smart pump idea, although good, is draining time trying to solve a problem I added to the project. As it eating into the schedule I am going to drop that part and just use the one microcontroller. The rest of the design is the same and the control methods are the same. Bringing back the smart pump idea can be done later and swapped in piecemeal.

Specifically I am finding getting the communication between the controllers more difficult than it should be. Debugging two sets of code at once is hard. Especailly without any on chip debugging. It's just "Did that work? No. Next idea" which is not good methodology. Made worse by working in the simulator! I have a new serial port PCI card coming which I need so I can run the newest version of the simulator, although I'm not sure that will solve the immediate problem. At least I will only be typing on one PC!.

Friday 11 October 2013

Deadline is longer than previously thought

haha the 4 week deadline was just for the planning, not the project in total. That's actulkly due on 6th December! That gives me plenty of time to debug the active pump controls.


However, for now I shall continue on the dumb pump mission so at least I will have a working set of pumps and can reduce the pin requirement later.


Last night I managed to kill the £45 LPC11U24 :( so as a backup in case I kill the LPC1768 I ordered the FreeScale KL25Z, which was only £17.20 thus making it an attractive controller


Useful pdf about interrupts and clocks

Found a useful reference for interrupts and clocks with good examples of setting all the bits to get them working properly. Handy if you've not done it for a couple o'years like me.
But watch out, the = print as - in Mozilla PDF reader!

Thursday 10 October 2013

NXP signalling the AVR

I spent an eternity reading PortD instead of PinD. Thank goodness for the power of web searching. Shame everyone programs in C. They are scared of the power.

NXP code


DigitalOut m1(LED1);
DigitalOut m2(LED2);

DigitalInOut DATA(p21);
DigitalInOut CTL(p23);

void set_data(unsigned char i) {
    DATA.write(i);
    m1.write(i);
}

void set_ctl(unsigned char i) {
    CTL.write(i);
    m2.write(i);
}

int main() {
    CTL.output();
    DATA.output();
    
    while(1) {
        set_data(0);
        set_ctl(1);
        wait(3);
        set_data(1);
        set_ctl(0);
        wait(2);
    }
 }

AVR Code

.include "m16def.inc"

; set portB to output
ser r16
out ddrb, r16
clr r16
out portb, r16

; set portD to input with pull-ups
out portd, r16
out ddrd, r16
ser r16
out portd, r16

; do the do
main:
    in r16, pind
    out portb, r16
    rjmp main

Wednesday 9 October 2013

AVR signalling the NXP

The NXP code is pretty basic

#include "mbed.h"

DigitalOut led(LED1);
DigitalIn DATA(p23);

int main() {
    
    while(1) {
        led.write(0);
        while(DATA);
        led.write(1);
        while(!DATA);
    }
}

The AVR code was a bit trickier as it uses the timer interrupt. Took me a while to get my head round it

.include "TN13DEF.INC"

.org 0000   ;  reset interrupt vector
  rjmp on_reset

.org 0012   ;  timer0 overflow interrupt vector
  rjmp tim0_overflow

on_reset:
  ser r16
  out ddrb, r16 ; set the pin I/O

  ldi r16, 0b_0000_0101 ; set the clock multiplier
  out tccr0b, r16

  ldi r16, 0b_0000_010 ; turn the timer on
  out timsk0, r16

  sei ; turn on interrupts

main:
  nop ; I walk and walk, do nothing 
  rjmp main

tim0_overflow:
  ; negate portb
  in r17, portb
  com r17
  out portb, r17
  reti

Getting the AT-Tiny working with the STK500

Fairly simple, follow online instructions.

  1. AT-TINY13 in SCKT3400D1
  2. Connect the ISP6PIN socket to SPROG1 with the 6-pin cable provided
  3. Connect the PORTE/RST to PORTB/PB5 and PORTE/XT1 to PORTB/PB3
  4. Jumpers VTARGET, AREF, RESET, XTAL1, OSCSEL close; others open

Using it is a bit annoying because you have to take the cables on and off to use the pins.

Tuesday 8 October 2013

Decisions Decisions - Smart or Stupid Pumps?

Do I put the control next to the pumps and free up the controller to just send messages or do I keep them dumb and use the controller to do everything ?

The programmer in me wants to put an AT-TINY13 at every pump and let them do the delivery. OTOH guy says put everything in the middle because there's so much spare CPU power.

An AT-Tiny is about £1. It is attractive to me to make intelligent pumps. But it means programming the AVR and whatever I use as the controller and get them to talk to each other. But this also means that the controller can be less powerful and all it needs to do is talk whatever protocol I devise. A rich protocol, which could even be 9p, seems to solve engineering problems. By standardising with this idea I can expand the range of devices in the family as I go along. I will only have to implement the protocol on the central controller once and not care about that is attached to it.
I'm looking for excuses to make smart pumps. The action at the pump end will be the same whatever controller is used, whether it is the central one or not is irrelevant. If I start with AVR assembler to control the pumps I can always use an AVR CPU to do it and they are not rare.
There we go, that is what I shall do.

Time to Propose a Protocol

At the moment I have a 3 wire serial system. 1 GND, one marked TX and one RX. I need to solidify this idea in text, write some code and test it in real hardware. If things don't go well the next option is to add another wire, which I still have space for if I stick to three peristaltic pumps. Which is no problem for this project. L293D's are under £2 each.

After a couple of days cogitating I have made a decision. I considered a variable length with the msb marking another byte like in UTF-8. However this is over complicated for this little job so I have decided on a fixed length scheme.

One possibility.

The minimum number size bound the amount of liquid in millilitres.
1111 1111 1111 1111 is 65535 which is 65.535 litres. This fits the bill for the 30 litres in the specification.
So the protocol, at the moment, is three bytes long
aaaa aaaP - action and parity bit
bbbb bbbb - lower bits of value
cccc cccc - upper bits of value

The next idea

I realised that it is unlikely that a pump will get a 1.01L instruction. They will usually get 10ml or 10L. However there may be the possibility that the controller has a small and large pump on the same L239D. So let's encode the magnitude in the action, I have plenty of those to go round and the amount can just be a single byte.
aaaa aaaP - action and parity bit
vvvv vvvv - value
This is the most satisfying to me. A message will then fit into a 16 bits.

The Protocol v0.1

ActionValueDescription
0000 00001010 1010All Off
0000 0001vvvv vvvvPump 1, v ml
0000 0010vvvv vvvvPump 2, v ml
0000 0100vvvv vvvvPump 3, v ml
0000 1000vvvv vvvvPump 4, v ml
0001 0000vvvv vvvvPump 1, v L
0010 0000vvvv vvvvPump 2, v L
0100 0000vvvv vvvvPump 3, v L
1000 0000vvvv vvvvPump 4, v L
1111 11111010 1010All on until further notice

The values in the All On and All Off are to make sure that a signal is being sent and not just some line noise.

Wednesday 2 October 2013

Aceeed

There are three acids listed in Resh's hydroponic book

  • Nitric acid
  • Sulfuric acid
  • Hydrochloric acid
  • Phosphoric acid

The trouble will be to find a suitable hose that is acid resistant.

The peristaltic pumps come with silicone tubing and for this the news is not so good. Because of that I have included citric acid in the list.

Acid 20 °CPVCSilicone
Nitricup to 50%Maybe - test it
Sulfuric up to 95%No
Hydrochloric50% - concentratedNo
Phosphoricup to 85%Maybe - test it
Citric10% - SaturatedExcellent

It seems a citric acid solution is preferable for my uses.