School Project

PandaMan96

New Member
Hello. I'm 15 years old and I'm doing GCSE Control Systems at school. I'm using a picaxe 20M2 chip to control my project and I have everything sorted except the LCD display. I wan't to put an 8x2 LCD display in because my project involves the user inputting time into a timer. The problem is, I have no idea how to use the PICaxe chip for an LCD display...:confused:
This is what is in place already for the timer and function for when the time expires. Can someone help?
Code:
let b0 = 0
main:
	if pin1=1 then
		let b0 = b0+1
		endif
		pause 100
	if pin2=1 then
		let b0 = b0-1
		endif
		pause 100
	if pin3=1 then
		let b0 = b0+10
		endif
		pause 100
	if pin4=1 then
		let b0 = b0-10
		endif
		pause 100
	if pin0=0 then
		pause 100
		goto main
	elseif pin0=1 then
		goto function
		endif

function:
		if b0 = 0 then main
		for b1 = 1 to b0
		wait 1
		next
		high B.0
		pause 700
		low B.0
		high B.1
		pause 700
		low B.1
		let b0 = 0 
		goto main
PandaMan
 

jtcurneal

Senior Member
A serial interface is definitely the easiest way to hook a display unit to a Picaxe and OLED displays are much easier to read in all types of situations.

If cost is a big concern, you could elimate the cost of a serial LCD/OLED board and use 6 pins of your 20M2 and drive the LCD directly.
Hippy has the documentation available for driving a LCD directly..

I am sure that a number of us here can help you with whichever route you decide to use.

Joel
 

nick12ab

Senior Member
  • A thread that might help for 8-bit mode: LCD (Winstar WH1602A) directions (Newbie) (see a post near the end for pin connections to 40X2)
  • For 4-bit mode see: LCD Interfacing
  • Many OLED Displays allow SPI interfacing which uses two I/O if you don't need to read data back.
  • Read an OLED Datasheet here which will give you lots of help.
  • An AXE133 Serial OLED Display is a good option
  • If you need lowest possible power consumption, you'll want a non-backlit LCD and no extra intermediate controller.
 

PandaMan96

New Member
Thanks for all the quick replies! Very useful :)
I like the look of the OLED displays. Money isn't really a problem as long as I spend no more than £15 on it. In fact I was planning on using a backlit LCD display, but as nick12ab said I want a lower power consumption.

I think I need the programming explained to me though, because I've just recently started learning and don't really know where to start to be honest:eek:. I would like to go the the OLED display that eclectic posted but how do I use it? I have potentially 11 output pins free.

edit: don't get me wrong - I don't want it done for me. I just need something to start me off. :p
 
Last edited:

nick12ab

Senior Member
but as nick12ab said that I want a lower power consumption.
You don't need lower power consumption but if you want a backlight choose an OLED if you need low power.

Starting you off... for 8-bit mode, see initialization in post 9.

You must also define rs and enable as pin constants. pinsB is used as the data bus.
 
Last edited:

nick12ab

Senior Member
Unparsed code
Code:
	low rs
	pinsB = %00000110 : pulsout enable,400
	pinsB = %00001100 : pulsout enable,400
	pinsB = %00111000 : pulsout enable,400
	pinsB = %00000001 : pulsout enable,400
 

nick12ab

Senior Member
I'm confused:eek:... could you explain what that code means/does?
It's for initializing the OLED or LCD display - the code should be compatible with both. Because the same type of controller is re-used on many different formats of display, you need to tell it the resolution, lines and data bus width, then your 'preferences' - i.e. do you want a cursor and do you want the screen to actually be on? In my example, the cursor is off and the screen is on.
 

Technical

Technical Support
Staff member
It's getting a bit confusing here as Nick is talking about connecting the screen direct, rather than via the serial OLED module, which is what 99% of students would use in a school project like this (as already suggested by ec in post 2)

We suggest you use the 'AXE133 Serial OLED module' and control it via 'serout' commands. You then only need to have one PICAXE output pin connected to the serial OLED module input and do not need to worry about the let pinsB etc..
 

PandaMan96

New Member
We suggest you use the 'AXE133 Serial OLED module' and control it via 'serout' commands. You then only need to have one PICAXE output pin connected to the serial OLED module input and do not need to worry about the let pinsB etc..
That seems like it would be best for me (lol sorry Nick). Where can I find out how to use the serout commands? I've seen it's in the basic commands manual. What is baudmode?

edit: Anyway, I'm off to bed now, so I'll check the thread again in the morrow. Thanks for your help and patience so far. :)

PandaMan
 
Last edited:

