python - 在python中读取arduino串行连接

标签 python serial-port arduino

我正在尝试在 Ubuntu 计算机上使用 Python 连接到我的 Arduino。我尝试了这个例子: http://playground.arduino.cc/interfacing/python

但我总是得到:

>>> import serial
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/serial/serialutil.py", line 282, in __init__
  File "build/bdist.linux-x86_64/egg/serial/serialposix.py", line 289, in open
OSError: [Errno 2] No such file or directory: '/dev/tty.usbserial'
>>> 

我可以在草图中使用串行连接,没有任何问题。我还将我的用户添加到 tty 和 dialout 组中。

如何使用 Python 连接到我的 Arduino?

最佳答案

首先列出串行端口。我不确定 dev/tty.usbserial 是否正确。

您尝试在终端中执行 ls/dev/tty* ,也许您的 Arduino 板会弹出为 ttyACM0 或类似的内容(抱歉,没有使用过 Ubuntu)等一下)。

您还可以查看PySerial finding ports article (可能需要 PySerial 2.7 或更高版本)

关于python - 在python中读取arduino串行连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25703607/

相关文章:

linux - 如何在 Intel Galileo 上重置运行代码

python - 如何在多个文件之间共享Python库

python - Django 1.11 密码重置 token 的生成发生意外变化

python - 通过分组计算数据帧中值的差异

python - 从串口发送数据

c++ - 使用带有 qt c++ 的 mavlink 协议(protocol)从串口读取

python - 针对不同的任务、情感分析对预训练的西类牙 RoBERTa 模型进行微调

c# - 串行端口异步读取(非阻塞)+ 线程

c# - 如何从 C# 调用 Win32API SetCommTimeouts?

c++ - Arduino:中断昂贵的功能并恢复另一个