I'm sending an integer from python using pySerial.
import serial
ser = serial.Serial('/dev/cu.usbmodem1421', 9600);
ser.write(b'5');
When i compile,the receiver LED on arduino blinks.However I want to cross check if the integer is received by arduino. I cannot use Serial.println() because the port is busy. I cannot run serial monitor first on arduino and then run the python script because the port is busy. How can i achieve this?
答案 0 :(得分:0)
You can upload an arduino program that listens for that specific integer and only blinks the light if it gets that int.
答案 1 :(得分:0)
您可以使用其他一些代码收听Arduino的回复。
import serial
ser = serial.Serial('/dev/cu.usbmodem1421', 9600); # timeout after a second
while ser.isOpen():
try:
ser.write(b'5');
while not ser.inWaiting(): # wait till something's received
pass
print(str(ser.read(), encoding='ascii')) #decode and print
except KeyboardInterrupt: # close the port with ctrl+c
ser.close()
使用Serial.print()
打印Arduino收到的串行端口,Python代码也在这里收听。