Connecting ZX-24PE to Serial LCD+2

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
Conrad_Turbo
Posts: 20
Joined: 16 July 2009, 9:31 AM

Connecting ZX-24PE to Serial LCD+2

Post by Conrad_Turbo »

I've been away from the BasicX/ZBasic scene for a while but I have begun to dabble in it again for a project I am working on. I used to have the Serial LCD+2 from BasicX connected to my BX24 (which is now long gone). So now I am trying to connect the LCD screen to the ZX-24PE that I have and just cannot seem to get it to communicate.

This is what I have read and done:
ZX-24PE - USART Serial Port
Com2 TX Pin 17 - connected to RX of LCD
Com2 RX Pin18 - connected to TX of LCD

Serial LCD+2
http://basicx.com/Products/LCD+/LCD%2B2 ... ide1.0.pdf
COM jumper is not installed, it is set up for non-inverted serial input
Initial power up test passed

The ZX24PE and Serial LCD+2 are running off the same 5V regulator. Here is the code snippet in my attempt to clear the LCD screen and put some text on it.

Code: Select all

'-----------------------------------------------------
Option Explicit
Const Clear_screen As Byte = 12
Const Position_Cursor As Byte = 16
'-----------------------------------------------------
Public Sub Main()

Dim Com_Out(1 To 40) As Byte
Dim Com_In(1 To 30) As Byte

	Call OpenQueue(Com_Out, SizeOf(Com_Out))
	Call OpenQueue(Com_In, SizeOf(Com_In))
	'Call ComChannels&#40;2, 9600&#41; <- only needed for Com3 or greater
	'Define pins for Com2 &#40;RX = pin18, TX = pin17&#41;
	Call DefineCom&#40;2, 18, 17, &H08&#41;
	Call OpenCom&#40;2, 9600, Com_In, Com_Out&#41; 
	'Wait for a bit 
	Call Delay&#40;0.25&#41; 
	'Clear LCD screen
	Call PutQueuestr&#40;Com_Out, Chr&#40;Clear_Screen&#41;&#41;
	Call PutQueueStr&#40;Com_Out, Chr&#40;Position_Cursor&#41; & Chr&#40;0&#41;&#41;
	Call PutQueueStr&#40;Com_Out, "Can you see me now?"&#41;

End Sub
'-----------------------------------------------------
Any ideas on what is wrong?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Connecting ZX-24PE to Serial LCD+2

Post by dkinzer »

I added code tags to make the code portion of your post more readable.
Conrad_Turbo wrote:Any ideas on what is wrong?
Nothing jumps out at me. Have you checked to see if the characters being added to the queue are actually being sent? You could hook up a level converter with its input attached to the TxD line out of the ZX and monitor the data using a terminal emulator running on a PC. Also, you could add code to after each addition to the queue to pause for a bit (long enough to send the characters added) and then query the queue to find out how many characters are present - it should be zero if you wait long enough.

Also, the DefineCom() call is not required, in most cases, for a hardware serial port. Even if you do need it (for example, to set two stop bits), you should pass zero for the pin parameters since the pins are pre-defined for each hardware serial channel.
- Don Kinzer
Conrad_Turbo
Posts: 20
Joined: 16 July 2009, 9:31 AM

Post by Conrad_Turbo »

Thanks for the heads up Don. I had a friend playing with the LCD+2/ZX24PE combo, he managed to hook up the LCD+2 to a 12v line as opposed to the 5v... So I'm on the hunt for a new serial LCD screen. :lol:

However I do have another serial question, this time to do with a serial input. I am interfacing a 2x8 keypad to an EDE1144 which is set up to communicate at 9600 baud. I have it connected to Pin 18 of the ZX24PE. For now (until I get a new LCD screen) I am just Debug.Print the keypress to see if it is working. This is what I have:

Code: Select all

