树莓派串口通信传数据的问题

JosephLiang 2021-03-31710 次点击
想请教一下各位大佬~我在做一个智能小车的项目用树莓派作上位机,Arduino作下位机,树莓派识别出目标的位置然后发送x,y,th三个数据给Arduino让arduino控制小车运动。期望是让树莓派对应arduino的一个loop只发一组数据(即一组xyth),但实际上树莓派传送数据一直停留在arduino的第一个loop中:

################树莓派#############
command = 0

while command = 0:
command = x + " " + y + "th" #x,y,th为目标检测代码识别得到的值,已转换为str。
command = command.encode()
serial.write(command)
command = 0

########### arduino #########
void loop()
{‌
while (Serial.available() > 0 && comdata.length() < 9)
{‌
delay(15); ///确保有足够时间接受完整数据!
comdata += char(Serial.read());
mark = 1;
}

if(mark == 1)
{‌ 运动部分}
mark = 0;
}
这是我自己试的代码,大概知道错误但不知道怎么写将它改成周期性传输数据=。=
有哪位大佬能稍微指导一下吗?
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。




› 相关内容关注微信公众号