Raspberry Pi Pico 和错误消息“ImportError:没有名为“machine”的模块”
我正在我的 Raspberry Pi Pico 上运行以下眨眼程序。我正在使用 CircuitPython。
from machine import Pin
import time
led = Pin(13, Pin.OUT)
while True:
led(1)
time.sleep(1)
led(0)
time.sleep(1)
当我运行它时,它给出了这个错误:
Traceback (most recent call last):
File "code.py", line 1, in <module>
ImportError: no module named 'machine'
我试图查找是否需要下载库文件或有关机器模块的任何内容,但我没有找到任何内容。为什么找不到机器模块?
I am running the following blink program on my Raspberry Pi Pico. I am using CircuitPython.
from machine import Pin
import time
led = Pin(13, Pin.OUT)
while True:
led(1)
time.sleep(1)
led(0)
time.sleep(1)
When I run it though, it gives this error:
Traceback (most recent call last):
File "code.py", line 1, in <module>
ImportError: no module named 'machine'
I have tried to find if I need to download a library file or anything about the machine module, but I haven't found anything. Why can't it find the machine module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的代码适用于 MicroPython。 CircuitPython 是不同的。请参阅CircuitPython Digital In &出。
Your code is for MicroPython. CircuitPython is different. See CircuitPython Digital In & Out.
我遇到了同样的问题,搜索发现了这个问题。
我将 Thonny 中的解释器设置(在选项下)从本地 Python 3 更改为 MicroPython (Raspberry Pi Pico)。
I was having the same issue and a search found this question.
I changed the Interpreter setting in Thonny (under options) from Local Python 3 to MicroPython (Raspberry Pi Pico).
我认为您使用了不正确的 uf2 文件,因为在撰写本文时官方(稳定)版本尚未发布。
为了检查这一点,请在 MircoPython 的命令行中键入以下内容:
如果响应显示“Pico”而不是“Pico W”,则从 此处 并将其复制到您的 Pico W(USB 模式)。
I think you are using the incorrect uf2 file as the official (stable) version is not out as of writing this.
In order to check this, type the following in MircoPython's command line:
If the response shows "Pico" and not "Pico W" then copy the latest version from here and copy it onto your Pico W (in USB mode).
板载 LED
与原始 Raspberry Pi Pico 不同,Pico W 上的板载 LED 未连接到 RP2040 上的引脚,而是连接到
无线芯片上的 GPIO 引脚。 MicroPython 已进行相应修改。这意味着您现在可以执行以下操作:
甚至:
改变当前状态。但是,如果您现在查看 led 对象:
您还可以执行以下操作:
这将配置 led 对象,将其与板载 LED 关联并打开 LED。
注意
有关 Raspberry Pi Pico W 的完整详细信息,请参阅 Raspberry Pi Pico W 数据表。 WL_GPIO1 连接到
RT6154A 上的 PS/SYNC 引脚允许选择不同的操作模式,而 WL_GPIO2 可用于
监控USB VBUS。
The on-board LED
Unlike the original Raspberry Pi Pico, the on-board LED on Pico W is not connected to a pin on RP2040, but instead to a
GPIO pin on the wireless chip. MicroPython has been modified accordingly. This means that you can now do:
or even:
to change the current state. However, if you now look at the led object:
You can also do the following:
which will configure the led object, associate it with the on-board LED and turn the LED on.
NOTE
Full details of the Raspberry Pi Pico W can be found in the Raspberry Pi Pico W Datasheet. WL_GPIO1 is connected to
the PS/SYNC pin on the RT6154A to allow selection of different operating modes, while WL_GPIO2 can be used to
monitor USB VBUS.