New to PicAxe

Robbier3

New Member
Hi Everyone,

I hope that you are all well.

I have just bought myself a new picaxe kit and was wondering if anyone could help me get it to do a simple task, I have read the manuals and tried but am not winning here, any help would be greatly appreciated.

What I am trying to do is a program that uses two push buttons to navigate through an Axe133 OLED display (18M2 chip built onto the OLED and a 20X2 external chip for control), for instance if I do the following:

As power is turned on you get a screen that says "hello" on the top and "push button 1" on the bottom of the display
- if you Push switch 1 (located on b.1 on the 20X2 chip) - go to a page that says "test" on the top and "go back" on the bottom right corner of the display
- if you push switch 2 (located on b.6 on the 20X2 chip) - sends you to the first page ("hello") when you were on the second page ("test")

This is how I have wired up the 20X2 chip

20X2 2 Switch Circuit.JPG

I have wired up the OLED and 20X2 chip exactly as specified and am communicating.

For the Axe133 18M2 chip I downloaded this code from the website:

Code:
; AXE133 Serial LCD/OLED using PICAXE-18M2
; Emulates basic serial operation of the popular AXE033 module
; CPS, May 2011
; v2 18/01/2012

#picaxe 18M2

; ********************************************
; Note you must uncomment just one of these two options
; depending on whether you have an LCD or OLED module
;#define use_OLED
#define use_LCD
; ********************************************


; Supported Commands
; 0-7, 8-15	CGRAM characters
; 16-252	normal ASCII characters, according to selected character map table
; 253, X	display 16 character pre-saved message from EEPROM memory, X can be 0-15
; 254, X	LCD command, X can be 0 to 255 
; 255, X	control outputs C.2, C.1, C.0 (via lower 3 bits of X)
;		So, if using a backlit LCD with the active low transistor driver
;		on output C.2, then 255,%000 switches backlight on and 255,%100 switches off


#define use_welcome	; display the welcome message upon power up
symbol line_length = 16	; change to 20 for displays with 20 character lines

symbol baud = N2400_16	; Serial baud rate 2400,N,8,1. Note main program runs at 16MHz

symbol spare0 	= C.0 ; spare output 0
symbol spare1 	= C.1 ; spare output 1
symbol spare2 	= C.2 ; spare output 2 (or optional backlight)
symbol backlight 	= C.2 ; optional backlight control for backlit LCDs, active low
symbol RX		= C.5	; serial receive pin
symbol enable 	= C.6	; LCD enable
symbol rs 		= C.7	; LCD RS 


; LCD data pins are on B.0 to B.7

; Store the 16 character user defined messages in EEPROM data memory
; First two messages are optionally used as welcome message

; If using a display with 20 characters you will need to edit 
; the start addresses to be multiples of 20 (currently at 16) 
; and add 4 characters to each message.
; Please remember 4 line displays always use the strange 1-3-2-4 layout.

#ifdef use_OLED		
EEPROM $00, ("  Serial OLED   ") 	; store msg in the EEPROM memory
#else
EEPROM $00, ("   Serial LCD   ") 	; store msg in the EEPROM memory
#endif


EEPROM $10, (" [url]www.picaxe.com[/url] ") 	; store msg in the EEPROM memory

EEPROM $20, ("This is msg 2   ") 	; store msg in the EEPROM memory
EEPROM $30, ("This is msg 3   ") 	; store msg in the EEPROM memory
EEPROM $40, ("This is msg 4   ") 	; store msg in the EEPROM memory
EEPROM $50, ("This is msg 5   ") 	; store msg in the EEPROM memory
EEPROM $60, ("This is msg 6   ") 	; store msg in the EEPROM memory
EEPROM $70, ("This is msg 7   ") 	; store msg in the EEPROM memory
EEPROM $80, ("This is msg 8   ") 	; store msg in the EEPROM memory
EEPROM $90, ("This is msg 9   ") 	; store msg in the EEPROM memory
EEPROM $A0, ("This is msg 10  ") 	; store msg in the EEPROM memory
EEPROM $B0, ("This is msg 11  ") 	; store msg in the EEPROM memory
EEPROM $C0, ("This is msg 12  ") 	; store msg in the EEPROM memory
EEPROM $D0, ("This is msg 13  ") 	; store msg in the EEPROM memory
EEPROM $E0, ("This is msg 14  ") 	; store msg in the EEPROM memory
EEPROM $F0, ("This is msg 15  ") 	; store msg in the EEPROM memory

