Water drop controller

Buzby

Senior Member
Well, yes, but I was trying to see if you could use the existing circuit before removing the connector.

I can make out some of the ICs; the HD64 is the microcontroller, and the AMIC is the ROM for it. The DS1603 is a dual elapsed time counter, it counts the number of seconds the unit is switched on for, and also the number of seconds it's switched off !.

Unfortunately I think it's going to be a herculean task to try to re-use the existing circuit at all, so just remove the connector and solder to that.
 

bfgstew

Senior Member
I am awaiting the delivery of my new 20 x 4 OLED and keypad from Tech supplies so in the meantime I have been learning coding. What a nightmare, for this is something totally new to me and a really steep learning curve and steeper still when I attempt to get this to work with the OLED!!!!!

Here is the basic code, I know there is a mile or so to go to get this how I want but it is a start.

Code:
main:
	let dirsB = %11111111 ;
submainS:
	b5 = 1                  ;Push to make switch to start cycle
	if b5 = 0 then : stop
	endif
	if b5 = 1 then : goto submainV
	endif
submainV:
	b3 = 4                  ;variable input on OLED that will light LED to show how many solenoids chosen
	if b3 = 1 then : let pinsB = %00000001 
	endif
	if b3 = 2 then : let pinsB = %00000011 
	endif
	if b3 = 3 then : let pinsB = %00000111 
	endif
	if b3 = 4 then : let pinsB = %00001111 
	endif
submainD:
	b0 = 4                   ;variable on OLED showing how many drops chosen
	if b0 = 1 then : goto submain1 
	endif
	if b0 = 2 then : goto submain2 
	endif
	if b0 = 3 then : goto submain3 
	endif
	if b0 = 4 then : goto submain4 
	endif 
submain1:
	high B.7
	pause 20                          ;variable that will show on OLED as T1
	low B.7
	goto submainS
submain2:
      high B.7
	pause 20                          ;variable that will show on OLED as T1
	low B.7
	pause 1000                        ;variable that will show on OLED as T2 
	high B.7
	pause 20                          ;variable that will show on OLED as T3
	low B.7
	goto submainS
submain3:
	high B.7
	pause 20                           ;variable that will show on OLED as T1
	low B.7
	pause 1000                         ;variable that will show on OLED as T2
	high B.7
	pause 20                           ;variable that will show on OLED as T3
	low B.7
	pause 1000                         ;variable that will show on OLED as T4
	high B.7
	pause 20                           ;variable that will show on OLED as T5
	low B.7
	goto submainS
submain4:
	high B.7
	pause 20                           ;variable that will show on OLED as T1
	low B.7
	pause 1000                         ;variable that will show on OLED as T2
	high B.7
	pause 20                           ;variable that will show on OLED as T3
	low B.7
	pause 1000                         ;variable that will show on OLED as T4
	high B.7
	pause 20                           ;variable that will show on OLED as T5
	low B.7
	pause 1000                         ;variable that will show on OLED as T6
	high B.7
	pause 20                           ;variable that will show on OLED as T7
	low B.7
	goto submainS
 
Last edited:

Texy

Senior Member
So does the code work as you expected?
You stated that you have are able to get the solenoids for free, so have you tried connecting one up?

Texy
 

bfgstew

Senior Member
Hi Texy,
So far I have compiled the code in its very basic form, just to see if I could do it......... LOL

I still have a long way to go as it needs to work with the serial OLED and keypad, but it works in simulation, so far. When that is done, I can then work on the circuitry and layout.
 

bfgstew

Senior Member
OK, I seem to be making progress with the coding, albeit slowly, but I have come across a bit of a hurdle and am wondering if anyone can give some much needed advice?
The following snippet of code shows 4 pins (B.7, B.6, B.5 and B.4) being used to go high and then low. I want to be able to have those 4 pins go high at variable start times, so if B.7 goes 1st, then B.4, then B.6 and lastly B.5, I also want them to have a pause time between them, then go low in the reverse order so the on and off times match (with me so far?). The code works in simulation but I am going to find getting this to work on the OLED much harder as I want to be able to easily vary what pins go high, what pause time I have and so on.
Please show me an easier way, because it gets harder the more I look at it especially when there are 4 drops involved with 4 solenoids, the example shown is with just 1 drop...................:p

Code:
submain1:
	let pinsB = %10011111 : pause 02 : let pinsB = %11011111 : pause 08 : let pinsB = %11111111
	pause 20                          ;variable that will show on OLED as T1
	let pinsB = %01101111 : pause 02 : let pinsB = %00101111 : pause 08 : let pinsB = %00001111
	goto submainS
 

Texy

Senior Member
I would store the on and off times in an array and use the settimer/timer functions (manual 2, page 223) to create the highs and lows for each port.
Unfortunately arrays are not directly support in picaxe basic, but if you do a search, you'll find a few examples of using, for example, the scratch memory.

Texy
 

bfgstew

Senior Member
Thanks Texy,
I was hoping for something a bit simpler (like me!) as I want it to come up on the screen with the times and able to be adjusted through a numerical keypad.
Just got my OLED kit, so going to build that up and start playing with that.
 

