LED project

LeeWhitt

New Member
I'm currently doing a college project using a PICAXE-28X2 Shield Base (AXE401), what im trying to do is to make 6 LED's light up one after the other but each one opening a solenoid at the same time, can anyone give me the program code for the first 2 LED's to start me off, so i could copy them to finish the rest, my project is going to be a bubble generating water display.

Looking forward to any help,

Cheers,

Lee.
 

bfgstew

Senior Member
Lee, I'll think you'll find you will not get anywhere with a college project if you ask outright for the job to be done for you.

Have you designed and built the circuit?
Have you had an attempt at writting any code?

Read the Picaxe manuals, learn and understand how it works, give it a go, use the Program Editor (downloadable) then give evidence of attemting to get it to work then help will flow freely.
 

oracacle

Senior Member
I agree with bfgstew.
The biggest problem is the fact that we do not know how things are wired, are you using a separate pin for the LED and the solenoid, of both on the same? what are the specifications of the solenoids? How is the system going to interface with user, does it need user input or just run a repeating loop? and bubbles, bubbles of what, do the solenoids control pneumatic or hydraulic valves?
The list of questions could get quite extensive.
 

Buzby

Senior Member
Hi Lee,

Welcome to the Forum !.

I've done a little work on water bubbles, but not quite as impressive as this : https://youtu.be/MhhnBgFOtg0

Mine was like this : https://youtu.be/n7Jtrvmhf-w

I'm working away from home at the moment, but I have my AXE401 with me so I'll spend some hotel time helping you.

First we'll get the LEDs flashing, them move onto the solenoids. ( The AXE401 doesn't have the circuitry to drive solenoids directly, it will need some extra components. )

Have you drawn a circuit diagram yet, even with just paper and pen ?.

Cheers,

Buzby
 

LeeWhitt

New Member
WaterProject1.jpg

Thank you Buzby

The Acrylic Unit on you tube was made at my Dads place, and you emailed me with this forum

So any help would be appreciated I just starting to look at the commands but dont want to make a mistake

Cheers
 

Buzby

Senior Member
Hi Lee,

Yes, the tubes were made by Mick, and I guessed that you were the same Lee !.

Have you started to use PE6 ?. You can write and test most of the code you will need in the simulator, without having to use the 'real' LEDs and AXE401 until later.

So what do you want to start with, building the hardware or writing the software ?

Cheers,

Buzby
 

LeeWhitt

New Member
Buzby

Ive looked at the PE6 so Id like to start with writing the software and then follow with the hardware

Cheers
Lee
 

Buzby

Senior Member
Hi Lee,

Have you written any code yet ?

If so, post it here and we'll have a look at it.

Cheers,

Buzby
 

LeeWhitt

New Member
Hi Buzby,

i have attached the start of my code; only a first attempt so not too sure about if its right or not, just done 3 outputs of the five at the minute, if i continued this would it be correct to light up the LED's as it shows on the simulator and then if i linked this to my breadboard and added the 1 amp transistor to each,would it open the solenoids? Picaxe test.jpg
 

Circuit

Senior Member
Lee, a useful trick for putting your code on the forum; within Programming Editor highlight the code or part of the code that you would like to put in your post. Then right click and you will see the option "Copy for Forum CTRL+SHIFT+C". Click on this, or use the CTRL+SHIFT+C shortcut, and then you can copy your code into your post with the additional code that will keep the format correct. This is much clearer (and easier) than posting screen shots.
 

Buzby

Senior Member
Hi Lee,

To drive solenoids look at the standard circuits 1, 2 & 4 in this manual : http://www.picaxe.com/docs/picaxe_manual3.pdf . Any one of these methods will work for this project.

Your code is fine at the moment, but will get very unwieldy to manage when you come to drive 5 LEDs with different patterns every few milliseconds. ( Your 1 sec and 500mS timings will fill the tubes with air. Air rises very fast through water ! ) You will have hundreds of lines of code, and it will be difficult to manage.