'-------------------------------------------------------------------------------
Public Sub Main&#40;&#41;

        'Pin 18 is RX Com2 input
	Call OpenQueue&#40;Com_In, SizeOf&#40;Com_In&#41;&#41;
	Call OpenCom&#40;2, 9600, Com_In, 0&#41; 'set up Com2 as a receiver only serial channel

	Dim Character as Byte
	Dim Success as Boolean
	
	Do
		'Find out if anything is in the queue.
		Success = StatusQueue&#40;Com_In&#41;

		' If data is in the queue, extract it.
		If &#40;Success&#41; Then
			Call GetQueue&#40;Com_In, Character, 1&#41;
			Debug.Print Character 'CStr&#40;Character&#41;
			Call ClearQueue&#40;Character&#41;
		Else
			Character = 0
		End If
	Loop
End Sub
'-------------------------------------------------------------------------------
Now the problem I have when I press a button on the keypad is that the number being printed is not consistent. I am using this specific keypad:
http://www.allelectronics.com/make-a-st ... -8//1.html

Any idea why?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

I changed the quote tag to a code tag in immediately preceding post. The latter is the one that uses a monospace font suitable for code. You can see how this looks in edit mode by clicking the Edit button on that post.
Conrad_Turbo wrote:Now the problem I have when I press a button on the keypad is that the number being printed is not consistent.
You can determine if the problem is with the EDE1144 or the ZX by connecting a level converter to the output of the EDE1144 and monitoring it with a PC running a terminal emulator program. If you see inconsistent data on the PC it is almost certainly a problem with the keyboard encoder.

By the way, you don't need (and almost certainly don't want) the call to ClearQueue() in the loop. The call to GetQueue() removes the oldest character in the queue, allowing the next-oldest to be seen on the next pass. Also, you may want to use the Chr() function to convert the character value received to a single-character string.
- Don Kinzer
Conrad_Turbo
Posts: 20
Joined: 16 July 2009, 9:31 AM

Post by Conrad_Turbo »

I see what you mean about using the code instead of quote button. I've never actually posted code on any forum, other than here, thanks for the heads up.

Don I appreciate the input. So on the serial output of the EDE1144 I should connect a MAX232 chip and then feed that to the PC. Then use Hyperterminal to view the incoming data?

Sorry I am not super terribly electronics proficient, but just want to make sure I am understanding your correctly.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Conrad_Turbo wrote:So on the serial output of the EDE1144 I should connect a MAX232 chip and then feed that to the PC. Then use Hyperterminal to view the incoming data?
Exactly so. The attached image shows one way to do this (Sout is the output from the EDE1144). A circuit like this is handy to have around as it allows you to "spy" on a serial data stream using the PC without affecting it at all. If you wanted to see both sides of the serial communication, you could add a second DB-9F and connect its pin 2 to pin 7 of the MAX232, connecting pin 10 to the receive side of the serial channel. If you're going to breadboard something like this you should probably also include inverters to allow you to spy on inverted serial streams, too.

N.B. check the datasheet of the actual converter chip you use. Some of them require 1uF capacitors while others require only 100nF. Others (like the max3232) require 330nF when running on 5 volts but only 100nF when running on 3.3V.

By the way, many people prefer TeraTerm or Bray's Terminal over Hyperterminal; there are probably others as well.
Attachments
level-converter.jpg
level-converter.jpg (34.54 KiB) Viewed 6250 times
- Don Kinzer
Conrad_Turbo
Posts: 20
Joined: 16 July 2009, 9:31 AM

Post by Conrad_Turbo »

Awesome thanks for the heads up. I have had the EDE1144 for quite a few years sitting in a electronics part drawer, finally had the need to use it and just odd how it is erratic.

I do have a few MAX232 kicking around in another drawer and should have the appropriate caps as well, everything is running off 5V so I will make note which specific caps to use.

I will be trying this out over the next few days. I have an o-scope so I can put up screen shots of whatever is needed too.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Conrad_Turbo wrote:I do have a few MAX232 kicking around in another drawer and should have the appropriate caps as well, everything is running off 5V so I will make note which specific caps to use.
The MAX232 operates at +5V only and requires 1uF capacitors. In contrast, the MAX202, ST202 and similar chips operate on +5 but only need 100nF capacitors. The MAX3232 can operate on either 3.3V or 5V but needs larger capacitors when operating at 5V.