;initialise LCD
init:
	gosub LCD_init 		; initialise LCD

; display welcome message if desired
#ifdef use_welcome	
	let b1 = 0			; message 0 on top line
	gosub msg			; do it

	low rs			; command mode
	let pinsB = 192		; move to line 2, instruction 192
	pulsout enable,1  	; pulse the enable pin to send data.
	high rs			; character mode again
	
	let b1 = 1			; message 1 on bottom line
	gosub msg			; do it
#endif		
		
; main program loop, runs at 16MHz

main:

	serin RX,baud,b1			; wait for the next byte

	; NB keep character mode test as first item in this list to optimise speed
	if b1 < 253 then
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		goto main			; quickly loop back to top
	else if b1 = 254 then
		low rs 	     		; change to command mode for next character
		serin RX,baud,b1		; wait for the command byte
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
		high rs			; back to character mode
		goto main			; quickly loop back to top
	else if b1 = 253 then
		serin RX,baud,b1		; wait for the next byte
		gosub msg			; do the 16 character message
		goto main			; back to top
	else ; must be 255
		serin RX,baud,b1		; wait for the next byte
		let pinsC = b1 & %00000111 | %10000000
						; output the data on C.0 to C.1, keep RS high
		goto main			; back to top
	end if


; power on LCD initialisation sub routine
LCD_init:
	let dirsC = %11000111	; PortC 0,1,2,6,7 all outputs
	let dirsB = %11111111	; PortB all outputs
	

	
#ifdef use_OLED
	; Winstar OLED Module Initialisation
	; according to WS0010 datasheet (8 bit mode)

	pause 500 			; Power stabilistation = 500ms

	; Function set - select only one of these 4 character table modes
	;let pinsB = %00111000 	; 8 bit, 2 line, 5x8 , English_Japanese table
	let pinsB = %00111001 	; 8 bit, 2 line, 5x8 , Western_European table1
	;let pinsB = %00111010 	; 8 bit, 2 line, 5x8 , English_Russian  table
	;let pinsB = %00111011 	; 8 bit, 2 line, 5x8 , Western_European table2
	
	pulsout enable,1  	; 
		
	let pinsB = %00001100	; Display on, no cursor, no blink
	pulsout enable,1 	

	let pinsB = %00000001 	; Display Clear
	pulsout enable,1
	pause 7			; Allow 6.2ms to clear display

	setfreq m16			; now change to 16Mhz

	let pinsB = %00000010 	; Return Home
	pulsout enable,1

	let pinsB = %00000110 	; Entry Mode, ID=1, SH=0
	pulsout enable, 1


#else	
	; Standard LCD Module Initialisation
	pause 15 			; Wait 15ms for LCD to reset.

	let pinsB = %00110000 	; 8 bit, 2 line
	pulsout enable,1  	; Send data by pulsing enable
	pause 5 			; Wait 5 ms
	pulsout enable,1 	 	; Send data 48 again
	pulsout enable,1  	; Send data 48 again
	
	setfreq m16			; now change to 16Mhz

	let pinsB = %00111000 	; LCD  - 8 bit, 2 line, 5x8  
	pulsout enable,1
			
	let pinsB = %00000001	; Clear Display
	pulsout enable,1 	
	pause 8			; 8 = 2ms at 16MHz
	
	let pinsB = %00000010 	; return home
	pulsout enable,1

	let pinsB = %00000110	; Entry mode
	pulsout enable,1 	
	pause 1			

	let pinsB = %00001100	; Display on, no cursor, no blink
	pulsout enable,1 	
#endif
	
	high rs			; Leave in character mode
	return


; display message from EEPROM sub routine
; message number 0-15 must be in b1 when called
; uses (alters) b1, b2, b3, b4
msg:
	let b2 = b1 & %00001111 * line_length
						; EEPROM start address is 0 to 15 multiplied by 16
	let b3 = b2 + line_length - 1 ; end address is start address + (line_length - 1)
	for b4 = b2 to b3			; for 16 times
		read b4,b1			; read next character from EEPROM data memory into b1
		let pinsB = b1 		; output the data
		pulsout enable,1  	; pulse the enable pin to send data.
	next b4				; next loop
	return
	