Think of the bubble tubes as as a kind of 'printer' that prints a row of 5 dots, then repeats with a different pattern of dots, and repeats again and again, each time with a different pattern.

The pseudocode for this is :
do
Gosub Get_next_dot_pattern
Gosub Print_dot_pattern
loop

Here is what the Get_Pattern routine might look like.

Code:
[color=Black]GetPattern:[/color]

[color=Blue]inc [/color][color=Black]patPtr[/color]
[color=Blue]if [/color][color=Black]patPtr [/color][color=DarkCyan]> [/color][color=Navy]9 [/color][color=Blue]then
      [/color][color=Black]patPtr [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Blue]endif


LOOKUP [/color][color=Black]patPtr,[/color][color=Blue]([/color][color=Navy]%10001[/color][color=Black],_
               [/color][color=Navy]%01010[/color][color=Black],_
               [/color][color=Navy]%00100[/color][color=Black],_
               [/color][color=Navy]%00000[/color][color=Black],_
               [/color][color=Navy]%00000[/color][color=Black],_
               [/color][color=Navy]%11111[/color][color=Black],_
               [/color][color=Navy]%00000[/color][color=Black],_
               [/color][color=Navy]%00000[/color][color=Black],_
               [/color][color=Navy]%00100[/color][color=Black],_
               [/color][color=Navy]%01010[/color][color=Black],_
               [/color][color=Navy]%10001[/color][color=Black],_
               [/color][color=Navy]%00000[/color][color=Blue])[/color][color=Black]_
               ,[/color][color=Purple]b3[/color]

[color=Blue]return[/color]
This code uses a variable to keep track of which 'row' we are printing, in this case rows are numbered 0 to 9.
It then uses the LOOKUP instruction to select the correct row, and returns the pattern of dots in b3. ( See the LOOKUP command in Manual 2 )

I've used two tricks to make the listing pattern look like the actual bubbles pattern.
The % specifies a number in binary. For example, %00111 is the same number as 7, which will give a bubble in the 3 right hand tubes. ( Page 7, Manual 2 )
The '_' at the end of a line of text continues that line on the next line. ( Page 6, Manual 2 )

This code is all you need to specify any combination of bubbles on any number of rows, ( within the limits of the LOOKUP command. )

Now you need the Print_dot_pattern routine.

The pseudocode for this might be :

Output pattern in B3 to pins b.0 to b.4
Pause to make bubble
Turn off all pins
Pause to make gap
I'll let you write the code for this routine. Check page 18 of Manual 2 for a easy way to drive all the pins of port B with one command.

Keep us posted with your code. Use the right-click menu 'Copy for Forum' in PE6 to make your code easily readable on here.

Cheers,

Buzby
 

LeeWhitt

New Member
Thanks Buzby

Ill need to read this a couple of time to understand

Are you saying cancel the coding I had done on look at getpattern instead?

Lee
 

Buzby

Senior Member
Hi Lee,

Yes, the code you were starting with was good for a few lines, but would get very messy and hard to follow as you added more to it.

The code we are building now will be short, maybe less than 40 lines, but will be able to produce hundreds of different bubble patterns.

The overall structure of the code will be as shown in the first psuedocode :

do
Gosub Get_next_dot_pattern
Gosub Print_dot_pattern
loop
The first gosub routine gets a pattern by using LOOKUP. This means you can add more patterns just by adding more lines like '%10110_', without changing anything in the rest of the code.

The second gosub sends the latest pattern to the LEDs/solenoids, pauses for long enough to make the bubbles, turns the LEDs/solenoids off, then finally pauses to make the gap below the bubbles.

I've shown you the first routine, that does not need any changes yet.

Your mission is to write the second routine. The simulator in PE will be a great help here.

Cheers,

Buzby
 

LeeWhitt

New Member
Binary 1.png

Not sure how i am supposed to program this, but ive tried copying and pasting in and i've got this error message, any ideas?

Cheers,

Lee
 

Buzby

Senior Member
Ooops !.

I forget to tell Lee he would need to define a variable for patPtr, like this :

