我将这个传感器与arduino板一起使用。
在第2页,它描述了引脚5的串行输出。
http://www.maxbotix.com/documents/HRXL-MaxSonar-WR_Datasheet.pdf
输出是ASCII大写" R",后跟四个ASCII字符 数字表示以毫米为单位的范围,后跟一个运输 return(ASCII 13)。串行数据格式为9600波特,8个数据位,无奇偶校验, 有一个停止位(9600-8-N-1)。
这是我的arduino代码(不正确)。它只输出' 82'这是首都R.
void setup()
{
Serial.begin(9600);
}
void loop()
{
int data = Serial.read();
Serial.println(data);
delay (1000);
}
如何获得字符串的距离读数?
非常感谢
答案 0 :(得分:1)
您是否尝试过 Set result_of_translate = hybridShapeFactory1.AddNewEmptyTranslate()
result_of_translate = CreateTranslate(Kotfl, 0, 1)
方法?
你应该使用它like that:
readBytesUntil
您的数据已包含在byte DataToRead [6];
Serial.readBytesUntil(char(13), DataToRead, 6);
中(DataToRead
中的' R')
答案 1 :(得分:0)
在我阅读时,问题是: 您如何将字符的字节(ascii)表示形式转换为可读的字母数字字符,例如“ a”与97?
实际问题:Arduino将ascii字符转换为字符串。 为什么ppl会发布未回答问题的回复?
没有确切答案,但使用(char)进行转换会带您进入那里。
char inByte = 0;
inByte = (char)Serial.read(); // ascii 97 received
Serial.println((char)inByte); // => prints an 'a' without the quotes