arduino 串口发送和接受的数据不一样

程序如下:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
long t = 0;
void loop() {
// put your main code here, to run repeatedly:
if( Serial.available())
{ t = Serial.read();};
Serial.println(t);
delay(2000);
}
实际使用arduino的串口监视助手发送100 返回48

第1个回答  2018-04-24
你这里,t是长整形,串口通信用的是字符串,所以你的整数在那边会给出对应的ASCII码的值,你把t改成char类型的试试,如果不行你再上个图。本回答被网友采纳