symbol patPtr = b2 ' Pattern pointer ( See page 7, Manual 2 for all about symbols )

So your code so far should look something like this :

Code:
[color=Blue]symbol [/color][color=Purple]patPtr  [/color][color=DarkCyan]=  [/color][color=Purple]b2          [/color][color=Green]' Pattern pointer[/color]

[color=Blue]do
      gosub [/color][color=Black]GetPattern
      [/color][color=Blue]gosub [/color][color=Black]Print_Dot_Pattern[/color]
[color=Blue]loop[/color]
Cheers,

Buzby
 

LeeWhitt

New Member
Can you explain - gosub Print_Dot_Pattern, As that now says fault on the line, but I can find that in the manual

Lee
 

Buzby

Senior Member
Can you explain - gosub Print_Dot_Pattern, As that now says fault on the line, but I can find that in the manual

Lee
Gosub is the instruction to run the subroutine called 'Print_Dot_Pattern'.

This will give an error if the 'Print_Dot_Pattern' subroutine does not yet exist.

You can create an empty placeholder for your subroutine like this :

Code:
[color=Black]Print_Dot_Pattern:       [/color][color=Green]' The colon defines the start of the subroutine called Print_Dot_Pattern

'
' Put your code here, to send the pattern to the LED/Solenoids.
'[/color]

[color=Blue]return                  [/color][color=Green]' This defines the end of the subroutine[/color]
Cheers,

Buzby
 

LeeWhitt

New Member
Buzby

Sorry I cant seem to get it working in any way, Im not understanding it, I may have to use the first coding I started unless you can tell me here each code goes its getting to complicated

Hope you can help

Lee
 

Buzby

Senior Member
Hi Lee,

Here are the code modules written so far, and put in the correct order. I've added some symbols to make it clearer.

All you need to do now is write the four missing lines !.

Cheers,

Buzby


Code:
[color=Navy]#PICAXE [/color][color=Black]28X2[/color]
[color=Navy]#NO_TABLE
#NO_DATA[/color]

[color=Green]' Symbols
' =======[/color]

[color=Blue]symbol [/color][color=Purple]patPtr           [/color][color=DarkCyan]= [/color][color=Purple]b2        [/color][color=Green]' The number of our current pattern[/color]
[color=Blue]symbol [/color][color=Purple]pattern          [/color][color=DarkCyan]= [/color][color=Purple]b3        [/color][color=Green]' The pattern [/color]
[color=Blue]symbol OnTime           [/color][color=DarkCyan]= [/color][color=Navy]200       [/color][color=Green]' Delay used in Pause for On time  [/color]
[color=Blue]symbol OffTime          [/color][color=DarkCyan]= [/color][color=Navy]200       [/color][color=Green]' Delay used in Pause or Off time

' Code starts here
' ================
' ================[/color]

[color=Purple]dirsB [/color][color=DarkCyan]= [/color][color=Navy]%11111111             [/color][color=Green]' Set port B to all outputs[/color]


[color=Blue]do                            [/color][color=Green]' Loop starts here
      [/color][color=Blue]gosub [/color][color=Black]GetPattern              [/color][color=Green]' Call the routine to get the next pattern
      [/color][color=Blue]gosub [/color][color=Black]Print_Dot_Pattern       [/color][color=Green]' Call the routine to send pattern to LEDs[/color]
[color=Blue]loop                          [/color][color=Green]' End of loop


' Subroutines
' ===========[/color]

