Let's Make Robots!

Help with Picaxe and serial LCD

Ok Picaxe Basic Gurus... I think I need some code snippits...

My new serial enabled LCD just arrived and I can't seem to get it up and running. I am using what I think is the standard picaxe basic commands but I am only getting white blocks, x's and some other random symbols. To be honest, I am confused with a lot of the serial commands in general, the whole ASCII thing and anything written as 0x7C or 0x14 or whatever.

Here is the display.

Here is the PDF

For instance, I first need to change the baud rate. The instructions tell me to send 124 followed by "<control>k" . Now it seems the picaxe standard is 2400 baud. What is the actual command? Do I send the "change baud" command at 2400 baud when the display is at a default of 9600? and then the command number is 124 and also 0x7C so what do I do?

In my mind (and to show I have no idea what I am doing) here are all the options I can see:

serout 7,N2400, (124, "<control>K")

-or-

serout 7,N2400,(124)

pause 5

serout 7,N2400,("<control>K")

-or-

serout 7,N2400,($7c, "<control>k")

I could go on and on with my guessing but nothing is working.

In general, I assume my major problem is with the baud rate, I hope and assume that after I get that fixed I should be able to return to the standard serout 7,N2400,("Hello") sorta commands.

Would anyone be so kind as to give me a crash course on what you think I should know?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I've got nothing! here is a table of the codes you sent compared to the characters that got displayed. Notice how lower "h" no longer gets mangled into upper "H", but into a "white square" which usually indicates some sort of unprintable or unrecognised character.

 

intended
result
sent (dec)
result (dec)
diff (dec)
sent (bin)
result (bin)
!
o
33
111
-78
010 0001
110 1111
"
7
34
55
-21
010 0010
011 0111
#
n
35
110
-75
010 0011
110 1110
$
unknown
36
n/a

010 0100
n/a
%
m
37
109
-72
010 0101
110 1101
&
6
38
54
-16
010 0110
011 0110
'
l
39
76
-37
010 0111
100 1100
(
white square
40
n/a

010 1000
n/a
)
k
41
107
-66
010 1001
110 1011
asterisk
5
42
53
-11
010 1010
011 0101
+
j
43
106
-63
010 1011
110 1010
,
.
44
46
-2
010 1100
010 1110
-
i
45
105
-60
010 1101
110 1001
.
4
46
52
-6
010 1110
011 0100
/
h
47
104
-57
010 1111
110 1000
0
unknown
48
n/a

011 0000
n/a
1
g
49
103
-54
011 0001
110 0111
2
3
50
51
-1
011 0010
011 0011
3
f
51
102
-51
011 0011
110 0110
4
unknown
52
n/a

011 0100
n/a
5
e
53
101
-48
011 0101
110 0101
6
2
54
50
4
011 0110
011 0010
7
d
55
100
-45
011 0111
110 0100
8
white square
56
n/a

011 1000
n/a
9
c
57
99
-42
011 1001
110 0011
:
1
58
49
9
011 1010
011 0001
;
b
59
98
-39
011 1011
110 0010
<
unknown
60
n/a

011 1100
n/a
=
a
61
97
-36
011 1101
110 0001
>
0
62
48
14
011 1110
011 0000
?
'
63
39
24
011 1111
010 0111
@
white square
64
n/a

100 0000
n/a
A
_
65
95
-30
100 0001
101 1111
B
/
66
47
19
100 0010
010 1111
C
^
67
94
-27
100 0011
101 1110
D
unknown
68
n/a

100 0100
n/a
E
]
69
93
-24
100 0101
101 1101
F
.
70
46
24
100 0110
010 1110
G
Yen
71
n/a

100 0111
n/a
H
unknown
72
n/a

