Serial to LCD programming problems

Haku

Senior Member
Yesterday I received a SMD 20m2 which I superglued to the back of one of my miniature 16x2 LCD screens, along with pin headers, programming resistors & 0.1uf cap:



It works great in terms of being able to display characters on the screen from content already within the Picaxe, the problem is when I try to use it as a serial-to-LCD backpack, erroneous characters appear and it doesn't always pick up on the serial data being sent to it. The 's' in the display in the above picture should not be there.

This is the code I'm using, which is an adaption from the code on this page http://www.jrhackett.net/LCD16.shtml

Code:
#picaxe 20m2
#no_data
#terminal off

' 20m2 serial-to-LCD backpack

symbol cmd = 0                   ' LCD command datatype
symbol txt = 1                   ' LCD ASCII text datatype
symbol LCDenable = c.4           ' LCD LCDenable pin
symbol Datatype = pinc.5         ' LCD register select signal pin
symbol SerialSource = c.7        ' serial input pin

setfreq m32
symbol baud=N9600_32

dirsb=255                        ' set portb to output
output c.4,c.5                   ' set control of LCD lines to output

'initialise LCD
pinsb=56:pulsout LCDenable,1     ' 8 bit 2 line LCD
pause 20                         ' allow setting to take effect
pinsb=12:pulsout LCDenable,1     ' cursor off
pause 20                         ' allow setting to take effect
pinsb=1:pulsout LCDenable,1      ' clear screen
pause 20                         ' allow setting to take effect


do
 bptr=28
 serin SerialSource,baud,@bptrinc
 serin [200],SerialSource, baud, @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
 @bptr=0
 bptr=28
 do until @bptr=0
  pinsb=@bptrinc
  select case pinsb
  case 0 to 31
   Datatype=cmd
  case 128 to 207
   Datatype=cmd
  else
   Datatype=txt
  endselect
  pulsout LCDenable,1
 loop
loop
When I hook in a commercially made LCD screen with serial backpack it doesn't have any glitches so I know the serial stream is ok. How can I make the Picaxe more robust and not miss any incoming data? I tried running at 4800baud but still get erroneous characters sometimes appearing.
 

srnet

Senior Member
Should you not have a delay after the LCDenable pulse to allow the LCD to finish the write, before the PICAXE writes another character ?
 

hippy

Technical Support
Staff member
I suspect its some timing issue and they are always hard to analyse. Seeing the code which sends to the 20M2 may help.
 

Haku

Senior Member
It's a timing issue of sorts but I don't think it's one to do with the commands sent to the LCD screen, for example if this code is run there's no glitches at all, removing the "pause 8000" line and replacing it with "pause 10" works, but I tried this with the serial-to-LCD code and it didn't have much effect at all.
Code:
#picaxe 20m2

data  0,("Picaxe 20M2  LCD")
data 16,("8-bit   Parallel")

symbol cmd = 0                   ' LCD command datatype
symbol txt = 1                   ' LCD ASCII text datatype
symbol LCDenable = c.4           ' LCD LCDenable pin
symbol Datatype = pinc.5         ' LCD register select signal pin

setfreq m32

dirsb=255                        ' set portb to output
output c.4,c.5                   ' set control of LCD lines to output

'initialise LCD
pinsb=56:pulsout LCDenable,1     ' 8 bit 2 line LCD
pause 20                         ' allow setting to take effect
pinsb=12:pulsout LCDenable,1     ' cursor off
pause 20                         ' allow setting to take effect
pinsb=1:pulsout LCDenable,1      ' clear screen
pause 20                         ' allow setting to take effect


do
 pinsb=128:Datatype=cmd:pulsout LCDenable,1 ' move cursor to beginning of line 1
 
 ' read & display data on LCD screen
 Datatype=txt
 for b0=0 to 15
  read b0,pinsb
  pulsout LCDenable,1
 next b0
 
 pinsb=192:Datatype=cmd:pulsout LCDenable,1 ' move cursor to beginning of line 2
 
 ' read & display data on LCD screen
 Datatype=txt
 for b0=16 to 32
  read b0,pinsb
  pulsout LCDenable,1
 next b0
 
 pause 8000
 
 pinsb=1:Datatype=cmd:pulsout LCDenable,1   ' clear screen
 
 pause 8000

loop

The data being sent to the 20m2 acting as a serial-to-LCD is a continual stream (not fully saturated at 9600 baud) showing the X & Y of a pair of analogue control sticks, a proper serial-to-LCD backpack has no problems coping with the data but it looks like the Picaxe just isn't fast enough at being able to keep up with receiving the data and then displaying it.
 

g6ejd

Senior Member
How about adding another stop bit to sending data stream.

You've got 104uS between each character symbol (9600 bit time), which is not a lot of time for the PICAXE to do much.

You could read your data in to RAM in small sections, maybe 20-bytes, then write them all out, having pre-loaded the area with say a 'space'

Most data sheets require 10mS for the display to react.

You could write to the display synchronously, waiting for an acknowledgment before proceeding.
 

Technical

Technical Support
Staff member
On the transmitter chip, send the data one byte at a time with a 10ms or so gap between bytes - does the error still occur?
 

