arduino跑python,尝试在我的Arduino和stu上执行Python3.7.2中的代码

提前谢谢你。在

我会尽量简短。在

我有一个Arduino+IDE,有一个串行端口,工作正常。

我下载了python3.7.2、PySerial和VPython。

全部安装完毕。在

通过我的MacBook终端安装了PySerial。sudo easy_install pyserial

Password: Searching for pyserial

Best match: pyserial 3.4

Adding pyserial 3.4 to easy-install.pth file

我也通过终端安装了VPython。

^{pr2}$

当我在python3.7.2shell中输入help(“modules”)时,我得到了这个消息,它说PySerial是我拥有的一个模块。在Please wait a moment while I gather a list of all available modules... PySerial _thread getopt resource YoutubeARDTOPY

_threading_local getpass rlcompleter future _tkinter

我在Arduino上做了一个简单的代码,写入串口,验证并上传。它工作得很好。关闭了那个港口。在Python3.7.2上运行这段代码,希望这段代码能够获取发送到Arduinos串行端口的内容,并开始向Pythons串行端口发送。在import serial #Import Serial Library

arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600)

while (1==1):

if (arduinoSerialData.inWaiting()>0):

myData = arduinoSerialData.readline()

print (myData.decode())

但我收到这样的错误信息

==========重新启动:/Users/donaldlair/Documents/YoutubeARDTOPY.py==========Traceback (most recent call last):

File "/Users/donaldlair/Documents/YoutubeARDTOPY.py", line 3, in

arduinoSerialData = serial.Serial('/dev/cu.usbmodem14101', 9600)

AttributeError: module 'serial' has no attribute 'Serial'

所以我查看了我的dir(serial)文件夹,结果出来了(我被告知要这么做,仍然不知道为什么,但这可能有助于弄清楚。在>>> dir(serial)

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'abc', 'absolute_import', 'division', 'errors', 'generators', 'hooks', 'marshal', 'meta', 'model', 'nested_scopes', 'print_function', 'properties', 'request', 'test', 'unicode_literals', 'utilities', 'with_statement']

这些东西我都是第一次学的,所以如果你真的回答了我很感激的话,请你把它说得小一点,因为我有点文盲和初学者。在

谢谢你!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值