Technical

Technical Support
Staff member
Baudmode is speed of communication, in your case you just need to use 'N2400' and then forget about it! Have a look in both the AXE133 and older AXE033 datahsseets for some examples on how to use the screens with serout.
 

jtcurneal

Senior Member
With most if not almost all of the character LCD/OLED display, you can use them in either 8-bit or 4-bit mode.
8-bit mode is somewhat faster and uses simpler code ( one write for each character )
4-bit mode requires more code ( 2 separate 4-bit writes for each char. ) but uses 4 fewer pins on the Picaxe.

It may come down to what materials you have and can get and how much code that you want to write.
I have mostly used 4-bit mode and have found that the slower speed is not a problem in most of my projects.

Joel
 

nick12ab

Senior Member
lol sorry Nick
I don't mind. It wouldn't be nice of me to persistently insist that you do "THIS" and NOTHING ELSE! it is however my recommended method but that is a personal preference and others will recommend others instead as no one has to have the same personal preference as someone else.

Baudmode is speed of communication, in your case you just need to use 'N2400' and then forget about it! Have a look in both the AXE133 and older AXE033 datahsseets for some examples on how to use the screens with serout.
To throw in some extra complication, the open-source AXE133 could be code modified to use a faster baud speed.

Also there's the FRM010 which has options for 2400 and 9600. The FRM010 is a single-chip option which mounts onto your project PCB rather than its own separate backpack and you can also do the same with an 18M2 and the AXE133 code. In the case of my GCSE project, it would have been much thinner if I was aware of the FRM010's existence (direct interfacing seemed like a scary concept to me then).
 

PandaMan96

New Member
You know what? I think I'm sorted. Thanks for the help! :) You've all been very useful.
I am going to go with the AXE133 OLED display because it suits my needs perfectly.

edit: No wait, I just though of one thing. Can you make the display display a variable? Like this?
Code:
init:
	pause 500					;for OLED display to initialise
	let b0 = 0				;makes surere the counter variable is at 0
main:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (b0)
		endif
		pause 100
	if pin2=1 then
		let b0 = b0-1
		serout B.2, N2400, (b0)
		endif
		pause 100
	if pin3=1 then
		let b0 = b0+10
		serout B.2, N2400, (b0)
		endif
		pause 100
	if pin4=1 then
		let b0 = b0-10
		serout B.2, N2400, (b0)
		endif
		pause 100
	if pin0=0 then
		pause 100
		goto main
	elseif pin0=1 then
		goto function
		endif

function:
		if b0 = 0 then main
		for b1 = 1 to b0
		wait 1
		next
		high B.0					;motor activates in one direction
		pause 700
		low B.0					;de-activate motor
		wait 1					;wait for the chain reaction to start					
		high B.1					;activate motor in opposite direction
		pause 700
		low B.1					;deactivates motor
		let b0 = 0				;resets b0
		goto main
PandaMan :)
 
Last edited:

westaust55

Moderator
You are on the right track.
But you will likely want to add the hash (#) symbol in front of the variable name.

B0 alone will in effect display the xth character in the display font set
So if b0 = 48 you will see "0"

But if you want to see "48" then use #b0 and then the SEROUT command sends separately a "4" and a "8"
 

PandaMan96

New Member
Ok thanks. I wasn't far off... I'm surprised with myself. I've mainly been learning from the command manuals :p
Well... That makes my code complete. Thanks for all the help everyone! :)
Code:
init:
	pause 500					;for OLED display to initialise
	let b0 = 0				;makes surere the counter variable is at 0
main:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin2=1 then
		let b0 = b0-1
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin3=1 then
		let b0 = b0+10
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin4=1 then
		let b0 = b0-10
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin0=0 then
		pause 100
		goto main
	elseif pin0=1 then
		goto function
		endif

function:
		if b0 = 0 then main
		for b1 = 1 to b0
		wait 1
		next
		serout B.3, N2400, (254,1)	;Clears the display
		pause 30
		serout B.3, N2400, ("Time's Up")
		high B.0					;motor activates in one direction
		pause 700
		low B.0					;de-activate motor
		wait 1					;wait for the chain reaction to start					
		high B.1					;activate motor in opposite direction
		pause 700
		low B.1					;deactivates motor
		let b0 = 0				;resets b0
		goto main
But could someone check this to make sure nothing's wrong? :D
 

Haku

Senior Member
Quick note on serial controlled vs direct (8bit or 4bit) controlled LCD character display screens:

