Getting Start with 4D System uLCD modules = basic tutorial

westaust55

Moderator
For those who are interested, I finally hooked up a 4D-Systems uLCD 3.2 inch 320 x 200 LCD module that I have had for some time.

To help others get started, the attached document is a form of basic tutorial with PICAXE program included to undertake some of the more simple tasks for display of text and some simple graphics (rectangle, circle and triangle).

At a later data I may extend this with some further programming and examples for other functions.


EDIT: Post 8 has ostensibly the same document but with typos spied now corrected.
 

Attachments

Last edited:

westaust55

Moderator
Thanks folks.

I have in the light of a new day spotted a couple of typos in the words (not the program part) which I will fix soon. :eek:
Maybe even add a photo to show what the end result of the program lines looks like.
 

rgooge

Member
Maybe not, Page 2 - you still have OLEDTx/Rx instead of uLCDTx/Rx for the two assignments..

but great work, I've been playing with the OLed module for a little while now.

By the way, did you ever have any problems with 'incorrectly' shutting down the OLED displays, I know there's manufacturers documentation on this but I'm wondering if it is such a big issue...
 

westaust55

Moderator
Thanks for the bug report.

While in the longer term with established program, I do try to use the shut down in advance, sometimes there is no specific end to a program or I have been lazy and not performed a specific shutdown command prior to removal of the power. If a keypad or similar is involved (inputs permitting) then a shutdown command can be given.

To date at least, with using OLED displays for 1 year the occasional removal of the power supply without a proper shutdown has not yet caused any problem for me.

But at the end of the day, manufacturers should know better than I when stating what SHOULD be done with the use of their products.
So it is a risk but as stated no problems encounters thus far.

Corrected version of Tutorial attached here:
 

Attachments

Last edited:

alistairsam

Senior Member
Hi
That documentation is really good.

I am working on a project using a graphics LCD to display images from a uSD card and was looking at these displays.

I have a picaxe 20x2 sending data to a 16x2 LCD, these are position co-ordinates of a telescope updating in real time based on reading from quadrature encoders. I have all that working fine with a standard LCD.

what I wanted to do was choose an object name from a list in an EEPROM connected to the I2C bus from the picaxe, and when it is chosen, send commands to the graphics LCD to display the image from the uSD card.

can this be done by sending the name of the object to the graphics LCD using serout and a string, and the program in the graphics LCD uses that to call that image from the uSD provided its present?

instead of using a 16x2 LCD, can I output those values to be written to the top of the graphics LCD and have an area below it where the image is displayed?

I'd have switches to turn display on / off, call the image, backlight on/off.
any ideas on how this can be done, that is send the picaxe variables to be displayed as text on top and display a full colour image at the bottom?

I'm reading through the 4dGL documentation and should be able to write up some code for it, but was'nt sure if I needed to keep a 16x2LCD for text, and use the graphics LCD just for the images.

Thanks
 
Last edited:

graynomad

Senior Member
Just looking at the docs they have a full set of drawText commands, display image from SD card, etc etc. Also if you get the touch version you won't need any switches.

So yes, you can ditch the LCD.
 

alistairsam

Senior Member
Just looking at the docs they have a full set of drawText commands, display image from SD card, etc etc. Also if you get the touch version you won't need any switches.

So yes, you can ditch the LCD.
Thanks Rob, thats what I was hoping for. but was'nt sure if it needs to be in text mode to display numbers and in image mode to display graphics and if i can do both at the same time.

I might just use an object list from a text file in the uSD card and then call an image. got some reading of 4dgl to do.
 

graynomad

Senior Member
Well I'm not 100% sure either, but it's so unlikely that you can't use both at once I didn't even consider it.

If you look at the example photos they mostly show text with graphics.
 

westaust55

Moderator
Thanks Rob, thats what I was hoping for. but was'nt sure if it needs to be in text mode to display numbers and in image mode to display graphics and if i can do both at the same time.

I might just use an object list from a text file in the uSD card and then call an image. got some reading of 4dgl to do.
If you are trying to control with the PICAXE chip then you may do better/easier with the serial version and using the LCD 4D-Systems module with the PICASO-SGC firmware. The 4DGL program language is tentatively capable of far more but would take you longer to get to grips with and basically runs from the internal program you develop and only looking for basic signals from the PICAXE.
 
