标签: raspberry-pi-pico

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

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

我不希望 Pico 在插入时自动安装为 USB 存储。我只是希望它充当 HID 设备。我知道除了 code.py 之外,我还可以编写 boot.py 脚本,但我在网上找不到任何可以放入其中的内容,这会阻止它作为 USB 设备安装。有时我仍然希望它作为 USB 安装(当按下按钮/连接 GPIO 引脚时),因此我仍然有办法更改设备上的代码。

这可能吗?如果是这样,boot.py 应该是什么样子才能仅在连接某个 GPIO 引脚时挂载?

python raspberry-pi adafruit-circuitpython raspberry-pi-pico

7
推荐指数
1
解决办法
6787
查看次数

如何在树莓派 pico 自动运行上编写 micropython 程序?

我使用Thonny软件将程序发送到我的树莓派pico。我正在尝试在插入 pico 时自动运行特定程序。目前 pico 上的另一个程序会自动运行,但我希望运行另一个程序。

micropython thonny raspberry-pi-pico

6
推荐指数
1
解决办法
4453
查看次数

如何在 Raspberry Pico 上的第二个核心上运行代码

我正在尝试让多核在我的 pico 上工作,

#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"

void core1_main()
{

    stdio_init_all();

    while (1)
    {
        uint32_t t = multicore_fifo_pop_blocking();
        printf("hellow world %d \n", t);
    }
}

