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);
}