100 1000
n/a
I
[
73
91
-18
100 1001
101 1011
J
-
74
45
29
100 1010
010 1101
K
z
75
122
-47
100 1011
111 1010
L
unknown
76
n/a

100 1100
n/a
M
Y
77
89
-12
100 1101
101 1001
N
unknown
78
n/a

100 1110
n/a
O
g
79
103
-24
100 1111
110 0111
P
X
80
88
-8
101 0000
101 1000
Q
W
81
87
-6
101 0001
101 0111
R
+
82
43
39
101 0010
010 1011
S
unknown
83
n/a

101 0011
n/a
T
V
84
86
-2
101 0100
101 0110
U
unknown
85
n/a

101 0101
n/a
V
asterisk
86
42
44
101 0110
010 1010
W
T
87
84
3
101 0111
101 0100
X
unknown
88
n/a

101 1000
n/a
Y
S
89
83
6
101 1001
101 0011
Y
S
89
83
6
101 1001
101 0011
Z
)
90
41
49
101 1010
010 1001
[
R
91
82
9
101 1011
101 0010
[
R
91
82
9
101 1011
101 0010
\
unknown
92
n/a

101 1100
n/a
]
Q
93
81
12
101 1101
101 0001
^
(
94
40
54
101 1110
010 1000
_
P
95
80
15
101 1111
101 0000
`
white square
96
n/a

110 0000
n/a
a
O
97
79
18
110 0001
100 1111
a
O
97
79
18
110 0001
100 1111
b
'
98
39
59
110 0010
010 0111
c
N
99
78
21
110 0011
100 1110
d
space
100
32
68
110 0100
010 0000
d
unknown
100
n/a

110 0100
n/a
e
M
101
77
24
110 0101
100 1101
f
&
102
38
64
110 0110
010 0110
g
L
103
76
27
110 0111
100 1100
g
L
103
76
27
110 0111
100 1100
g
L
103
76
27
110 0111
100 1100
h
white square
104
n/a

110 1000
n/a
i
K
105
75
30
110 1001
100 1011
j
unknown
106
n/a

110 1010
n/a
k
J
107
74
33
110 1011
100 1010
l
unknown
108
n/a

110 1100
n/a
m
I
109
105
4
110 1101
110 1001
m
I
109
105
4
110 1101
110 1001
n
$
110
36
74
110 1110
010 0100
o
H
111
72
39
110 1111
100 1000
o
H
111
72
39
110 1111
100 1000
o
H
111
72
39
110 1111
100 1000
p
white square
112
n/a

111 0000
n/a
q
G
113
71
42
111 0001
100 0111
r
#
114
35
79
111 0010
010 0011
s
F
115
102
13
111 0011
110 0110
t
unknown
116
n/a

111 0100
n/a
u
E
117
69
48
111 0101
100 0101
u
E
117
69
48
111 0101
100 0101
v
unknown
118
n/a

111 0110
n/a
w
D
119
68
51
111 0111
100 0100
x
unknown
120
n/a

111 1000
n/a
y
C
121
67
54
111 1001
100 0011
y
C
121
67
54
111 1001
100 0011
z
!
122
33
89
111 1010
010 0001
z
!
122
33
89
111 1010
010 0001
{
B
123
66
57
111 1011
100 0010

I included the "HELLO CHRIS" experiment. It would seem that your serlcd is at least somewhat predictable and consistent (except for the h thing).

The whole thing in Excel format here.

A picture says more than a thousand numbers:

result_vs_sent_ctc_ascii.gif

Think away the "outlyers" (that are probably a result of you not reading your own handwriting correctly) and you get a very clear correlation between input and output. Let's see.

In,  Out, diff
33, 111,  -78
35, 110,  -75
37, 109,  -73
...
121, 67,   54
123, 66,   57

Odd numbers in, high numbers out.

In,  Out, diff
34,  55,  -21
36,  ?
38,  54,  -16
40,  ?

Even numbers in, lower numbers out. Every other even number results in an unknown.

I have not cracked this yet, but at least there is now proof of system in the chaos. Those outlyers can now be cleaned up. And hopefully (tomorrow) I will be able to get a conversion formula. And maybe that formula will explain what we're doing wrong and how to correct that.

Extrapolation tells me that the magical 124 can be had by sending 7 or 9. Excel sheet updated.

8ik

Not only did I confirm that indeed I used a lowercase "h" in the "hello" and it came up "H    "... But I also ran a for/next loop from 0 to 123 (124 being that magic "command number". I included a full one second pause so I could see things come up and again, I got gibberish! As it counted through the loop I still got a bunch of arrows, white blocks, funny symbols and an occasional letter -nothing more. And yes, using the debug, I can confirm my picaxe is indeed spitting out the numbers I asked for.

Here is my letter to sparkfun, by the way... I tried to "catch more flys with honey" and kiss their ass a little bit to see if I could get them to spend a little more time on me: (This was the second email I sent)

Well, I did some digging and I think I have found the problem. It seems that it is not a baudrate issue but rather that the picaxe does not include a start bit in it's serial command. I gotta admit this sorta sucks because I was looking forward to using this nice black w/ white lettering unit instead of the crappy green picaxe one. *Sigh* At any rate, I will still take any advice you have, or maybe you can let me know your return process. If indeed I am right, it would probably be cool to put a note on your site that these units won't work with a picaxe.

I guess I shouldn't complain, you guys have been a dream to deal with, with all my orders shipped wicked fast and all getting to me in just a couple days. --You even gave me a discount on some sharp sensors once when I smoked 4 of them at once. Just let me know how to get this one back to you and I guess I'll live with the green display. --I wish you stocked it by the way, I would prefer to order from you guys.


Thanks
Chris the Carpenter

If this is indeed a translation problem,

(h to H, e to nothingness), I would love to take a crack at cracking it. That's why I were so interested in the results of the "33 to 123" test. If we can work out a table of mangled ascii, we might be able to reverse engineer the bug.

if (interested) readon:

Like when all upper case chars are translated to lower case: we'd know something is wrong with bit 5.

Difficulty is that "unprintable characters" are expected to get mangled. The first characters in the table (0 through 31) are such buggers. Number 32 is a space. You already avoided sending 124 (which is aactually a "vertical bar")because it is supposed to be a control character.

However, the hypothesis is that code gets mangled before the LCD gets a chance to interpret them. So we might as well send the whole bunch and let the chips fall (fail?) were they may. And vice versa: we may be sending a prefectly nice and  upstanding piece of ascii like "e" (101) and it might get magled into something really special and weird, like a control char, or a backspace, or an "end of transmission". Then, all bets are off from that point on. That's why I suggest to scan a small region of the table at the time, say blocks of 16, until you get back interpretable data. Reset you LCD in between blocks. Reduce blocks' sizes when it still spews out (mostly) nonsens. Increase when you're feeling lucky.

Still assuming that we're chasing that magic retranslation table, with good reason...

else rts:

good luck!

endif

I think your LCD is probably OK. I say this because you are getting something on the display. At the risk of telling you something that you already know, your problem is most likely the serial link parameters. I had similar symptoms when working with acoustic couplers and teletext based bulletin boards a couple of decades ago.

Can you reset the LCD to the factory settings? It could be that it has interpreted some string of bits as a command to reconfigure itself.

If that doesn't work, or isn't possible then try changing the parity flag and the number of stop bits (0, 1 and 2 are usually possible). That's six different tests.

If you get the same number of characters output as you input (give or take one or two, independent of the number of characters that you sent) then I think the baud rate may be OK - ie one character out => one character in.

A final thing to check may be the serial cable. Are the pins wired correctly? Are all the joints good? Are you getting an intermittent connection? Etc.

I'd still try driving the LCD from a PC, or using the PicAxe to drive a PC. A binary chop of the problem would tell you which end to focus on.

Mike

First, to get the 9600 baud, I am using a 8hz external resonator with a setfreq em8.

If I simply use this, I get one capital "H" with 4 blank spaces after it:

setfreq em8

main:

serout 7,N9600_8,("hello")

pause 10

end

I have tried T9600_8 --no go

I have tried to send a number instead of letters -no go

I still can't figure out the "<control>k" crap, but I can't even seem to send a simple 124 without the display changing --It is my belief that sending 124 should not affect the screen at all unless it is followed by a command. I.e. it is just a heads-up that a command is coming.

Here is what SparkFun said:

The serial LCDs use 8,N,1 serial as stated in the datasheets. You should be able to configure the PICAxe to 8N1 as the PICAxe is just a PIC microcontroller with a BASIC interpreter. Also, there is a backpack on the serial LCDs that contains a PIC, so modifying that code will also work.

I can't provide support for using PICAxe software as we are only a reseller, but it seems you should be able to configure the PICAxe to output a different serial payload.
 

 

I am stumped as to why Sparkfun did not give you any more info or help. Did you give them the same quality (specific) questions we usually to get from you?

And I am stumped as to why "hello" gets translayered into "H    ". Did you indeed use a lowercase "h" in your code? I can understand a system that only interprets the first character in a string, but here the system has changed it. And why into the upper case of the input? Would bit #5 not make it through the line? Upper case characters are exactly 2^5=32 places higher in the ascii table. Would a bitwise inversion (hi=lo vv) cause such mayhem?

Would you please check if the Upper Case H is a coincidence? I suggest the following code:

#picaxe40x1
setfreq em8
 
' all the ascii codes (decimal) from bang! to tilde~
for b1 = 33 to 126
  serout 7,N9600_8,(b1)
  debug
  pause 3000
next b1

Change the pause to anything that is slow enough for you to read bot the LCD and the debug screen. If these two serial actions even tolerate each other.

Rik

There's no point asking sales clerks engineering questions. It's like asking a pineapple how to make a bloody mary. Now that you've been nice to them I'd suggest asking for a relacement just in case you've accidently got a faulty unit. At this point we're not 100% certain that it's not a fault in the display.

Have you tried driving the LCD from the serial port on your PC and a terminal emulator? This should be much easier and prove the LCD is OK.

Mike

Yellow Card

Mike