我正在编写一个在Raspberry Pi 2模型B和Arduino UNO之间进行接口的代码,我无法通过将ser.readline()的输出与变量进行比较得到肯定的响应。下面是我的raspberry-pi代码的代码片段,其中“u”只是我发送给arduino让它解释的命令,我已经能够确认它能够成功地解释它。
while 1:
time.sleep(1)
ser.write(u.encode('utf-8'))
print('ACK sent')
res = ser.readline()
if res = 'ON':
print('Pass')
else:
print('Try again')
在Arduino上,我发送给ser.write(命令)的响应是
Serial.write("ON\n")
不管我用什么来比较这两个值,pi总是打印“再试一次”,即使当我打印res值时,它清楚地打印“on”。
我错过了什么?