Reading serial characters (output from sonar board)

dvd

New Member
I am trying to use the 14M2 to read the serial output provided by an LV maxsonar board. The data sheet for this module states that

The output is an ASCII capital “R”, followed by three ASCII character digits representing the range in inches up to a maximum of 255, followed by a carriage return (ASCII 13). The baud rate is 9600, 8 bits, no parity, with one stop bit
The full datasheet can be found here:

https://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf

I've tried reading in the input using the serin command on pin C.4 without success. The output always returns a fixed value and does not change. The latest try is attached below. The output of all variables is always 4.

I think I don't correctly understand the way the serin command (and its options) work. Any help or tips would be very welcome.

2017-08-22 20_45_50-PICAXE Editor 6.0.9.3.png
 

westaust55

Moderator
Sorry, but not a user of the logicator flow chart method so unsure of the intricacies of the flow chart syntax.

Noting that you have N9600_8 as the serin baud rate parameter, have you also set the frequency of the 14M2 to 8 MHz (the start-up default is 4 MHz).
Also as the maxsonar board sends in RS232 format, try changing that baud rate parameter to T9600_8.







By the way, did you receive the information you sought in relation to capacitors around voltage regulators? There was no reply to the many posts in that thread:
http://www.picaxeforum.co.uk/showthread.php?30154-5V-voltage-regulator-capacitor-values&p=312881#post312881
 

inglewoodpete

Senior Member
Noting that you have N9600_8 as the serin baud rate parameter, have you also set the frequency of the 14M2 to 8 MHz (the start-up default is 4 MHz).
Also as the maxsonar board sends in RS232 format, try changing that baud rate parameter to T9600_8.
Alternatively, if you are happy to run the 14M2 at its default speed (4MHz), you can use T9600_4 on the SerIn command.
 

hippy

Technical Support
Staff member
Blockly was not really intended to do advanced interfacing directly. That can however be done by using the BASIC block from under Advanced.

First; ensure there is a "Set varA to 0" block at the top of the program.

Then add a BASIC block which contains the three lines -

SetFreq M8
SerIn C.4, T9600_8, ("R"), #varA
SetFreq MDEFAULT

That should then read the distance into 'varA'
 

dvd

New Member
Hi all,

Thank you for the response. Based on your responses I came up with the following code, which seems to work. Using T9600_8 seems to give nonsense output. The manual also seems to indicate that N should be used for RS232:

When receiving RS232 level data using a simple resistor interface, use N (inverted) signals.
symbol varA = w0
symbol varB = w1
symbol varC = w2
symbol varD = w3
symbol varE = w4
symbol varX = w4

main:
setfreq m8
do
;apperently, one can read in the 4 values in one line
serin C.4, N9600_8, varA, varB, varC, varD, varE
;borrowed from this post: http://www.picaxeforum.co.uk/archive/index.php/t-22483.html
let varX = VarB - 48 * 10 + VarC - 48 * 10 + VarD - 48
debug
loop
stop
 

dvd

New Member
This is a very interesting approach. From your code, It seems like I can 'look for the R' and read in the characters that follow into a variable. I'll play around with that.
 

dvd

New Member
Thank you for your reply. I think I figured it out (see below) starting from your suggestion.

Yes, I read all the posts in the the other thread - and learned a lot about capacitors. I have put that project on hold but will return to it very soon (this week, fingers crossed). As I haven't been able to test the capacitor combinations suggested in the posts, I haven't replied yet. However, I bought a bunch of caps and will experiment soon.
 

westaust55

Moderator
Sorry, a mental "hiccup".
yes you are correct and I was aware that RS232 is inverted.
Just had a momentary confusion if thinking "T" (True/TTL) was for RS232 whereas iNverted is the correct requirement.
 
Top