If you use polarized 1uF capacitors you must be careful to orient them the correct way. Here again, the datasheet offers the guidance needed.
- Don Kinzer
Conrad_Turbo
Posts: 20
Joined: 16 July 2009, 9:31 AM

Post by Conrad_Turbo »

I am using the MAX232CPE with non-polarized 1uF caps. I downloaded TeraTerm and am looking at serial port Com1.

If I quickly press button 1 I get: 1XXXC, the number of XXX is not consistent, it'll either come out at 1C or have more than three 1's show up, followed by a C. Button 6, I get 76E, 76, 7E, 76EE, 76. Button 7 I get 9 show up and more 9's depending on how long I hold it.

I'm not sure how this relates to the info on the datasheet for the EDE1144:
http://www.paladinsemi.com/ic_datasheets/pdn1144.pdf

Looking at the EDE1144 datasheet I realized I missed something the 330&#937; resistors and the 4.7k&#937; for the keypad. :oops: :lol: Too bad they couldn't have incorporated these resistors into the EDE1144... I will add them and report how things turn out.

I will leave the MAX232CPE on the project board, it is sharing the output TX from the EDE1144 with the ZX24PE as well. The keypad project board is connected to the ZX24PE project board with approximately 4' of twisted 22ga wire.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Conrad_Turbo wrote:I'm not sure how this relates to the info on the datasheet for the EDE1144
Pressing the '1' key once should result in a single ASCII 1 being sent. The spurious characters following the expected character is almost certainly due to the omission of the pulldown resistors. The 330 ohm resistors are to protect the outputs of the EDE1144 in case multiple keys in different rows are pressed at the same time.

The way that a matrix keypad driver usually works is to output a zero or one on one of the row or column lines and then read in the column or row lines. In this particular case, given that pulldowns are used on the column lines the EDE1144 surely outputs a one on each row line in succession and reads back the column lines after each. A reading of zero means no keys are pressed and one bits in the individual columns mean that that column key is pressed in the row currently being driven with a one.
- Don Kinzer
Conrad_Turbo
Posts: 20
Joined: 16 July 2009, 9:31 AM

Post by Conrad_Turbo »

Don, thanks for the help! Adding the resistors did the trick, can't believe I missed them! I checked the data serially through the MAX232CPE, then had the serial data pass to the ZX24PE and debug.print with the above code. The output seems to be consistent now. Question for you, what would be the most efficient way of coding to have the "Character" coming from the EDE1144 be translated in the ZX24PE to relate to the actual key being pressed?

For example when I press button #1, character = 48. If I press button #2, character = 49. Do a bunch of If Then statements?

Code: Select all

			If Character = 48 Then
				Character = 1
			ElseIf Character = 49 Then
				Character = 2
			End If
Only one catch is some of the keys are direction keys, 2nd, clear, help and enter keys...so Character cannot be a byte in that case.

I appreciate your input Don!
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Conrad_Turbo wrote:[W]hat would be the most efficient way of coding to have the "Character" coming from the EDE1144 be translated in the ZX24PE to relate to the actual key being pressed?
The value received for each key is the ASCII representation of the key value, i.e. 0 is &H30, 1 is &H31, ... 9 is &H39. For that series of keys, you can convert the ASCII code to the corresponding value simply by subtracting &H30 and you can detect a key in that range by using a compound conditional:

Code: Select all

If &#40;&#40;key >= &H30&#41; And &#40;key <= &H39&#41;&#41; Then
I would suggest using the key codes as sent by the EDE1144 and only convert them as needed, e.g. the numeric keys. You might want to take a look at the matrix keypad code that I posted:i2c Matrix Keypad. In particular, the function GetUnsignedVal() collects a series of keypresses terminated by the Enter key and returns the decimal value.
- Don Kinzer
Post Reply