Raspberry Pi Pico 和错误消息“ImportError:没有名为“machine”的模块”

发布于 2025-01-15 13:59:30 字数 664 浏览 4 评论 0原文

我正在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我只土不豪 2025-01-22 13:59:30

您的代码适用于 MicroPythonCircuitPython 是不同的。请参阅CircuitPython Digital In &出

from digitalio import DigitalInOut, Direction, Pull

led = DigitalInOut(board.LED)

Your code is for MicroPython. CircuitPython is different. See CircuitPython Digital In & Out.

from digitalio import DigitalInOut, Direction, Pull

led = DigitalInOut(board.LED)
不喜欢何必死缠烂打 2025-01-22 13:59:30

我遇到了同样的问题,搜索发现了这个问题。
我将 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).

古镇旧梦 2025-01-22 13:59:30

我认为您使用了不正确的 uf2 文件,因为在撰写本文时官方(稳定)版本尚未发布。
为了检查这一点,请在 MircoPython 的命令行中键入以下内容:

>>> import sys
>>> sys.implementation
(name='micropython', version=(1, 19, 1), _machine='Raspberry Pi Pico with RP2040', _mpy=4102)

如果响应显示“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:

>>> import sys
>>> sys.implementation
(name='micropython', version=(1, 19, 1), _machine='Raspberry Pi Pico with RP2040', _mpy=4102)

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).

冬天旳寂寞 2025-01-22 13:59:30

板载 LED
与原始 Raspberry Pi Pico 不同,Pico W 上的板载 LED 未连接到 RP2040 上的引脚,而是连接到
无线芯片上的 GPIO 引脚。 MicroPython 已进行相应修改。这意味着您现在可以执行以下操作:

导入机器 led = machine.Pin("LED", machine.Pin.OUT) led.off()
led.on()

甚至:

led.toggle()

改变当前状态。但是,如果您现在查看 led 对象:

LED 引脚(WL_GPIO0,模式=OUT)

<块引用>
<块引用>

您还可以执行以下操作:

led = machine.Pin("LED", machine.Pin.OUT, value=1)

这将配置 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:

import machine led = machine.Pin("LED", machine.Pin.OUT) led.off()
led.on()

or even:

led.toggle()

to change the current state. However, if you now look at the led object:

led Pin(WL_GPIO0, mode=OUT)

You can also do the following:

led = machine.Pin("LED", machine.Pin.OUT, value=1)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文