; Check end user has defined just one type of display
#ifndef use_OLED
#ifndef use_LCD
#error "Oops - no OLED / LCD type defined at top of program!"
#endif
#endif

#ifdef use_OLED
#ifdef use_LCD
#error "Oops - both OLED / LCD types defined at top of program!"
#endif
#endif


Any help here would mean alot to me, thank you for your time.

- Rob
 
Last edited by a moderator:

edmunds

Senior Member
Is there a specific part that does not work or "nothing works" at all? Can you post your code instead of the LCD code? Maybe even edit the post to remove it, since it does not add any value here - it is available to anyone from the web.


Regards,

Edmunds
 

kando

Senior Member
Hi,and welcome to Picaxe... this may help you get started. a few commands to control the OLED screen.. (16x2 lines)
I am presuming you have downloaded the axe133 software into the OLED 18M2.

Oled = pin you have attached the oled screen to. Baud is usually set to N2400

Like this...
symbol oled=b.3 ;the pin the data line to the OLED screen is on
symbol baud=N2400 ; the baud rate you send data to the screen
symbol home=128 ;leftmost position of line 1 of display
symbol base=192 ;leftmost position of line 2 of display

Code:
serout oLed,Baud, (254,1) ;clear oled screen
pause 30 ; after each of these commands. The screen updates.

;place the cursor ready for action in the home position
serout oled,baud,(254,home);place cursor in home position
pause 5

;Place the cursor in the base position ready for action
serout oled,baud,(254,base);place cursor in base position
pause 5 ;some pauses need to be longer (trial and error)

;now to say something
serout oled,baud,(254,home,"PRESS ENTER TO  ")
Pause 30
serout oled,baud,(254,base,"START           ")
pause 30

Bear in mind the screen has only 16 characters in each line. However you can scroll the lines with another command. As an example

for b0=1 to 14		;Scroll
	serout oled,Baud,(254,28)
	pause 30
next b0

Here 28 scrolls it one way and 24 scrolls it the other.
serout oLed,Baud,(254,4) ;Set right to left printing mode
serout oLed,Baud,(254,5) ;Scroll printing to the left
serout oLed,Baud,(254,6) ;Set left to right printing mode
serout oLed,Baud,(254,7) ;Scroll printing to the right

;Cursor movements and blinking character................................
serout oLed,Baud,(254,8) ;Display is turned OFF cursor is OFF 
Blinked character is OFF
serout oLed,Baud,(254,10);Display is turned OFF cursor is ON but not                   visible. Blinked Character is OFF
serout oLed,Baud,(254,11);Display is turned OFF cursor is ON but not visible. Blinked Character is ON but not visible at cursor position
serout oLed,Baud,(254,12);Display is turned ON cursor is turned OFF
Blinked Char is turned OFF
serout oLed,Baud,(254,13);Display is turned ON cursor is turned OFF
Blinked Char is turned on at cursor position
serout oLed,Baud,(254,14);Display is turned ON cursor is turned ON 
Blinked Char is turned OFF
serout oLed,Baud,(254,15);Display is turned ON cursor is turned ON 
Blinked Char is turned ON at cursor position
 
Last edited:

Robbier3

New Member
Hi Kandmo and Edmunds,

Thank you very much for taking the time to help me, I tried playing with what you gave me but I keep getting errors (it tells me that I need to assign a port?) this is what I have so far that isn't working very well:
Code:
#picaxe 20x2

'setfreq m64
    
Symbol Page1 = pinB.6
Symbol Page2 = pinB.1


main:
 
        serout B.7, N2400, (254, 1, 254, 1) ' Clear Screen
        pause 30
     
        
    
'*********** SCREEN 1 *****************

Screen1:    

        Serout B.7, N2400, (254, 128, 253, 2) ' Message 2 from LCD FIRMWARE "Welcome"
                
        Serout B.7, N2400, (254, 128) 'Jump to first line of LCD
    
        pause 100
        
        Serout B.7, N2400, (254, 192) 'Jump to second line of LCD'
	  
	  Serout B.7, N2400, (254, 192, 253, 3) ' Message 3 from LCD FIRMWARE "Testing 123"
                
        Serout B.7, N2400, (254, 192) 'Jump to first line of LCD
    
        pause 200
	  
	  