Last edited:

alistairsam

Senior Member
Hi

I got the uLCD024PT(SGC) display, it is a 2.4" serial display with touchscreen.
I also got the USB-MB5, but it does'nt get detected in windows. so have posted in the 4dgl forums.
with the usb module, can you send serial commands from the pc to draw and display objects like the serial commands from an mcu?
i'm going through the serial command set document, hope to test some of the sample scripts.
 

westaust55

Moderator
Hi
can you send serial commands from the pc to draw and display objects like the serial commands from an mcu?
All of my experiementation is based upon PICAXE control of the display not PC control.
Beleieve 4D Systems free FAT COntroller software allows you to control a serial device from a PC but suspect you want to control via some third party program. maybe a post on the 4D forum as you indicate you have done could be more fruitful.
 

alistairsam

Senior Member
Hi,
i started with a 20X2 to send init and text commands as per the getting started guide, but my display only flashes the default splash screen after 5 secs. looks like my serout is not getting across. not sure how i'd test it.
one question i had is we're setting the uLCDRx pin high at power on, and then after a pause, sending the U .
but does'nt the pin have to be taken low? if not, does it go back to high after data is sent without being defined?

my code so far is from the getting started guide.

Code:
#PICAXE 20X2
setfreq m8
; 
dirsC = %00000001

; - - - VARIABLES - - - 
SYMBOL fback   = b13 
symbol uLCDRx = C.0
symbol uLCDTx = B.0



init:

high uLCDRx
pause 8000


initialize:
SEROUT uLCDRx, T9600_8, ($55,$55,$55)  ; automatic baud rate detection bit stream 
 SERIN uLCDTx, T9600_8, fback  ; wait for response to indicate action done 
sertxd ("test",CR,LF)
sertxd (fback,CR,LF)  
 SEROUT uLCDRx, T9600_8, ($51, $04) ; set new baud rate. Using 2400 bps as an example. 
; Note that the baud rate is already changed so we must received the acknowledgement at the new 
'baud rate 
SERIN uLCDTx, T2400_8, fback  ; wait for response to indicate action done 
  
 SEROUT uLCDRx,T2400_8,($59,$03,$01) ; do a screen power up  
 SERIN uLCDTx, T2400_8, fback 
  
 SEROUT uLCDRx,T2400_8,($59,$04,$01) ; for portrait Orientation use ($59,$04,$03) 
 SERTXD ( "set to landscape", cr, lf) 
 SERIN uLCDTx, T2400_8, fback 
   
 SEROUT uLCDRx, T2400_8, ($45)    ; clear the screen 
 SERIN uLCDTx, T2400_8, fback 
  
 SEROUT uLCDRx, T2400_8, ($42, $00, $00)   ; set the background to black 
 SERIN uLCDTx, T2400_8, fback 
 
 main:
 SEROUT uLCDRx, T2400_8, ($70, $00)  ; set the "pen" to draw solid box (ie filled) 
 SERIN uLCDTx, T2400_8, fback
 sertxd (fback,CR,LF) 
    
 SEROUT uLCDRx, T2400_8, ($72, $00, $0A, $00, $5A, $00, $60, $00, $90, $77, $7F) ; draw 
'filled rectangle  
 SERIN uLCDTx, T2400_8, fback 
  
 SEROUT uLCDRx, T2400_8, ($70, $01)  ; set the "pen" to draw wire-frame (ie outline) 
 SERIN uLCDTx, T2400_8, fback 
    
 SEROUT uLCDRx, T2400_8, ($72, $00, $08, $00, $58, $00, $62, $00, $92, $F8, $00) ; draw wire 
'frame rectangle as a border  
 SERIN uLCDTx, T2400_8, fback 
   
 PAUSE 3000
  
goto main
 

westaust55

Moderator
Keep in mind that the 4D Systems products use the Tue polarity and not the iNverted polarity for serial comms.

See that attached diagram and information.

When the PICAXE first starts, IO is generall made as inputs and in cases where some outputs are dedicated as outputs they are made low.
If the output is not configured and made high as soon as the PICAXE starts the 4D Systems display considers a low as a start and will accept any garage as data to determine a baud rate.

The stop bit goes high and stays there so there is no need to use a HIGH command after a byte is sent.

