Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用pyserial在arduino和python之间进行通信_Python_Arduino_Pyserial - Fatal编程技术网

无法使用pyserial在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

我已经开始了一个关于arduino的项目,我要求它与python进行通信。我通过web找到了一个关于arduino python串行通信的示例代码,当输入1时,它会点亮LED。 python和arduino代码都在工作,但LED没有亮起。 董事会运作正常,因为我尝试了其他基本示例

Arduino代码:

Python代码:

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);
     }
   }