KeyPressed:
    if Screen2 = 1 then
	pause 50
	gosub Screen2
	else gosub Screen1
	
Screen2:
	
        Serout B.7, N2400, (254, 128, 253, 5) ' Message 5 from LCD FIRMWARE "Page 2"
                
        Serout B.7, N2400, (254, 128) 'Jump to first line of LCD
    
        pause 200
        
        Serout B.7, N2400, (254, 192) 'Jump to second line of LCD'
	  
	 Serout B.7, N2400, (254, 192, 253, 6) ' Message 6 from LCD FIRMWARE "Press to go back"
                
        Serout B.7, N2400, (254, 192) 'Jump to first line of LCD
    
        pause 100
	

	endif
 
Last edited by a moderator:

kando

Senior Member
Hi,
B.7 will be your port as this is the pin you have attached the OLED screen data line to.
In this case below you should be using a picaxe 20X2
The baud rate is the rate you speak to the OLED
the home position is the position 128 (it just is)
the base position is at 192 (it just is)

Ok start with something simple like getting some text onto the screen like this....


Code:
#picaxe 20x2
 symbol oled=b.7 ;the pin the data line to the OLED screen is on
 symbol baud=N2400 ; the baud rate you send data to the screen
 symbol home=128 ;leftmost position of line 1 of display
 symbol base=192 ;leftmost position of line 2 of display

main:
serout oled,baud,(254,1):pause 30;clear OLED display
serout oled,baud,(254,home,"*Hi this is Me**");there are only 16 characters on each line
serout oled,baud,(254,base,"Second line here");there are only 16 characters on each line
pause 10

end; end of program statements
The other commands do other things just try them in place of the second and third command here.

have another go
 

rq3

Senior Member
If you are using the OLED display, then you have uncommented the wrong line in the code:

; ********************************************
; Note you must uncomment just one of these two options
; depending on whether you have an LCD or OLED module
;#define use_OLED
#define use_LCD
; ********************************************

Should be:

; ********************************************
; Note you must uncomment just one of these two options
; depending on whether you have an LCD or OLED module
#define use_OLED
;#define use_LCD
; ********************************************
 

kando

Senior Member
If you are using the OLED display, then you have uncommented the wrong line in the code:

; ********************************************
; Note you must uncomment just one of these two options
; depending on whether you have an LCD or OLED module
;#define use_OLED
#define use_LCD
; ********************************************

Should be:

; ********************************************
; Note you must uncomment just one of these two options
; depending on whether you have an LCD or OLED module
#define use_OLED
;#define use_LCD
; ********************************************
Rq3 is correct in this... You will then have to download the software back into the 18M2 on the OLED
 

mikeyBoo

Senior Member
For what it's worth dept.:

hi Robbier3,
Not specific to your question, but since you are new to Picaxe, I attached a couple of template files that may help you understand the Picaxe register layouts. The Picaxe editor lets you use symbols to represent registers so your code will be easier to read.

I don't use the Picaxe chips a whole lot, so it helps me remember "whut' goes where".

The X, Y, Z register assignments can be ignored if you like. I just use them so I can have reusable code libraries.

If you want, take a look at my project under "User Projects - Misc. Picaxe Kayak Control System.bas". All the subroutines starting with "OLED." deal with writing to the display. If you search "OLED" on the forum, I'm sure there are lots of other examples.

Good luck with your project & (most importantly) have fun!
 

Attachments

Robbier3

New Member
Hi MickeyBoo,

Thank you very much for your assistance and links, I am going to play tonight to see what I can come up with, I hope you have a great day!!!

- Rob
 

Robbier3

New Member
Hi Kando,

It works! Thank you so much! I am going to go through what the other functions do, I think the main thing here is for me to understand what I am doing before I jump to anything bigger like before. Thank you very much, I hope that you are well!

- Rob
 

Robbier3

New Member
Hi rq3,

Thank you for your input, I have a lot to work with now, you guys have been very kind and helpful, enjoy your day!

- Rob
 
Top