Pololu USB-to-serial adapter to read MaxSonar-EZ1

Hi all, I’m trying to use the Pololu USB-to-serial adapter to read ranges from the MaxSonar-EZ1, but I’m having an interesting problem. When I connect Tx from the sonar straight to my com port I see proper range data (in hyper terminal), for example the code “R006” on a new line when I have my hand right against the sensor.

When I try connecting Tx from the sonar to Rx on the USB to Serial adapter, I see data, but in nonsensical characters. They do change as I move things in front of the sonar, and a five character string repeats when I have my hand against the sensor, but it’s all different characters (none of which starts a new line). I doubt they’ll help diagnose this problem, but the characters are a plus sign, a spade (like the ace of), the number 6, a capital V, and a space. Looking at these files in notepad, all but the V show up as the “I can’t display this character” box.

Any thoughts on what I’m doing wrong?

Changing the communication settings on the port doesn’t seem to change things, and I suspect that the serial protocols on either side of the USB adapter are independent and auto-detected.

When I use the USB adapter I am powering the sonar from the bus voltage pin (as opposed to the separate regulated power supply I used when I tested it with a serial port) but I measure my bus voltage as 5.04V and the sonar only draws 2 mA typ. I doubt that it would work at all if this were a problem, but I suppose I should have tried powering it separately. It’s at work and I’m at home now.

Another possibility, do I need to invert the signal between the sonar and the adapter? I really don’t think I should need to, but I could see that giving me scrambled, but repeating characters.

Thanks for any help.


Here is what the EZ1 data sheet says (cut and paste):

TX – Delivers asynchronous serial with an RS232 format,
except voltages are 0-5V. 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, not inverted, with one stop bit.
Although the voltage of 0-5 V is outside the RS232
standard, most RS232 devices have sufficient margin
to read 0-5V serial data. If standard voltage level
RS232 is desired, invert, and connect an RS232
converter such as a MAX232.

I don’t have an EZ1, but I don’t think that the claim “not inverted” can be correct. I connect PIC processors directly to a PC port all the time (as do Basic Stamp users), and the protocol is “inverted serial, 0-5 volts”. The bits must be inverted for this scheme to work. It is easy to check: If the EZ1 outputs ~0 volts on TX when not transmitting a character,then goes high at the start of a character, the protocol is inverted serial. Check with an LED and series resistor.

If this is so, the EZ1 won’t work with the USB-serial adapter unless you invert the signal with a transistor (and then, perhaps not). If you figure it out, post it!

Good luck, Jim

Thanks for the insight. I’ve worked with PIC’s a lot in the past, but never sending serial from the PIC back to the PC. I didn’t think to try inverting the signal until after leaving work (I’m still kicking myself for leaving my breadboard there, but not enough so to go back in over the weekend). I wonder where you downloaded your copy of the manual from though, because the copy linked from Pololu does not say “non-inverted.” Also, Looking at the circuit schematic, the TX pin on the sonar has a pull down restor, so either the signal is normally low (inverted serial) or it’s wasting current all the time.

I’m still a little confused about one thing. I didn’t initially think to check if the signal needed to be inverted (which in hindsight TOTALLY make sense as to why I was getting repeating characters, just the wrong ones) because the sonar worked just fine connected directly to a serial port. Technically the levels aren’t to spec, but the highs and lows are still picked up as highs and lows, right?


There appear to be a couple of different datasheets on the EZ1 – some say not inverted, others don’t. The first one I saw did say “not inverted”, and the second didn’t. Confused me too! However, the clue comes from the final suggestion, “invert, and connect an RS232 converter such as a MAX232”. This means that the bits are inverted because normally you connect a uart output directly to the MAX232.

The resting state of the RS232 line is -8 to -15 volts, which then goes to +8 to +15 for the start bit. The “inverted serial” connection relies on the fact that most serial ports actually regard input voltages of less than about +2 volts to be negative, and greater than +2 volts to be positive.

So, the resting state of an inverted serial connection from a typical MPU is 0V, rising to +5 for the start bit. Uart output is the other way around. You should be fine if you put a simple transistor inverter between the EZ1 and the USB-serial.

Alternatively, you could put a 255x5 character lookup table into your program to convert the garbage characters into usuable ranges :wink:

Cheers, Jim

Thanks, inverting the logic with a transistor worked swell. I’m also now triggering it (holding the trigger pin low and bringing it high when I want to take a reading) with TTL characters from the usb-serial converter going through a second transistor inverter.