[color=Black]GetPattern: [/color][color=Green]' This routine get the pattern

      [/color][color=Blue]inc [/color][color=Purple]patPtr
      [/color][color=Blue]if [/color][color=Purple]patPtr [/color][color=DarkCyan]> [/color][color=Navy]37 [/color][color=Blue]then
            [/color][color=Purple]patPtr [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]endif

      LOOKUP [/color][color=Purple]patPtr[/color][color=Black],[/color][color=Blue]([/color][color=Navy]%10001[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%11111[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%10001[/color][color=Black],_
                     [/color][color=Navy]%00000[/color][color=Black],_
                     [/color][color=Navy]%00000[/color][color=Black],_
                     [/color][color=Navy]%11111[/color][color=Black],_
                     [/color][color=Navy]%00000[/color][color=Black],_
                     [/color][color=Navy]%00001[/color][color=Black],_
                     [/color][color=Navy]%00010[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%01000[/color][color=Black],_
                     [/color][color=Navy]%10000[/color][color=Black],_
                     [/color][color=Navy]%01000[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%00010[/color][color=Black],_
                     [/color][color=Navy]%00001[/color][color=Black],_
                     [/color][color=Navy]%00000[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%10001[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%00100[/color][color=Black],_
                     [/color][color=Navy]%00000[/color][color=Black],_
                     [/color][color=Navy]%10101[/color][color=Black],_
                     [/color][color=Navy]%01010[/color][color=Black],_
                     [/color][color=Navy]%00000[/color][color=Blue])[/color][color=Black]_
                     ,[/color][color=Purple]pattern[/color]

[color=Blue]return[/color]

' =====================================================================

' Subroutine to operate the LEDS/Solenoids   

[color=Black]Print_Dot_Pattern:    
 
 [/color][color=Green]'
 ' Put code to drive LEDS here
 '
 ' It is just 4 lines if you use the instruction on page 18 of manual 2
 '
 '[/color]
[color=Blue]return                   [/color]
Here is the psuedocode for the 4 lines you need to write ...

Output pattern in B3 to pins on port B
Pause to make bubble
Turn off all pins
Pause to make gap
 
Last edited:

LeeWhitt

New Member
Thanks Buzby

That looks better, but the code to drive Leds, I cant find on Page18 of manual 2, is that right?

Lee
 

Buzby

Senior Member
Hi Lee,

The first instruction you need will set the pins of port B to the pattern held in B3. Have a look for an instruction on page 18 that sets the bits of a port.

The second instruction you need will wait a short while to let the air into the tube. You already know this instruction.

The third instruction is the same as the first, but this time it turns all the pins on port B off.

The fourth instruction is just another wait, to make a gap below the bubble.

Cheers,

Buzby
 

LeeWhitt

New Member
Code:
[color=Black]Print_Dot_Pattern:    
 
 main: [/color][color=Blue]let [/color][color=Purple]b3[/color][color=DarkCyan]=[/color][color=Purple]pinsB
 [/color][color=Blue]PAUSE [/color][color=Navy]2000
 [/color][color=Blue]LOW [/color][color=Purple]PINSB
 [/color][color=Blue]PAUSE [/color][color=Navy]2000
 [/color]
[color=Blue]return          [/color]
Can you please check if this is right? it doesnt seem to light up on the simulation bar the first cycle.
 

Buzby

Senior Member
Hi Lee,

You are nearly there !.

1st, You dont need the word main:

2nd, The Let you have is copying the bits wrong way round, it should be pinsB=B3

3rd, On the third line, the LOW instruction is for a single bit, you need to use pinsB again.

Make these changes and post the code.

Cheers,

Buzby
 

lbenson

Senior Member
This is a peculiar thing syntactically. The HIGH and LOW commands take a pin number (e.g., b.0), and one would think that pinsB would not be valid, but in fact, if you print pinsB ("sertxd(#pinsb,cr,lf"), you print "0". 0 is actually the pin number for b.0, so if you were to say, for instance, "high pinsb", b.0 will go high. (pinsc also has a numeric value of 0.) I would think there should be a syntax error for this kind of usage.

This is not what you want. pinsB refers to all the pins in the b port (as inputs); outpinsB refers to the pins as outputs.

You must first designate which pins in port B are outputs (with the dirsB command), and then set the bits. For instance, the following commands for a picaxe 14M2 will set all 6 port B pins as outputs, and make them high. You can try this in the simulator.

#picaxe 14m2
dirsb = $ff ' all pins are outputs
outpinsB = %00111111 ' all pins are high

You can them make some high and some low

outpinsB = %00010101 ' even numbered pins are high (0,2,4)
 
Last edited:

Technical

Technical Support
Staff member
print pinsB ("sertxd(#pinsb,cr,lf"), you print "0". 0 is actually the pin number for b.0, so if you were to say, for instance, "high pinsb", b.0 will go high. (pinsc also has a numeric value of 0.) I would think there should be a syntax error for this kind of usage.
sertxd(#pinsb,cr,lf) is only equal to 0 when all the inputs on that port are 0. pinsB can actually take any value between 0 and 255 because it is a byte variable.

B.0 is a constant of value 0.

So sertxd(#pinsb,cr,lf) is valid, to see what the input values are as a whole and pinsB is also useful to use with 'variable = pinsB' type commands.

To switch outputs on and off singularly use high/low followed by a constant like B.0
To switch all 8 outputs on/off use 'outpinsB = b3' or 'outpinsB = 0' etc
To read all the port inputs into a variable use 'b3 = pinsB'
To read all the port outputs into a variable use 'b3 = outpinsB'
 

Buzby

Senior Member
I thought I'd made a syntax error, as pinsB is not the same as outpinsB.

But this code works :

Code:
[color=Black]Print_Dot_Pattern:        
 
 [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Purple]pattern
 [/color][color=Blue]pause OnTime
 [/color][color=Purple]pinsB [/color][color=DarkCyan]= [/color][color=Navy]0
 [/color][color=Blue]pause OffTime


return                  [/color]
So pinsB seems to work the same as outpinsB.

How are you getting on ?

Buzby
 

Technical

Technical Support
Staff member
So pinsB seems to work the same as outpinsB.
They are not the same within the silicon, the first maps to the port reading register and the second to the output latch register.
Although generally they often give the same values, they don't always, and this can lead to unexpected behaviour if you use the wrong one.
Hence reads should always be made from the port register (pinsB) and writes to the output latch register (outpinsB).
 

Buzby

Senior Member
Hi Technical,

I was fairly sure I'd made a mistake, but as pinsB = $xx works on the silicon, I didn't check any further.

What it does in the simulator I don't know, I had the 40X2 and LEDs connected, so it was a quick 'real life' test.

( It's been a long time since I programmed PIC in assembler, so the map may be different now, but didn't both Read and Write to a port use the same address, with the action being determined by the state of the R/W line ?. However, from now on I shall ensure that 'outpins' is on the left and 'pins' is on the right, even if the syntax checker lets me do otherwise. )

Cheers,

Buzby
 

Buzby

Senior Member
Hi Lee,

Now you've got the simulation working, it's time to add the transistors to drive the LEDs and solenoids.

Take a look at Standard Circuit 4 in Manual 3.

This will drive both a solenoid and an LED at the same time. Just put the LED in parallel with the solenoid, with a series resistor of about 2.7K. ( Assuming a 12V supply. )

You will need a 12V supply to drive the solenoids, but don't get it mixed up with the 5V for the PICAXE. That will destroy it.

Cheers,

Buzby
 

Buzby

Senior Member
Hi Lee,

How are you getting on ?

Have you had any success driving LEDs and / or solenoids ?

Cheers,

Buzby
 

Buzby

Senior Member
Re: Water Bubble Display

Quote Originally Posted by Buzby
Hi Lee,

Let's keep this in the forum. That way everyone can help and learn.

See you there.

Jeff
Hi Jeff, finally trying to put the program onto the Picaxe circuit 28x2 and the picaxe program comes up with Program Failed "Error: Hardware not found on COM1!"

Any ideas?

Cheers,

Lee.
Hi Lee,

Good to hear from you again !.

'Hardware not found', that can be caused by a few different things.

What hardware are you using, is it the AXE-401 28X2 Shield Base ?

http://www.picaxe.com/Hardware/Project-Boards/PICAXE-28X2-Shield-Base/

You are best asking for answers here in the forum, as you will get help 24/7. I'm working away on a petrochem site and can't get online often.

Cheers,

Buzby
 

westaust55

Moderator
Hardware not found at COM1 can suggest that the Programming Editor was stared without the AXE027 can installed first.

Best is to have the AXE027 cable installed prior to starting the PE.
Otherwise you will need to go into options and check/select the correct serial COM port before a program download.
 

LeeWhitt

New Member
Hi Buzby! all problems are solved and i've got my presentation infront of a panel on monday (very nervous haha) i have some final questions on things im unsure on; and i dont want to be asked about them and have no answer so i thought i'd run it by you

1.) which pins have been used and why? i know that some are analogue and some are digital and 2 are earth i believe? but which ones were used and how did you know those were the correct ones? if you know the numbers of the pins that'd be great, i have the software on my laptop at home but wont be able to get to it for a couple days so i cant see the numbers.

2.) is it definitely solenoid valves that the circuit is wired to which is what pushes the air into the water chambers? i would of thought it was a pump of some kind?

3.) is there a type of oil or something that could of been put in the water that would of made the bubbles flow quicker (less resistance) i remember reading about this and it seemed rather interesting, it could of just been a special kind of water.

thats all i can think of for now! any help is appreciated

after the project is all done and dusted i'll be sure to do abit of research into how to programme more indepth and do some reading on the forum and hopefully contribute abit!

i'll be sure to let you know how it goes or ask if if i can think of anything else i might need help on

Cheers again,

Lee :)
 
Last edited:

Buzby

Senior Member
Hi Lee,

Good to hear from you again.

Hi Buzby! all problems are solved and i've got my presentation infront of a panel on monday
Glad to hear that, good luck !

Can you post a picture ?.

1.) which pins have been used and why? i know that some are analogue and some are digital and 2 are earth i believe?
The pins I used were five consecutive digital outputs on PortB. ( B.0 TO B.4 ). These pins, and many others, can be used as digital inputs/outputs or analogue inputs, as well as other uses such as PWM or TOUCH etc. See the pinout diagram on page 11 of Manual 1.

Yes, the 28X2 does have two 0v ( earth ) pins. I always connect both to the same 0v supply, but if you are using the AXE401 that's taken care of by the PCB.

2.) is it definitely solenoid valves that the circuit is wired to which is what pushes the air into the water chambers? i would of thought it was a pump of some kind?
The bubble tube I helped build used solenoid valves to allow air into the tube. The air came from a fish tank pump.
More expensive setups use peristaltic pumps instead of valves, which gives smoother and more precise control of the bubbles.

3.) is there a type of oil or something that could of been put in the water that would of made the bubbles flow quicker (less resistance) i remember reading about this and it seemed rather interesting, it could of just been a special kind of water.
Bubbles rise very fast in water, and tend to get ragged as they accelerate up. Patterns look better if the bubbles rise slower !.
The slow, smooth effect is made by using oil instead of water. Something like clear baby oil is good.

after the project is all done and dusted i'll be sure to do abit of research into how to programme more indepth and do some reading on the forum and hopefully contribute abit!
That's what we like to hear, and when the project is complete why not post it in the Finished Projects section of the forum - you might win a prize !.

Cheers,

Buzby
 

69-cat

Member
I have been following this project to learn the different ways of controlling outputs but have a question. When using dirsB = %11111111 ' Set port B to all outputs is there a way of controlling a greater number than 8 outputs using this process?
Dave
 

hippy

Technical Support
Staff member
When using dirsB = %11111111 ' Set port B to all outputs is there a way of controlling a greater number than 8 outputs using this process?
Not directly. Port B only has eight port pins B.0 to B.7. You can also use dirsC= to set Port C's C.0 to C.7 pins, but they have to be separate commands, there's not a single command which does all.
 

69-cat

Member
That is what I thought but it does not hurt to ask!
Thanks Again Hippy

Dave

Not directly. Port B only has eight port pins B.0 to B.7. You can also use dirsC= to set Port C's C.0 to C.7 pins, but they have to be separate commands, there's not a single command which does all.
 
Top