【arduino】--PC串口读取serial1的值,为何都是乱码?
arduino吧
全部回复
仅看楼主
level 7
我的硬件是mega2560的 使用port1的18 19针脚连接至PC的com口,电脑的的串口调试软件能接受到乱码的数据,而且程序里的灯并未循环闪烁。
#define Led 13
void blink88();
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
pinMode(Led,OUTPUT);
}
void loop() {
if(Serial.available()>0){
char ch=Serial.read();
if (ch=='0'){
blink88();
int date=99;
Serial1.print(date,BIN);
//Serial.print("00");
}
}
}
void blink88(){
digitalWrite(Led,HIGH);
delay(1000);
digitalWrite(Led,LOW);
delay(1000);
}
2016年03月04日 02点03分 1
level 7
晕 仔细想了一下,还是C语言没学好,我加了判断的前提,是不是闪得太快了,LOOP执行了一次没看到。 为何发给电脑的数据是乱码的呢?
2016年03月04日 03点03分 2
level 9
你用什么看的,hex还是ASCII
2016年03月04日 06点03分 3
十六进制和非十六进制都看了 好像两个编码有区别?IDE自带的串口调试和其他的串口调试编码不一样?
2016年03月04日 07点03分
level 7
如此的乱码 IDE界面发送的字符0,到serial1 再发给电脑串口就卵样了。。
2016年03月04日 07点03分 4
char a='0' 发给电脑后是接收到A9 D3 D2 52 24 00 十六进制的
2016年03月04日 07点03分
level 9
你直接只用串口0,不用串口1试一试,程序没问题,com3经过电平转换了吗?
2016年03月04日 17点03分 5
level 12
你需要TTL转RS232
2016年03月04日 23点03分 7
哦原来这样啊,那我试试啊,我这直接接RS232转串口的
2016年03月05日 01点03分
level 7
已经实现了,在serial写数据到serial1口再转到电脑,电脑的com口需要TTL转换才可以。arduino上手就是快啊,多谢楼上几位大神指点。
2016年03月05日 03点03分 8
level 7
新问题来了。。。 想从电脑Com3发送字符串数据“hello"到serail1,再由serial1转给serial。单每次都是读一个字节。
2016年03月05日 04点03分 9
level 1
arduino串口接收数据乱码:
8楼正解,Arduino串口出来的数据,无论是物理的串口还是虚拟串口,数据格式是TTL的,不是RS232.
2018年08月06日 15点08分 10
1