In the Init: part, try reducing the PAUSE duration back to 2000 for 1 second (must be at least 0.5 sec but the 8000 = 4 seconds which is getting a bit long)

In the Autobaud command remove two of the $55 values - you only need one. Mutliple $55/"U" (or similar) is used with 433 MHz radio as a preamble.

What voltage are you running the PICAXE and uLCD module at ? Should by 5Vdc.
 

Attachments

Last edited:

alistairsam

Senior Member
yay, got it working.
i was basically following the pinout from the USB-MB5 usb interface module, and that had J2 pin 2 as Rx and pin3 as Tx printed on its pcb, and since it plugs into the display header pins i assumed it would be correct. But then I checked the display datasheet and found that pin 2 is actually Tx and pin 3 is Rx.

So just reversed my serout and serin pins and it worked perfectly as described in your getting started guide.
thanks for a brilliant manual and the effort in documenting it.

now to start learning how to send commands to read images off the built in usd and display them on input from a touch button. lots of reading required for that.
but atleast i have started.

it worked with a pause of 3000 at the program start, and with T9600 baud.
 
Last edited:

westaust55

Moderator
Great to read you have it working.

Have a read here: http://www.picaxeforum.co.uk/showthread.php?t=16877
in particular post 3.
That loads some images from USD on an OLED and comamnds are fairly similar (mainly two bytes for coordinates on uLCD modules)

I have yet to play with the touch aspect (and also out of town briefly) but will likely post more details (tutorial update) once the touch feature is working with a PICAXE chip
 

alistairsam