bfgstew

Senior Member
Sorry Texy, didn't mean to sound ungrateful, thank you for your suggestion and will take it on board.

Just built the OLED and fired up OK, did a simple test and it worked first time, I must be getting better!!!!

Now to connect the Rev Ed keypad, this is were it will get tricky for me, how on earth do you connect the thing, yes there are 7 soldering pads on the bottom and NC-C2-R1-C1-R4-C3-R3-R2-NC on the web site but were does each one go to??????
Any suggestions?
 

bfgstew

Senior Member
Many thanks for that Texy, it was looking like I needed to upgrade from the 18M2 to the 28M2, but if I can get this connected with 1 wire and a resistor matrix it will save a lot of space and money.

Hooray, I can progress now, cheers my friend.............:D
 

Texy

Senior Member
They keypad matrix o/p needs to connect to a spare adc pin on the picaxe. Sorry I'm not sure which oled your using - is it serial or parrallel? You mention a 'chip' ?
Texy
 

bfgstew

Senior Member
Its the 20 x 4 serial OLED from Rev Ed with an onboard 18M2+ chipset, I also have a 18M2 chipset which will be used to trigger the solenoids and LED's. The keypad, can it be connected on the 18M2+ chipset or does have to go on the 18M2 chipset?
 

Texy

Senior Member
Its the 20 x 4 serial OLED from Rev Ed with an onboard 18M2+ chipset, I also have a 18M2 chipset which will be used to trigger the solenoids and LED's. The keypad, can it be connected on the 18M2+ chipset or does have to go on the 18M2 chipset?
The keypad will be connected to the picaxe that drives the solenoids and the LEDs. You cannot, or should not program the picaxe connected directly to the oled.
T.
 

bfgstew

Senior Member
Ok Texy, cleared that one up then....................I sound like a right doughnut...................DOH!!!!!!

Thanks for your patience.
 

bfgstew

Senior Member
Ok, read up on the adcsetup and am now more confused than ever!!!!
I connect the output from the keypad matrix to C.2, then what? I just do not understand the set up procedure for it, can anyone explain it a bit clearer for me please.
 

Texy

Senior Member
You may not need to use adcsetup at all. Have you tried
readadc c.2, b10

This loads the adc value on c.2 into byte variable b10

Texy
 

bfgstew

Senior Member
So the readadc sees the input from the matrix, then if a code is written to interpret the variables an output can be determined, i.e. button 1 is pressed and the number 1 is shown on screen?
 

Texy

Senior Member
Yes, and for experimenting and learning picaxe , that's what you should be doing.
What hardware have you got going do far?
Have you used to sertxd function to debug code?

T.
 

bfgstew

Senior Member
I haven't got anything running yet! Still in early stages of building circuit up. OLED and 18M2 are all connected up, next job is doing the keypad matrix, which, thanks to you has become a lot easier, then I can start to test my ability to code something. Just having LED's for outputs at the moment, until it looks like it does what it is supposed to, then add the SCR's and wire up to the solenoids.

Stewart
 

eclectic

Moderator
@Stewart.

Texy's comment re. the circuit is spot on.

Please can you provide a (draft) circuit schematic?
Or at least a flow diagram.

Then folks may be able to help,
before you might make a mistake.

e
 

bfgstew

Senior Member
'Tis in my head at the moment, so going to draft one up later for your scrutiny..........;)

Thanks for your help so far, it is appreciated.

Stewart
 

bfgstew

Senior Member
Here is a rough draft, the 5VDC supply is regulated as per Picaxe manual and serial cable Rx and Tx also as per Picaxe manual, keypad and matrix are as previous post #92.

draft drop schematic.JPG
 

bfgstew

Senior Member
Well, I have managed to build the controller unit up and it all seems to be working fine, even the keypad matrix which I put together, with loads of references from here and the net, managed to get a really good range of voltage across all 16 buttons!!!!! I must emphasise to those who are learning and building their first project that the voltage regulator is a MUST, I am getting a rock steady 5.01V from it now and really does help.
Now to start mastering the dark arts of programming.........Will post a picture of the controller when I have a bit of spare time.
Thanks to Texy for his patience and guidance so far on this project...........I wont let you down.......;)
 

bfgstew

Senior Member
Hi again guys,
Just need a pointer in the right direction please.

I am, as said in last post, learning how to programme, so far so good, I have managed to get the OLED lit up as I want and have understood commands on that bit (just!!!!!)
I am now after getting the keypad to communicate with the 18M2 using readadc, my logic is if I can get a little code just to prove to me that each push button does what it says I will learn a bit more, then can code a bit more, rather than asking someone to rattle out a full code for me. This is the code I have been trying out.

Code:
main:
	readadc C.2,w10
	if w10 > 3 then flsh
	goto main
flsh:	
	high B.0
	pause 500
	low B.0
	end
As said, it is a little code to just show to me that when a keypad is pressed if the readadc value is either higher or lower it will light an LED.
Input voltage is 5.014vdc, keypad is 4 x 4 with resistor matrix and an output range between 1.89v to 3.98v, connected to C.2 on 18M2.
Thanks in advance
Stewart
 