Serial controlled - dead easy to use & reccomended for first-timers & when you don't want hassle, but usually more expensive due to the need of a serial controller chip attached to the screen, also the screen update speed is limited by the incoming baud rate of the serial controller chip, usually they run at 2400,4800 or 9600, though some can run at 38400,57600,115200 baud for very quick screen updating.

Direct 8bit or 4bit controlled - uses more pins of the Picaxe, requires more programming even when just displaying a plain text message, can get tricky to debug when things don't work first time, but the upside is on Picaxes running at fast speeds (32mhz,40mhz,64mhz) the screen update is extremely fast even running at 4bit.

I'm sure someone'll be along shortly to correct/add to the above information :)
 

PandaMan96

New Member
@Pandaman

You can get some LCD ideas using the
Simulator.
PE. > View > Options > Simulation

e
That helps. A lot. :)
I've made some minor adjustments to the code. I made the screen clear before adding another number because on the simulation it added one after the other like "1011121314" and so on.

Code:
init:
	pause 500					;for OLED display to initialise
	let b0 = 0				;makes surere the counter variable is at 0
main:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin2=1 then
		let b0 = b0-1
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin3=1 then
		let b0 = b0+10
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin4=1 then
		let b0 = b0-10
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin0=0 then
		pause 100
		goto main
	elseif pin0=1 then
		goto function
		endif

function:
		if b0 = 0 then main
		for b1 = 1 to b0
		wait 1
		next
		serout B.2, N2400, (254,1)	;Clears the display
		pause 30
		serout B.2, N2400, ("Time's Up")
		high B.0					;motor activates in one direction
		pause 700
		low B.0					;de-activate motor
		wait 1					;wait for the chain reaction to start					
		high B.1					;activate motor in opposite direction
		pause 700
		low B.1					;deactivates motor
		let b0 = 0				;resets b0
		serout B.2, N2400, (254,1)
		pause 30 				
		goto main
 
Last edited:

PandaMan96

New Member
Here is my finished code. :D

Code:
init:
	pause 500					;for OLED display to initialise
	let b0 = 0				;makes sure the counter variable is at 0
	serout B.2, N2400, (254,1)
	serout B.2, N2400, (#b0)
main:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin2=1 then
		let b0 = b0-1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin3=1 then
		let b0 = b0+10
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin4=1 then
		let b0 = b0-10
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin0=0 then
		pause 100
		goto main
	elseif pin0=1 then
		high B.3
		pause 50
		low B.3
		goto function
		endif
function:
		if b0 = 0 then main
		for b1 = 1 to b0
		wait 3
		let b0 = b0-1
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0)
		next
		serout B.2, N2400, (254,1)	;Clears the display
		pause 30
		serout B.2, N2400, ("Time's Up")
		high B.0					;motor activates in one direction
		pause 700
		low B.0					;de-activate motor
		wait 1					;wait for the chain reaction to start					
		high B.1					;activate motor in opposite direction
		pause 700
		low B.1					;deactivates motor
		let b0 = 0				;resets b0
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0) 				
		goto main
 

fritz42_male

Senior Member
Now I'm getting seriously worried. A 15 year old male who is intelligent, has good spelling & grammar, is courteous and follows posting etiquette! What is the world coming to!

Please don't think I'm being patronising but it really is refreshing to think that not all teenagers fit the stereotype shown so often on TV

I know they are out there but sometimes it just doesn't seem like it.
 

westaust55

Moderator
Concur with fritz42_male.

@Pandaman96
well done also with your program presentation.

While these may be personal preferences and in terms of priority/precendence, if I may make some suggestions:

1. Program structures:
Try to have the initial and closing line for a loop (DO...LOOP) and other sructures (eg IF...THEN) tabulated in by the same number of spaces.
Also consider a space after the "structure" portion so the extent of the code portion is very clear.
Thus
Code:
main:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
		endif
		pause 100
	if pin2=1 then
		let b0 = b0-1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
		endif
		pause 100
Becomes:
Code:
main:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
	endif
	pause 100

	if pin2=1 then
		let b0 = b0-1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
	endif
	pause 100
2. Use a subroutine for same code executed in many places
For the program lines
Code:
	serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
You could put this into a subroutine and then use a GOSUB statement to call that code section
then
Code:
	if pin1=1 then
		let b0 = b0+1
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
	endif
	pause 100
becomes:
Code:
	if pin1=1 then
		let b0 = b0+1
                GOSUB Display-flash
	endif
	pause 100
