Picaxe 20X2 putting out strange numbers. Need help converting if possible.

Greyling

New Member
Hi I am using a 20X2 and trying to pass numbers out the serial port using serout to a 20M2 using serin. When I view the numbers with the terminal program they are correct. BUT when I use another terminal program like CoolTerm or the Arduino serial terminal program, the numbers are all wrong. This is a sample of the output.

20X2 - Numbers out to term prog:
1 = 127
2 = 63
3 = 126
4 = 31
5 = 125
6 = 63
7 = 127
8 = 15

What I want to see is this:
1 = 1
2 = 2
3 = 3
4 = 4
etc...

Can someone shed some light on why I am not getting the correct numbers? I cant seem to make sense of this. Thanks!
 

westaust55

Moderator
It may also be helpful if you post your code so folks can see what format the values are being sent in.

Are the values straight binary or ASCII encoded for each digit?

Dlso, do you have the CoolTerm and other terminal programs set to the same baud rate, parity and stop bits?
 

Greyling

New Member
Yes, I believe the baud and stop/parity bits are correct, The term prog displays the digits normally (no funny characters)....the 20X2 code part is this:

pause 200 '<---- start of loop

if pinC.0=1 then
serout B.3, N4800, (1)

if pinC.1=1 then
serout B.3, N4800 (2)

if pinC.2=1 then
serout B.3, N4800 (3)

if pinC.3=1 then
serout B.3, N4800 (4)

if pinC.4=1 then
serout B.3, N4800 (5)

if pinC.5=1 then
serout B.3, N4800 (6)

if pinC.6=1 then
serout B.3, N4800 (7)

if pinC.7=1 then
serout B.3, N4800 (8)

Then it goes back to loop
------------------------------------------
the 20M2 code is basically:

serin (3000), C.7, N4800, (b0)
high B.1
pause 200
low B.1
serout B.4, N4800, (b0)

Then loop back to start over.
I have tried using (#b0) as well as (b0) but the digitl still are not correct.
Any ideas?
 

inglewoodpete

Senior Member
WA55 has alluded to several possibilities that could be causing your problem.

One further possibility is that your data polarity is inverted. Ie data line is idling low when the receiver is expecting it to be idle high. Have a close read of the SerOut command description.
 

Greyling

New Member
I did read the serout section and as far as I can tell all is OK.

The numbers I am getting are wrong but they ARE consistant. For instance
1 = 127 Always, it never deviates at all
2 = 63 Always, never changes
3 = 126 always
4 = 31 Always
5 = 125 etc...
6 = 62
7 = 124
8 = 15
These number could run all day and they never change so I do not think it is baud rate or polarity related.
 

hippy

Technical Support
Staff member
It is possible there are multiple issues here; corrupt characters because no qualifiers are used, sending non-printable binary data, signal polarity or baud rate issues, not clear where the incorrect data is from; the sending PICAXE or repeater PICAXE.

Start with a single PICAXE sending fixed byte out every second and doing nothing else. Check that can be received correctly by everything.
 

rossko57

Senior Member
Revisit the inverted polarity data idea, that would give consistent (wrong) answers. Simply tested by replacing N4800 with T4800, rather than guessed at.
 

westaust55

Moderator
I think IWP has hit the "nail" on the proverbial head.


consider normal RS232 and sending the value %00000011

start = 0, LSB=1, 1, 0,0,0,0,0,MSB=0,Stop = 1, start = 0, LSB=1, 1, 0,0,0,0,0,MSB=0,Stop = 1, etc (red bits equate to %00000011 = 3decimal)

when inverted we see:

stop=1, Start=0,LBS = 0,1,1,1,1,1,1, MSB=0, Stop1, etc
keeping in mind LSB first so with the blue bits, we have the byte now as %01111110 = 126decimal

sorry tried some ASCII art but too far out of alignment

EDIT: okay the below and attached may diagram may clarify

RS-232 Normal vs Inverted.jpgRS-232 Normal vs Inverted.jpg
 

Attachments

Last edited:

BESQUEUT

Senior Member
I agree with brillant W55 analysis.
Plus :
receive code is very slow. It will lost a lot of bytes...
If only one pin is on, that is not a problem since the same byte is send many times.
But what if more than one pin is on at the same time ?

Please, publish whole code, not only extracts...
 

westaust55

Moderator
If only one pin is on, that is not a problem since the same byte is send many times.
But what if more than one pin is on at the same time ?
..
That is another consideration altogether.

Since the OP is monitoring the entire port, if there is any prospect of multiple input signals high at once, then read all the pins st once with
B0 = pinsC
And send that code the the second PICAXE
The second PICAXE could receive into B0 and then check every bit and determine what is to happen for all cases.
 

Greyling

New Member
HOLY COW, you guys ARE GOOD!!! Thank you ALL for the help/suggestions. It turned out it WAS the T--- instead of the N--- baud setting. The numbers in byte form were backwards.
I am SO impressed you guys could figure that out given my 'Less than optimal' description of the problem (and lack of complete code listing). I have learned SO much from this example. I now understand alot of things that I did not before. This project will eventually become a burglar alarm and Westaust55's idea of reading all pins at once is going to help A LOT. Besqueut's idea about slow code and 'same byte many times' got me to look at and solve other probs I had with the Arduino and understanding the flow better. I dont want to make this post too long so Thanks again to PETE, HIPPY, ROSSKO57, West55 and anyone else I missed. This IS the best help forum I have ever seen. You guys are the greatest!
 
Top