Senior Member
Thanks for that. I will go through that thread and try out the images once I get my replacement USB-MB5 card (was faulty, they've sent me a replacement).

Have attached a pic of what I'm displaying.

Not sure how I'll interface the touch with the picaxe, as I need to have two or three different modes, one for a display as attached where it shows the position of my telescope, second to find and display true colour images of objects from the usd card.
I was thinking of using switches and the GPIO pins and possibly a script running on the SGC display.

some things, I'm still not clear about.
how you choose and define colour, how the MSB:LSB works.

Also, I have a mix of static and changing text. I'm erasing and re-writing the changing values by re-writing the text in black, the background colour, rather than erasing the screen.
but is the only method?
 

Attachments

Last edited:

westaust55

Moderator
You can display an image from the microSD card and text or graphic objects in a separate area or over the image

If the text is in the same place all the time another method is to draw a filled rectangle in the background colour.
 

alistairsam

Senior Member
You can display an image from the microSD card and text or graphic objects in a separate area or over the image

If the text is in the same place all the time another method is to draw a filled rectangle in the background colour.
Just found another method from the 4d forum
"Why not just set the opacity to 1 then the text is alway printed over the old text including the removal of the old info behind it."

will give it a shot. if it works, it'll save redrawing with black or drawing a filled rectangle and should be fast. not sure if you've already tried it though.
 

alistairsam

Senior Member
just tested the opaque text method for changing text without refresh or redraw in black and it works perfectly.
eliminates the need to send same text in black again, or rectangle to rewrite a text character. so no flicker at all.
command is $4F,$01

Code:
variabl_display:

for gg = 1 to 360
 
SEROUT uLCDRx, T9600_64,($4F,$01,$73,$07,$03,$03,$F8,$00,#w10,$00)
SERIN uLCDTx, T9600_64, fback
  
'SEROUT uLCDRx, T9600_64,($73,$07,$03,$03,$00,$00,#w10,$00)
'SERIN uLCDTx, T9600_64, fback

SEROUT uLCDRx, T9600_64,($4F,$01,$73,$07,$0D,$03,$F8,$00,#w10,$00)
SERIN uLCDTx, T9600_64, fback
  
'SEROUT uLCDRx, T9600_64,($73,$07,$0D,$03,$00,$00,#w10,$00)
'SERIN uLCDTx, T9600_64, fback

next gg

goto variabl_display
 

alistairsam

Senior Member
Great to read that the opacity method works.
We can all learn something new every day.
just one issue that i noticed. if its say a 2 character text, and it changes to a 1 character, the 2nd character is not erased. so need to modify the picaxe code.

what I was thinking was if its numbers, say from 1 to 300, i'll send an erase or write in black command when it goes under 100, and another erase or black when it goes under 10.
maybe you'll would have some better ideas on how to workaround this especially if values go higher and lower by a random factor.
 

alistairsam

Senior Member
i'm now trying to get the touch screen to work.
this was what was suggested on the 4d forums.

"You 'poll' the touch screen for activity using normal SGC commands. It will tell you if a touch has occurred since you last poll and you can also find out where, you don't need 'real time interrupts' or anything. it happens concurrently with other activity."

as you might know, we'll need to retrieve the x,y co-ordinate when a touch has occurred and then based on the range of the value returned, the picaxe can send the desired action.
would this be the ideal method?
 

alistairsam

Senior Member
solved the character erase issue mentioned earlier with a piece of code mentioned by ckoehn in a different thread.
works perfectly. :)

Code:
variabl_display:

for gg = 1 to 360

bintoascii gg,b0,b1,b2

if b0=48 then 'if a zero
b0=32 'change to a space
endif
if b0=32 and b1=48 then 'if first is a space and second is a zero
b1=32 'change to a space
endif

 
SEROUT uLCDRx, T9600_64,($4F,$01,$73,$07,$03,$03,$F8,$00,b0,b1,b2,$00)
SERIN uLCDTx, T9600_64, fback
  
next gg

goto variabl_display
 

westaust55

Moderator
using opacity command

I have also just tried the same approach on the uOLED displays and the opacity methods works equally as well there instead of filling the area first in the background colour. :)
 

westaust55

Moderator
Yes, will be aiming to do so soon.

Maybe a couple of days away as I am currently doing a few experiences with an OLED display at the moment and intending to write up a more complete single document as a summarised basic tutorial for the OLED display as opposed to multiple posts.
 

alistairsam

Senior Member
maybe I should google this up but what is the difference between OLED and LCD displays in terms of the screen, pros and cons?

as for the touch screen, I might experiment with having a 4dgl script running as the autoexec script and handle the file listing and image display part, and the picaxe sending data to other parts of the screen. just a theory but might be possible.
 

alistairsam

Senior Member
i finally got a slideshow of images working using the serial 4ds display and an autoexec.4ds script that reads images off a uSD card.
got the touch to work with the picaxe as well. so far, i've got it to get touch co-ordinates and display them on screen.
trying to draw pixels based on co-ordinates received so that pixel would follow the stylus around the screen.
finally to get menus and touch buttons to work with the picaxe.
 

killmanager2

New Member
Help please

I tried the code but i still get nothing just white for about a 1s then black. I am using PICAXE 18M2 @ 4.5V with an uLCD-144. This is the code...

symbol Tx = 6
symbol Rx = 5
#PICAXE 18M2
symbol bfeed = b13
Init:
setfreq m8
High Tx
pause 2000

serout Rx, T9600_8, ($55)
serin Tx, T9600_8, bfeed

serout Rx, T9600_8, ($51, $04)

serin Tx, T9600_8, bfeed

serout Rx, T2400_8, ($59,$03,$01)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($59,$04,$01)
sertxd ("set to landscape", cr, lf)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($45)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($42,$00,$00)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($74,"W",$00,$08,$00,$00,$FF,$FF,$01,$01)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($74,"R",$00,$10,$00,$00,$F8,$00,$01,$01)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($74,"G",$00,$18,$00,$08,$07,$E0,$01,$01)
serin Tx, T2400_8, bfeed

serout Rx, T2400_8, ($74,"B", $00,$20,$00,$10,$00,$1F,$02,$02)
serin Tx, T2400_8, bfeed

Any help would be greatly received.
 

Goeytex

Senior Member
I just got my µLCD-144(GFX) up and running and integrated with my latest Picaxe RF project. Loaded the SGC personality file
and connected it up to Picaxe 20X2. Set serial speed to 38400 with the Picaxe running at 32mHz - no problems if a little care is taken
with the timing as the unit powers up. Now I have a nice visual of data being received and sent by the Primary RX module.
This gets the Project off of the PC.

These are really nice displays. When configured as SGC .... it gives Picaxe access to tons of SD Card memory via serial commands/scripts.
I think would be very good for a developing a Picaxe Data Logger Application using a 2 - 4 gig SD card.

GFX mode opens up a world of possibilities.

Thanks for the Tutorial. Saved me a bit of time.

Goey
 
Last edited:
Top