lcd to serial or i2c?

ac21

Member
So oi bought a 2x16 LCD and connected it parallel, I want to use it to display variables like i2c info but searching on how to do this yields little to no info, so I'm planning on sacrificing a chip and turning it into a serial LCD or i2c.. Please advice which should be better.
 

hippy

Ex-Staff (retired)
A serial interface to your LCD would probably be better, being easiest, using only one interface line, and because there is example code for doing that.

It would also be worth looking at the AXE132 which is what you would probably be creating in doing it yourself ...

http://www.techsupplies.co.uk/axe132
 

westaust55

Moderator
The i2c based interface is do-able but more complex in code and may reduce the level of support you receive as it becomes more specific to your project.
The have been past threads where folks have bought PCF8574 (i2c IO expander) based interfaced LCD modules and then through lack of documentation find themselves asking for help with code to drive the display.
If you are competent with i2c and have a project with other i2c devices then yes it can save needing any more PICAXE IO pins but you do need a larger block of BASIC program code to drive the display (similar to needing more code to drive a parallel interfaced display).
 

erco

Senior Member
Here's a cheap ($1.51 USD) and interesting I2C/parallel driver for typical Hitachi HD44780/1602 LCD displays: http://www.ebay.com/itm/New-5V-IIC-I2C-Serial-Interface-Board-Module-For-Arduino-1602-LCD-Display/360791383879?rt=nc&_trksid=p2047675.m1851&_trkparms=aid=222002&algo=SIC.FIT&ao=1&asc=261&meid=4815539989708715093&pid=100005&prg=1088&rk=5&rkt=5&sd=281169588018&#ht_4175wt_879

I'm told this is more Arduino-centric since there is an Arduino library for this device. It may be more difficult to use with a PicAxe. I ordered one, it's cheap enough to try.

PH Anderson's LCD117 seems to be a crowd pleaser for the PicAxe & Stamp crowd: http://www.phanderson.com/lcd106/lcd107.html
 

ac21

Member
If I'm gonna use set up my 20m2 like the example Inglewoodpete posted, what baud rate can i set it to.
 

Paix

Senior Member
With the greatest of respect Ac21, you ask a question which indicates that you have not even looked at IWP's code. Your ambition isn't to be questioned, but you must learn to read the information directly available.

From the code:
Code:
#PICAXE 20X2
#Terminal 9600
It is best to use other people to answer the questions that you are not able to simply answer for yourself :)
previously in the code:
Code:
'Version 0.0 114 bytes 01-Apr-2013 Original 08M Version.  Max speed 4800 baud.
. . .
. . .
        'Initialise serial uplink
      'hSerSetup B4800_8, %00110   '%abcde where, for X2 chips:
      hSerSetup B115200_8, %00110  '%abcde where, for X2 chips:

Mk I eyeball is king! What conclusion do you come to regarding the Hserial speed and speed in use with the monitor?
 

ac21

Member
I saw that but for 20m2 I thought it might be different.
I'm very new to this, thank you for your help.

Tried it but failed it looks like the x2 has more features then m2:(
 
Last edited:

Paix

Senior Member
The X2 series has a range of commands that are not available to the M2 series. What I could recommend is looking through the code and sorting out the different Basic commands that are used, into a list, and then looking them up in the Manual #2 to see if they are applicable on your target processor.

A number of the missing ones which are available on X2 are bit oriented and you might find that it is a little more adept on the HS serial, which might be a bit of a deal breaker for you on this Inglewoodpete clone project.

I only use 09M2 and 18M2 chips to keep my options down. Occasionally it means that there are things that are out of my range, but that is a conscious decision. If I was really desperate I would embrace additional chips, but generally life is too short to follow everything.

Forgive me if I was a bit blunt, but the sooner you start making your own discoveries, the sooner you will develop the nack of examining and understanding a lot of the code, at least in part. That's the start.

Houston, I hope you don't have a problem !

I have to dash; I have bees to check up on, and more. Makes me wonder about bees in the US and the California almond crop that should be getting pollinated about now, but there is drought there and snow in a lot of other states . . . at least we can do Picaxe programming from the armchair :)

Start small and work your way up. Serial communication isn't something that everyone understands from day one.
Good luck.
 

hippy

Ex-Staff (retired)
Tried it but failed it looks like the x2 has more features then m2:(
That is correct; the M2's do not have the large background receive buffer for serial and nor can they operate as I2C Slaves.

To use inglewoodpete's example you would need to use an X2 chip.

If you wish to use an M2 chip then the code for the AXE132 product range would be a good starting point.
 

ac21

Member
No Paix, No problems in Houston, a little chilly tho:)

hippy I copied the AXE133Y Firmware and adapted it to the 20m2

WP_000208.jpg
WP_000209.jpg

i have some doubts tho:rolleyes:

Code:
symbol baud = N2400_16	; Serial baud rate 2400,N,8,1. Note main program runs at 16MHz
this actually means it will run at three times the speed of 2400 baud?

In the original code the 18m2 used pin c.5 for serial input which is a input only pin(c.6 for me), at what rate can this pin receive data, ideally if a hserin pin was available that would be best correct?

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 20m2

; ********************************************
; 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.6 ; serial receive pin
symbol enable     = C.4 ; 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, ("     Picaxe     ")    ; store msg in the EEPROM memory
#endif


EEPROM $10, ("----------------")    ; 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 = %10110000   ; PortC 0,1,2,6,7 all outputs
	let dirsB = %11111111   ; PortB all outputs
	output c.4
	output c.7

	
#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
 

hippy

Ex-Staff (retired)
Code:
symbol baud = N2400_16	; Serial baud rate 2400,N,8,1. Note main program runs at 16MHz
this actually means it will run at three times the speed of 2400 baud?
No; it means it uses 2400 baud while the PICAXE itself is running at 16MHz.

In the original code the 18m2 used pin c.5 for serial input which is a input only pin(c.6 for me), at what rate can this pin receive data
The input pin can receive a wide range of baud rates, but it's more an issue of how fast the baud rate can be before the application fails to function as desired. I believe the maximum may be 4800 if run at 32MHz.

ideally if a hserin pin was available that would be best correct?
Having a large serial background receive buffer would be best. The M2 chips do not have that.

I doubt using HSERIN on an M2 would have any advantage over SERIN in this application, it may well be more trouble than it is worth. I don't know if anyone has actually tried it.
 
Top