Haku

Senior Member
I've tried various methods of getting the received serial data onto the LCD but none are as reliable as a firmware chip in terms of not losing any of the incoming stream.

I tried a quick test of sending a repeating message with 10ms pauses inbetween each character. but the characters don't get displayed real-time, the serin command continues running until all the @bptrinc's are filled up and then the rest of the code displays the buffer all at once, then loops back round to read in more characters in which time some of the incoming characters are often lost.

Oh well and I was hoping it would be a nice prototyping/debugging tool considering it's size is significantly smaller than the 20*2 LCD with serial backpack I have. Guess it'll have to be designated for a project that doesn't need instant constantly updating real-time data to be displayed, the 20m2 still has 5 unused pins so maybe it'll find a perfect place in a future project.
 

g6ejd

Senior Member
9600 baud data is relatiively slow, and I'm sure the PICAXE has more than enough performance to cope with your requirement, I think you need to consider a different software architecture to achieve your outcome. There is also an option of dropping down a level to machine code.
 

mrburnette

Senior Member
It works great in terms of being able to display characters on the screen from content already within the Picaxe, the problem is when I try to use it as a serial-to-LCD backpack, erroneous characters appear and it doesn't always pick up on the serial data being sent to it. The 's' in the display in the above picture should not be there.
My suspicion is interference ... you have the chip directly glued on top of the circuit board traces and have all of those little "antennas" (wire jumpers) connecting it with the display. I prototyped a 08M2 counter from a 1 second timer on PIN #4 and just moving my hand around the breadboard jumpers would override the 4.5V 50mS pulse and the PICAXE would start counting the AC hum from my body... of course, I was acting as a big antenna and inducing the 60Hz signal into the PICAXE.

- Ray

Note: you said "superglue" but I am hopeful that you did not use any of the cyanoacrylate based adhesives... these products should never be used around electronics because of the corrosion potential of the vapors.
 

Haku

Senior Member
Thanks for the AXE133 idea, I tried the core loop of that code at 2400 and no problems, then tried 4800 and still no problems but it just displays garbled characters at 9600 so I don't understand how you managed to get it to work at 38400.
 

g6ejd

Senior Member
Why don't you do what hippy suggests and use the axe133 code, because that works and you only have to change 1-line to get the right Baud-rate.

Alternatively, looking at your code, you appear to writing data in parallel to the display, but on then line:

pulsout LCDenable,1 ' this lasts for 1.25uS which is outside of the HD44780 specification, which cites 4uS, so :

pulsout LCDenable,5 ' brings the operation inside the display driver specification if your running at 32MHz

Actually, could you take the time to show us the circuit diagram, as that would enable a very quick diaganotics to be completed.

Final thoughts are to measure the clock frequency or use the clock calibration command, well adjust it slighlty slower or faster and see what the effect is, could be your clock is way off (unlikely) but you never know.
 
Last edited:

hippy

Technical Support
Staff member
Why don't you do what hippy suggests and use the axe133 code, because that works and you only have to change 1-line to get the right Baud-rate.
The AXE133 code is specifically designed for operation at N2400 and using higher baud rates may also require a change in clock speed and is also dependent on how close together the sending PICAXE sends each byte out - The 18M2 LCD/OLED controller has only a limited time in which to do all it needs to and be back ready for the next character received.

Various techniques ( such as the earlier code using @bptrinc ) can be used to buffer bytes received and then output one after each other at leisure, but then that limits the amount of data in each SERTXD command and a further SERTXD cannot be issued until the previous data has been output from the buffer.

Perhaps the easiest course is to stick with N2400 baud and use that in the sending program, dropping down to 4MHz/8MHz when executing SERTXD.
 

Haku

Senior Member
I've not yet encountered any timing issues regarding Picaxe>LCD as I've had a 28x2 running at 40mhz controlling one of these miniature screens without any glitches with using "pulsout enable,1", it wasn't acting as a serial-to-LCD unit though, but I also got some new 28x2's & 40x2's with some 16mhz resonators so out of curiosity one day I might try running one at 64mhz as a 9600baud serial-to-LCD using the AXE133 code.

The 20m2 is running perfectly fine as a 4800baud serial-to-LCD using some of the AXE133 code so I'm happy with that.
 

John West

Senior Member
<snip>
Note: you said "superglue" but I am hopeful that you did not use any of the cyanoacrylate based adhesives... these products should never be used around electronics because of the corrosion potential of the vapors.
Do not use super-glue anywhere that you might ever again place a soldering iron tip. I made that mistake and a single whiff of the vapor was a violent assault on both my eyes and respiratory system. I'm guessing that the vapor produced by heating cyano-acrylate is quite likely "cyanide."

Whether it is or isn't, it's truly nasty stuff to inhale or get in one's eyes.

BTW, it's a much better practice to use the "dead bug" construction technique in situations like this one. Simply flip the IC on its back and glue it to the PCB that way. Then the chip legs will not be touching the bd traces with nothing to insulate them from the traces besides solder mask, (which was never intended to be an insulator.)
 
Top