plus a subroutine:
Code:
Display-flash:
		serout B.2, N2400, (254,1)
		pause 30
		high B.3
		pause 50
		low B.3
		serout B.2, N2400, (#b0)
               RETURN
Now there are time when the use of subroutines may not be idea, such as when you need the absolute max speed for same time critical task
But at other times when the program become big, the use of subroutines can reduce the program space occupied.


3. Capitals and lower case:
The programming editor is not case sensitive and this is certainly my personal preference - my philosophy is:
Use capitals for BASIC program keywords (eg FOR....TO...NEXT, DO...LOOP, IF...THEN.....ELSE....ENDIF)
Use labels with a capital for the first letter and lowercase generally thereafter
for variable names all in lower case

Add some remarks at the top of the program listing to describe the purpose of the program, what it does, which PICAXE chip it is targeted at
Maybe even add the date when written.

These are all guidelines and if started early are easier to maintain without too much thought.
Do not get me wrong, there is nothing wrong with your program, just putting ideas forward towards much bigger programs in future.
 

PandaMan96

New Member
Now I'm getting seriously worried. A 15 year old male who is intelligent, has good spelling & grammar, is courteous and follows posting etiquette! What is the world coming to!
:) I don't think you are being patronising at all. Thanks for the compliment; it irritates me when people sometimes assume I fit the sterotype. Generally, if you have a 15 year old boy who knows a bit about programming and took GCSE systems and control, they will not be a chav.

@westaust55, thanks for agreeing with fritz' compliment :)

As for your advice, that does make a lot of sense to me. I haven't made any personal preferences yet because this is my first code using the BASIC language. I have used other languages (not for PIC[axe] programming), like Flash Actionscript and a variant of C called liteC.
I agree with your advice and I will modify my code accordingly.

EDIT: I've just tried the sub-routines and I get a syntax error in the "GOSUB Display-flash" line...?
Code:
Init:
	pause 500					
	let b0 = 0				
	serout B.2, N2400, (254,1)
	serout B.2, N2400, (#b0)
Main:
	IF pin1=1 then
		let b0 = b0+1
		GOSUB Display-flash
	ENDIF
		pause 100
	IF pin2=1 then
		let b0 = b0-1
		GOSUB Display-flash
	ENDIF
		pause 100
	IF pin3=1 then
		let b0 = b0+10
		GOSUB Display-flash
	ENDIF
		pause 100
	IF pin4=1 then
		let b0 = b0-10
		GOSUB Display-flash
	ENDIF
		pause 100
	IF pin0=0 then
		pause 100
		goto Main
	ELSEIF pin0=1 then
		high B.3
		pause 50
		low B.3
		goto Function
	ENDIF
Display-flash:
			serout B.2, N2400, (254,1)
			pause 30
			high B.3
			pause 50
			low B.3
			serout B.2, N2400, (#b0)
			RETURN
Function:
		IF b0 = 0 then Main
		FOR b1 = 1 to b0
			wait 3
			let b0 = b0-1
			serout B.2, N2400, (254,1)
			pause 30
			serout B.2, N2400, (#b0)
		NEXT
		serout B.2, N2400, (254,1)	
		pause 30
		serout B.2, N2400, ("Time's Up")
		high B.0					
		pause 700
		low B.0					
		wait 1									
		high B.1					
		low B.1					
		let b0 = 0				
		serout B.2, N2400, (254,1)
		pause 30
		serout B.2, N2400, (#b0) 				
		goto Main
Thanks :)

PandaMan
 
Last edited:

nick12ab

Senior Member
Please don't think I'm being patronising but it really is refreshing to think that not all teenagers fit the stereotype shown so often on TV

I know they are out there but sometimes it just doesn't seem like it.
People interested in programming and working with electronic components will never fit this stereotype - people who do fit that stereotype will be stealing electronics to re-sell, not buying electronics to build with.
 

fritz42_male

Senior Member
People interested in programming and working with electronic components will never fit this stereotype - people who do fit that stereotype will be stealing electronics to re-sell, not buying electronics to build with.
Agreed and PandaMan reminds me of myself at his age. Although being at a boys only school I was socially inept with girls until much later in life.

I wish I had had access to Picaxe type stuff at that point in my lifr but I had to wait another 3 years before even getting access to 6502 processors.

PandaMan I try not to pay too much attention to stereotypes but I still get caught now and again. lol.
 
Last edited:

westaust55

Moderator
My error there :mad:
- versus _ (forgot the shift key then cut and paste).

Labels nomenclature/format is described in PICAXE manual 2 page 5:

Labels can be any word (that is not already a reserved keyword) and
may contain digits and the underscore character. Labels must start with a letter or
underscore (not digit), and are defined with a colon ( : ) at the marker position.
The colon is not required within the actual commands.
 
Top