Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: paf on November 11, 2009, 09:10:07 AM

Title: Problems using LV-MaxSonar serial with Axon
Post by: paf on November 11, 2009, 09:10:07 AM
Can someone provide help with this problem?

I'm using a LV-MaxSonar-EZ3 connected to an Axon.  I have no problems using the analog output of the sonar, but wish to use the serial to obtain greater accuracy.  According to the datasheet from Maxbotix, the sonar sends a 'R' followed by the measurement in inches and then by the carriage return (ASCII 13).  When I connect the serial output of the sonar to the Axon, I do not get an 'R' or a CR.  Using this code:

int snr = 0;
while(1)
{
 snr=uart0GetByte();
 if (snr != -1)
 {
 rprintf("%d\r",snr);
};

I get:
43
103
102
100
121
(which is repeated)

I would expect to get an 82 (ASCII value of R) as the first value and a 13 (ASCII value of CR) as the last value.
Title: Re: Problems using LV-MaxSonar serial with Axon
Post by: hopslink on November 11, 2009, 10:00:08 AM
The datasheet for the sonar module shows that it's UART tx output is inverted in order to provide a logic level approximation to RS232. The UART on the Axon isn't expecting this and thus won't decode the data properly. Try to add an inverter between the two to rectify the situation.

It may be possible to fix this in code on the Axon but it is likely to be awkward since there may be data mangling issues due to missing (inverted) start/stop bits.
Title: Re: Problems using LV-MaxSonar serial with Axon
Post by: paf on November 11, 2009, 10:27:36 AM
Thanks for the advice.  However, I'm new to all of this.  Could you point me to some resources on how to add an inverter?

Thanks!
Title: Re: Problems using LV-MaxSonar serial with Axon
Post by: Admin on November 11, 2009, 03:32:22 PM
An inverter IC. Look it up, it'll take seconds to wire, really.

Also, you defined snr as an int but you're expecting a char value. :P
Title: Re: Problems using LV-MaxSonar serial with Axon
Post by: hopslink on November 11, 2009, 05:42:03 PM
The Wikipedia Inverter page >HERE< (http://en.wikipedia.org/wiki/Inverter_%28logic_gate%29) is quite good. As a suggestion for an IC have a look at (google) a datasheet for the 74HC04.

You should have no problems as there are only four connections to make - Input, output, power and ground. Input will be the Tx output from your sensor, output will go to your Axon Rx pin, power and ground will be those used on the Axon.