首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用Circuit Python时不将Raspberry Pico自动挂载为USB存储

如何在使用Circuit Python时不将Raspberry Pico自动挂载为USB存储
EN

Stack Overflow用户
提问于 2021-02-22 02:02:05
回答 3查看 940关注 0票数 3

我在Raspberry Pi Pico上使用Circuit Python为我提供了键盘快捷键的硬件按钮。我使用Circuit Python而不是MicroPython,因为它有USB_HID库。

我不希望Pico在插入时自动挂载为USB存储。我只想让它充当HID设备。我知道除了code.py之外,我还可以写一个boot.py脚本,但是我在网上找不到放什么东西会阻止它挂载为code.py设备的地方。我仍然希望它有时作为USB挂载(当按钮被按下/GPIO引脚被连接时),所以我仍然有一种方法来更改设备上的代码。

这个是可能的吗?而且,如果是这样的话,boot.py应该是什么样子的,只有当某个GPIO引脚连接时才安装?

EN

回答 3

Stack Overflow用户

发布于 2021-03-25 05:41:28

我最近遇到了一个需要做你正在寻找的同样的事情,在一个像样的兔子洞之后,我决定在这个时候不能这样做。

https://github.com/adafruit/circuitpython/issues/1015

看起来该请求是几年前打开的,并且仍然被列为打开状态。

我不确定在"gadget“模式下运行pi _0是否可以实现这一点,但也许值得一看。

票数 2
EN

Stack Overflow用户

发布于 2021-02-27 07:12:33

这在CircuitPython学习指南的这一节中有所介绍:https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage

票数 1
EN

Stack Overflow用户

发布于 2021-06-16 01:50:39

这里有一个很好的HID指南:

https://learn.adafruit.com/circuitpython-essentials/circuitpython-hid-keyboard-and-mouse

下面是HID示例:

代码语言:javascript
复制
import time

import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

# A simple neat keyboard demo in CircuitPython

# The pins we'll use, each will have an internal pullup
keypress_pins = [board.A1, board.A2]
# Our array of key objects
key_pin_array = []
# The Keycode sent for each button, will be paired with a control key
keys_pressed = [Keycode.A, "Hello World!\n"]
control_key = Keycode.SHIFT

# The keyboard object!
time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)  # We're in the US :)

# Make all pin objects inputs with pullups
for pin in keypress_pins:
    key_pin = digitalio.DigitalInOut(pin)
    key_pin.direction = digitalio.Direction.INPUT
    key_pin.pull = digitalio.Pull.UP
    key_pin_array.append(key_pin)

# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.D13)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT

print("Waiting for key pin...")

while True:
    # Check each pin
    for key_pin in key_pin_array:
        if not key_pin.value:  # Is it grounded?
            i = key_pin_array.index(key_pin)
            print("Pin #%d is grounded." % i)

            # Turn on the red LED
            led.value = True

            while not key_pin.value:
                pass  # Wait for it to be ungrounded!
            # "Type" the Keycode or string
            key = keys_pressed[i]  # Get the corresponding Keycode or string
            if isinstance(key, str):  # If it's a string...
                keyboard_layout.write(key)  # ...Print the string
            else:  # If it's not a string...
                keyboard.press(control_key, key)  # "Press"...
                keyboard.release_all()  # ..."Release"!

            # Turn off the red LED
            led.value = False

    time.sleep(0.01) ```

The example only prints Hello World, so it's not very useful, but it's a good base to mod. 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66305409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档