1

I have an Arduino Mega with an MaxBotix (MB7066) sonar attached, the sonar has the ability to send serial data with it's reading. It uses a asynchronous RS232 format, except the voltages are 0-Vcc. The output should be a capital "R" (ASCII), followed by four digits(ASCII) and a carriage return (ASCII 13). The baud rate is 9600, 8 bits, no parity with one stop bit. What I get from the device is as follows: (sonarSerial.read() while sonarSerial.available())

43
192
6
6
179
89
30
0

What do I have to get to the information? Or is my sensor just retuning garbage? Please see the code below:

#include <SoftwareSerial.h>
#define pin1 3
#define pin2 5 //pwm
#define pin3 6 //analog
#define pin4 10 //RX for sonar, TX for arduino
#define pin5 11 //TX for sonar, RX for arduino
SoftwareSerial sonarPort(pin5,pin4);
void setup(){
 Serial.begin (9600); 
 pinMode(pin1, OUTPUT);
 pinMode(pin4, OUTPUT);
 pinMode(pin5, INPUT);
 sonarPort.begin(9600);
}
void loop(){
 digitalWrite(pin1, HIGH);
 digitalWrite(pin4, LOW);
 digitalWrite(pin4, HIGH);
 delayMicroseconds(20);
 digitalWrite(pin4, LOW); 
 long pulse = pulseIn(pin2, HIGH)/58;
 Serial.print("PM Result: ");
 Serial.println(pulse); 
 String buffer = "";
 sonarPort.listen();
 while(sonarPort.available() > 0){
 int inByte = sonarPort.read();
 buffer += inByte; buffer += " ";
 if(!sonarPort.available()){ 
 Serial.print("Serial result: "); 
 Serial.println(buffer);
 }
 }
 delay(500);
}
asked Jan 12, 2015 at 11:14
1
  • Please provide specific model of the sensor you are using. Commented Jan 12, 2015 at 21:17

2 Answers 2

1

I contacted MaxBotix with the problem and for my surprise their technical support is really great:

The Arduino is set up to natively read TTL serial data.The MB7066 outputs its serial data in the RS232 format. Do not worry; this problem can easily be fixed. You can use an inverter such as the MAX232. You can also follow the following tutorial to make your own https://github.com/simonmonk/raspirobotboard/wiki/Rangefinder-Adapter.

Another option would be to test using this code section SoftwareSerial sonarSerial(rxPin, txPin, true); //define serial port for recieving data, output from maxSonar is inverted requiring true to be set.

answered Jan 13, 2015 at 9:17
0

In the bitstream of your ASCII data the pattern for "R" (01010010b) does never occur.
So obviously something is wrong in your system and/or setup. Have you already considered the information given here http://www.maxbotix.com/articles/034.htm?

I would connect the sensor to a PC to check whether it's working correctly using a standard terminal software.

answered Jan 12, 2015 at 12:19
1
  • I don't have the cable yet so no, I have not checked, will later post my code to remove the possibility of a bad setup. Commented Jan 12, 2015 at 14:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.