Texy

Senior Member
So what happens when you run the code and either not press a button or press a button?
You could change your code like this
Code:
readadc C.2,w10
sertxd(#w10,cr,lf)
if w10 > 3 then flsh
goto main
to find out what the adc is reading realtime for each button press. You'll need to open the terminal window and set the baudrate accordingly.

Texy
 

bfgstew

Senior Member
Depending on the variable w.10, nothing when I press a button or it flashes on after I download prog!

How do I check realtime, that is a bit advanced for me just now..................!

Thanks Texy
 

bfgstew

Senior Member
Sussed out the realtime window, set baudrate up but nothing comes up in window though after download?????
 

bfgstew

Senior Member
Now getting a mass of 255 scrolling down the screen, when I do push a keypad button it throws up a different number but it is going to fast to see it?
 

bfgstew

Senior Member
Ok read through the mass of numbers and this is what I get.

button 1 - 123
2 - 116
3 - 106
4 - 150
5 - 145
6 - 139
7 - 168
8 - 164
9 - 161
0 - 178
* - 181
# - 176
up - 96
down - 174
left - 133
right - 157
 

Texy

Senior Member
Just put a pause command in the loop if you need to slow it down (look it up in the manual).
Some of those numbers look too close to each other. You might like to look at those resistor values maybe?

T.
 

bfgstew

Senior Member
Success with keypad, can get 0 to 9 on screen and move cursor left and right, also reset screen!!!!

Is it possible to input numeric value anywhere the cursor is rather than direct address (254,121), if so is there a command code please as I cannot find anything more about OLED codes.

Cheers

Stewart
 

bfgstew

Senior Member
Don't laugh but this is my latest code.....................it doesn't work very well but it is still a start for a complete beginner!!!!

I want to have the script on screen and able to change the variables using the keypad so it can run what is showing - difficult bit!!!

I have only put in for 1 solenoid to run, I think 4 is a bit much just now, so going to concentrate on this for now.

So any pointers anyone please? All I get is the script coming up, then a bunch of zero's and then nothing, apart from B.7 lighting when a hit the start button (1 success)!

Code:
;#Picaxe 18M2 Water drop controller with OLED 
init:
	pause 500            
      serout C.1, N2400, (254,1)
      pause 500
      serout C.1,N2400,(254,128,"Solenoid Select -(0)") ;select solenoids to use ( ) is the variable 1-4
	serout C.1,N2400,(254,192,"Drop Select - (0)")	  ;drop selection ( ) is the variable 1-4
	serout C.1,N2400,(254,148,"P1-0000 P2-0000")      ;P1 - P8 is the pause time between drops 0000 is the varible time
	serout C.1,N2400,(254,212,"P3-0000 P4-0000")
	serout C.1,N2400,(254,168,"P5-0000 P6-0000")
	serout C.1,N2400,(254,242,"P7-0000 P8-0000")    
	pause 500
	let dirsB = 255
mainA: 
	readadc 2,w10                                     ; read keypad input to C.2 adc  
	read b1,b16
	serout C.1,N2400,(254,147,#b1," ")                ;variable inputs to OLED screen to show time selected
	serout C.1,N2400,(254,208,#b1," ")
	serout C.1,N2400,(254,152,#b1,"    ")
	serout C.1,N2400,(254,160,#b1,"    ")
	serout C.1,N2400,(254,216,#b1,"    ")
	serout C.1,N2400,(254,221,#b1,"    ")
	serout C.1,N2400,(254,172,#b1,"    ")
	serout C.1,N2400,(254,180,#b1,"    ")
	serout C.1,N2400,(254,246,#b1,"    ")
	serout C.1,N2400,(254,254,#b1,"    ")
	goto mainB
	
mainB:
	readadc 2,b15                               ;b15 is the start button to run programme
	if b15 = 175 then main1
	goto mainA
main1: 
	pause 50                                 ; 1 drop
	high B.7
	pause 50
	low B.7
	goto mainA
	
main2:
	pause 50                                 ; 2 drops
	high B.7
	pause 50
	low B.7
	pause 50
	high B.7
	pause 50
	low B.7
	goto mainA
	
main3:
	pause 50                                  ; 3 drops
	high B.7
	pause 50
	low B.7
	pause 50
	high B.7
	pause 50
	low B.7
	pause 50
	high B.7
	pause 50
	low B.7
	goto mainA
	
main4:
	pause 50                                   ; 4 drops
	high B.7
	pause 50
	low B.7
	pause 50
	high B.7
	pause 50
	low B.7
	pause 50
	high B.7
	pause 50
	low B.7
	pause 50
	high B.7
	pause 50
	low B.7
	goto mainA
 

premelec

Senior Member
Not sure what keypad circuit you are using - I have used a 6 resistor voltage divider type well - since READADC is ratiometric it doesn't care about power supply variation and has good reading spread.
 

premelec

Senior Member
Great! - that's what counts! I looked back in my files and another difference is the circuit I used has monotonically changing values with the number pressed correlating with the pressed number.
 
Top