The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
[font="calibri;"]Has anyone had any experience using a Netduino Plus to read range data from a MaxBotix LV-MaxSonar-EZ3 sonar through a serial port? I’m having trouble making sense of the data it’s sending.[/font]
[font="calibri;"]I’m using Visual C# 2010 with the .NET Micro Framework 4.2, and have flashed the Netduino Plus to use version 4.2. My goal is to use this sonar to read the range to a target/obstacle, and then use the range to decide whether to take some other action (e.g. to stop driving, but that’s for later). According to the spec sheet, the LV-EZ3 operates at 9600 baud; every 49 ms it transmits the sequence RxyzCr, where R is literally ASCII R, xyz is a sequence of 3 ASCII character digits indicating the range to target (in inches up to 255), and Cr is ASCII 13 carriage return. The LV-EZ3 just starts transmitting after power up; no other control required. Transmitting the sequence is supposed to take 4.7ms.[/font]
[font="calibri;"]I can initialize, open, and close the serial port from the LV-EZ3 to the Netduino Plus with no problem, and after looking through the serial examples on the forum, I’m able to read and Debug.Print the data coming in. The problem I’m running into is making sense of the data.[/font]
[font="calibri;"]Just sending the data to the output window with Debug.Print (after converting each byte to a string), the byte sequence looks like 43, 6, 178, 89, 30, 43…repeating next time through. 43 and 6 are always in sequence, the other numbers vary—which makes sense if they are somehow indicating range. Looking at an ASCII table, though, none of those values make sense.[/font]
[font="calibri;"]The second thing that’s odd is that I seem to get a varying number of bytes. The sonar is supposed to send 5 bytes. By definition, if the “Data Received” event handler is raised, there ought to be data. But, I check for it just in case, and sometimes there isn’t any. The first time the event is raised, the handler always finds 6 bytes in the buffer. After that, it varies--sometimes, there are 4 bytes; sometimes, 9 bytes. (I’m doing the Debug.Print from inside the Data_Received event handler. I’ve tried discarding the buffer at the end of the handler to ensure the next read is clean.) I’m probably doing something silly, but I’m at a loss about where to look next.[/font]
[font="calibri;"]I had thought that perhaps I needed to run the LV-EZ3 through a 232 to TTL converter in order to invert the signals. So, I wired up a PRT-0449 SMD shifter, and the green Tx light indicates the sonar banging away, but it no longer triggers the SerialDataReceived event on the Netduino. I’m officially stumped.[/font]
[font="arial, sans-serif;font-size:12.800000190734863px;"]I saw you forum question looking for help regarding the MB1030 ultrasonic sensor.[/font]
[font="arial, sans-serif;font-size:12.800000190734863px;"]You state: [/font][color=#0000ff;][font="calibri;"]Just sending the data to the output window with Debug.Print (after converting each byte to a string), the byte sequence looks like 43, 6, 178, 89, 30, 43…repeating next time through. 43 and 6 are always in sequence, the other numbers vary—which makes sense if they are somehow indicating range.[/color][/font]
[font="arial, sans-serif;font-size:13px;"]Has the sensor's full serial port setting been verified? You stated previously the sensor has a baud of 9600, but you did not make mention of the remaining settings. These must be configured for proper operation. The sensor has 8 data bits, 1 stop bit, and no parity.[/font]
[font="arial, sans-serif;font-size:13px;"]You also stated: [/font][color=#0000ff;][font="calibri;"]The second thing that’s odd is that I seem to get a varying number of bytes. The sonar is supposed to send 5 bytes.[/color][/font]
[font="arial, sans-serif;font-size:13px;"]The sensor only outputs 5 bytes, and does not change this value. If you have the ability, you may want to add in your programming that there is no flow control. If there is a flow control the device reading the sensors output will keep all the range readings on 1 line. When flow control is turned off, each range reading will get its own line of text.[/font]
[font="arial, sans-serif;font-size:13px;"]You may wish to verify the sensor's connected properly to the computer by reading through our tutorial named "Using the MaxSonar TX Output (Pin 5)" (http://maxbotix.com/articles/034.htm). If the sensor is connected to a DB9 port on the back of a computer, software such as HyperTerminal can be used to read the sensor's output to verify the sensor operation. If HyperTerminal is configured in the manner described in the sensor datasheet and the sensor does not output data correctly, the sensor may be faulty. If this is the case please email me directly so we can initiate the RMA process for you.[/font]
[font="arial, sans-serif;font-size:13px;"]If additional support is needed, please don't hesitate to email me directly at thomas@maxbotix.com[/font]
[font="arial, sans-serif;font-size:13px;"]Please let me know if you have any questions.[/font]
[font="arial, helvetica, sans-serif;"]I am using 8 data bits, 1 stop bit, no parity. On the Netduino, I'm using the COM port that doesn't have flow control (although I tried the other one; no difference). [/font]
[font="arial, helvetica, sans-serif;"]I am able to read range data using the analog pin on the sonar; the received values make sense. I haven't tried using PWM.[/font]
[font="arial, helvetica, sans-serif;"]What I can't figure out is why I'm not getting 5 bytes systematically, and I never see the "R" that should be the first byte sent. I keep thinking I must be inverting some signal, or reading something backwards. I've read everything I can find on the Maxbotics website about the LV-Maxsonar line (that's how I decided on the EZ3), but I may still be missing something obvious.[/font]
[font="arial, helvetica, sans-serif;"]Looking very closely at the sonar (big magnifying glass), it does appear that the "X" in "TX" printed next to the transmit pin might have a connection to the circuit line above it (which I think is the 5V line). I soldered a header to the sonar, so part of troubleshooting was to ensure I hadn't gotten solder where it didn't belong. But, I don't see the lettering connect to anything else, so that's a stretch.[/font]
[font="arial, helvetica, sans-serif;"]Looks like my next purchase will need to be a DB-9 to USB converter. To this point, the sonar has only been connected to the Netduino; the Netduino is connected to the computer via USB. I'm taking the serial values that the Netduino thinks it's getting and sending those to the Visual Studio output window.[/font]
[font="arial, sans-serif;font-size:13px;"]Thanks for the response. You stated: [/font]What I can't figure out is why I'm not getting 5 bytes systematically, and I never see the "R" that should be the first byte sent. I keep thinking I must be inverting some signal, or reading something backwards.
Do you have the ability to read the TX output directly into a computer's DB9 with a software such as HyperTerminal or HyperSerialPort? This can diagnose if there is a sensor operational issue or if it is a coding issue. I think for best support, you may want to email me directly at thomas@maxbotix.com. This can help expedite the technical support.
Once we have the issue resolved, is it acceptable with you to post the resolution on this forum for others to see and reference?
[font="arial, sans-serif;font-size:13px;"]Please let me know if you have any questions.[/font]
Finally had the chance to dig out my old computer with a physical serial port. Using Realterm, and plugging the sonar directly into the DB-9 serial port, the sonar is happily banging away with RxyzCR at a rate of 9600 baud. So, that tells me sensor is working. That leaves my coding or the connections to the Netduino Plus (not really a surprise). I'll email directly, and any solution we find should absolutely be posted for others to use.
I keep thinking about whether there's a signal issue between the Maxbotics sonar and the Netduino Plus. The Netduino doesn't use RS-232 signal levels. I did try using a 232 to TTL converter, but I could have easily messed that up. At this point, I could use the sonar's analog mode to get the data I need, but it's such a simple interface that it seems like the perfect tool to figure out where I'm going wrong with my serial coding and the Micro Framework. My project will require reading serial data from other sources that aren't as handy in providing an analog or PWM alternative.
I should note, for others, that I wrote some rough code to check for noisy data, as suggested by your website. The sonar readings are very stable (within 10%).
Progress. I thought again about the 232-to-TTL shifter (using a Sparkfun PRT-0449), and I finally realized I had wired it backwards in my earlier, failed attempt. Since the sonar is operating at RS-232 level, then for the purpose of the shifter, the sonar is the computer/DTE. The Netuduino operates at TTL, so that makes it the modem/DCE. Tx from the sonar to the DB-9 Tx pin; Tx from the shifter to the Netduino Rx pin; one null modem cable now operating.
I am now getting valid decimal bytes--82 for R, three 2-digit decimal numbers representing the 3 digits of the range, and decimal 13 for CR. I'm still not getting 5 bytes consistently, but since Realterm read it fine, that tells me I'm doing something wrong in the code.
hi please can i get the library and code u used. I'm basically building an obstacle detector. i have connected the GND to the GND on the microcontroller and +5v to +5 on the netduino and 2 to D2. pls help.
I am in the middle of moving, so it will take me a bit to find the code. However, the main issue turned out to be that I had wired the RS-232 to TTL converter incorrectly (see above). You can't just connect the Netduino directly to the sonar for serial data transfer.
For the serial port, I had the problem mostly solved by just reading 5 bytes and discarding them if it didn't read correctly, but then my Create developed a problem sending serial data, so I switched to the sonar analog output--I haven't had a chance to get back to the serial transfer yet. Important to remember that the Netduino analog input will NOT tolerate 5V--you have to use 3.3V.