int main()
{
    multicore_launch_core1(&core1_main);
    uint32_t i = 0;

    while (1)
    {
        sleep_ms(250);
        multicore_fifo_push_blocking(i++);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我正在努力完成的一项非常基本的任务。我正在尝试更多地了解这个多核魔法。基本上我开始等待 core1 来获取一些数据。然后我简单地打印出来并等待下一条数据。在核心 0 上,我每 250 毫秒将一个数字推送到 FIFO 一次。
我在编译时没有收到任何错误,但运行代码不会产生任何输出。
我在这里做错了什么?有什么我应该注意的吗?

我已经尝试了很多方法来获得多核,但没有用。

更新 这给了我一些输出。我添加了等待 USB 连接和初始化的时间。现在我从 core 2 收到一些消息。

#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"

// const uint led = PICO_DEFAULT_LED_PIN;

void core1_main()
{
    printf("hellow world from second …
Run Code Online (Sandbox Code Playgroud)

c microcontroller cortex-m raspberry-pi-pico

6
推荐指数
1
解决办法
4218
查看次数

操作系统错误:[Errno 12] ENOMEM

我使用这里的代码。从 Thonny 运行多次后没有出现问题,我得到:

操作系统错误:[Errno 12] ENOMEM

我使用 nuke.uf2 清除 Raspberry Pi Pico W 上的存储。运行该文件太多次后,错误再次出现。nuke.uf2 是一个临时修复。

###############################################################
# WS2812 RGB LED Ring Light Breathing
# with the Raspberry Pi Pico Microcontroller
#
# by Joshua Hrisko, Maker Portal LLC (c) 2021
#
# Based on the Example neopixel_ring at:
# https://github.com/raspberrypi/pico-micropython-examples
###############################################################
#
import array, time
from machine import Pin
import rp2

#
############################################
# RP2040 PIO and Pin Configurations
############################################
#
# WS2812 LED Ring Configuration
led_count = …
Run Code Online (Sandbox Code Playgroud)

led micropython raspberry-pi-pico

6
推荐指数
1
解决办法
4632
查看次数

为什么MOV指令被ADD指令取代

我有以下说明:mov r1, r7在我的汇编代码中,但在研究反汇编之后,我发现实际生成的代码是adds r1, r7, #0

我检查了ARMv6-M架构参考手册,发现有一条MOVS <Rd>,<Rm>指令(A6.7.40)与ADDS.

虽然这不是一个大问题,但我仍然很困惑为什么汇编程序会替换我用不同操作码编写的代码。根据我正在阅读的书,所有非跳转指令都需要 1 个周期(我更希望汇编器是愚蠢的,而不是试图为我优化某些东西)。

我正在使用 Raspberry Pi Pico SDK,它使用 GNU 汇编器,据我所知。

我的所有代码都是用 helloworld.S 编写的,完整的源代码是:

.thumb_func
.global main

main:
mov r7, #0
bl stdio_init_all
loop:
ldr r0, =helloworld
add r7, #1
mov r1, r7
bl printf
mov r0, #250
bl sleep_ms
b loop
.data
.align 4
helloworld: .asciz "Hello World %d\n"
Run Code Online (Sandbox Code Playgroud)

assembly arm thumb cortex-m raspberry-pi-pico

5
推荐指数
1
解决办法
1382
查看次数

VS Code 无法识别 Pi Pico SDK 标头

所以我已经完成了在 Linux 的 Windows 子系统中编译的所有设置,一切都工作正常。我正在 VS Code 中编写代码,但它无法识别“pico/stdlib.h”等标头。代码编译并工作正常,但最好能正确设置代码,这样我就可以获得自动填充功能等。

如何将 SDK 库与 VS Code 正确链接?

谢谢!

c visual-studio-code raspberry-pi-pico

4
推荐指数
1
解决办法
5097
查看次数

如何让 Pico W 在启动时设置正确的时间

当使用电池运行时,Pico W 的时钟/utime 默认从 2021-01-01 00:00:00 开始。

每次启动时显然应该:

  • 自己获取当前时间,可能是通过互联网获取的。
  • 将其内部芯片设置为该时间,以便其 utime 库返回正确的时间。

有什么好的既定技术可以实现这一目标吗?

使用微蟒蛇。

micropython raspberry-pi-pico

3
推荐指数
1
解决办法
7904
查看次数

我如何让树莓派 pico 与 PC/外部设备通信

例如,当我给代码5时,我想打开我们的rpi pico中的LED(rpi pico通过电缆连接到电脑)

#This code will run in my computer (test.py)

x=int(input("Number?"))
if (x==5):
    #turn on raspberry pi pico led
Run Code Online (Sandbox Code Playgroud)

rpi pico的代码:

#This code will run in my rpi pico (pico.py)

from machine import Pin
led = Pin(25, Pin.OUT)

led.value(1)
Run Code Online (Sandbox Code Playgroud)

反之亦然(使用 rpi pico 中的代码在计算机上的代码中执行某些操作)

我如何调用/获取 pc 中的变量到 rpi pico

注意:我正在使用 opencv python 编写代码,我想在我的计算机上处​​理来自计算机摄像头的数据,并且我希望 rpi pico 根据处理后的数据做出反应。并将树莓派 pico 通过电缆连接到电脑。

python raspberry-pi micropython raspberry-pi-pico

1
推荐指数
1
解决办法
9168
查看次数

如何在 MicroPython 中格式化时间?

我正在尝试使用 Raspberry Pi Pico 和 MicroPython 转换time.localtime()为字符串。我尝试过.join(),但 Raspberry Pi Pico 运行 MicroPython:

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

now = time.localtime()
print("Current date and time: ")
print(now)

w = 128
h = 32

i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=200000)
addr = i2c.scan()[0]
oled = SSD1306_I2C(w, h, i2c, addr)

oled.fill(0)
oled.text("Raspberry Pi ", 5, 5)
olex.text("Hi Leo", 5, 15)

oled.show()
Run Code Online (Sandbox Code Playgroud)

format time micropython raspberry-pi-pico

1
推荐指数
1
解决办法
3878
查看次数

尝试为 Raspberry Pi Pico 构建 uf2 文件时出现 CMake 错误

在尝试执行该 命令时,我多次cmake -G "NMake Makefiles" .. 收到错误 。CMake Error: Error required internal CMake variable not set, cmake may not be built correctly

CMakeLists.txt:

cmake_minimum_required(VERSION 3.12)

project(nrf CXX)

include(pico_sdk_import.cmake)


pico_sdk_init()


add_executable(${PROJECT_NAME}
src/main.cpp
src/NRF24.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
inc
)

target_link_libraries(${PROJECT_NAME}
pico_stdlib
hardware_spi
)

pico_add_extra_outputs(${PROJECT_NAME})

pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
Run Code Online (Sandbox Code Playgroud)

CMake 错误:

CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_C_COMPILE_OBJECT
CMake Error: Error required internal CMake variable not set, cmake may …
Run Code Online (Sandbox Code Playgroud)

c++ cmake raspberry-pi-pico

1
推荐指数
1
解决办法
3033
查看次数

树莓派PICO ADC读取

为什么在Raspberry Pi Pico上获取ADC读数时不得到?即使我将ADC引脚接地,模拟读数总是在10到20之间波动。如何将模拟读数减少到零?

raspberry-pi-pico

0
推荐指数
1
解决办法
7381
查看次数

编译器错误显示“函数未在此范围内声明”,但该函数是公共的

我正在用 C++ 在 Raspberry Pi Pico 上设置 IRQ,但是当我编译代码时,它告诉我回调函数“未在此范围内声明”。我已经在墙上敲了几个小时了,因为该函数声明并且是公开的。

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"

uint64_t time_between_triggers;
uint16_t times_triggered;

void shaft_speed_init(uint8_t _gpio_number, uint8_t _precision, uint8_t _counts_per_turn){
    gpio_set_irq_enabled_with_callback(2, GPIO_IRQ_EDGE_RISE, true, &_shaft_speed_gpio_callback);

}

void _shaft_speed_gpio_callback(uint16_t _gpio, uint32_t _event_mask) {
    uint64_t trigger_time;
    static uint64_t prev_trigger_time;

    trigger_time = to_us_since_boot(get_absolute_time());
    time_between_triggers = time_between_triggers + (trigger_time - prev_trigger_time);
    prev_trigger_time = trigger_time;
    times_triggered++;
}
Run Code Online (Sandbox Code Playgroud)
[main] Building folder: variable_rate_planter 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/taylor/Documents/Programs/Pi-Pico/variable_rate_planter/build --config Debug --target all --
[build] [2/8  12% :: …
Run Code Online (Sandbox Code Playgroud)

c++ raspberry-pi-pico

0
推荐指数
1
解决办法
619
查看次数