无法使用pyserial在arduino和python之间进行通信
我已经开始了一个关于arduino的项目,我要求它与python进行通信。我通过web找到了一个关于arduino python串行通信的示例代码,当输入1时,它会点亮LED。 python和arduino代码都在工作,但LED没有亮起。 董事会运作正常,因为我尝试了其他基本示例 Arduino代码: 我 Python代码:无法使用pyserial在arduino和python之间进行通信,python,arduino,pyserial,Python,Arduino,Pyserial,我已经开始了一个关于arduino的项目,我要求它与python进行通信。我通过web找到了一个关于arduino python串行通信的示例代码,当输入1时,它会点亮LED。 python和arduino代码都在工作,但LED没有亮起。 董事会运作正常,因为我尝试了其他基本示例 Arduino代码: 我 Python代码: import serial import time # Required to use delay functions arduinoSerialData = seri
import serial
import time # Required to use delay functions
arduinoSerialData = serial.Serial('/dev/ttyACM0', 9600) # Create Serial port object called arduinoSerialData
time.sleep(2) # wait for 2 secounds for the communication to get established
print ("Enter 1 to turn ON LED and 0 to turn OFF LED")
while 1: # Do this forever
var =input() # get input from user
var=var.encode()
arduinoSerialData.write(var)
试试这个
if(Serial.available() > 0)
{
if((char)Serial.read() == '1')
{
digitalWrite(12,HIGH);
delay(2000);
}
}
看看这个
if(Serial.available() > 0)
{
if((char)Serial.read() == '1')
{
digitalWrite(12,HIGH);
delay(2000);
}
}