树莓派PICO-UART串口

同样,如果您使用 Arduino Mbed 核心类型,则可能要添加该 UART 语句。

此处;此演示草图适用于任一核心。经过测试,一切正常!

似乎要逐渐初始化?

/*
 * Demonstration of using multiple Serial Ports on RPi Pico board.
 * By default when using the Arduino Cores:
 *   Serial is a virtual Serial port operating over the USB
 *   Serial1 is tied to UART0 on pins 1 and 2
 *   Serial2 may need creating, and is UART1 on pins 8&9
 */

#ifdef ARDUINO_ARCH_MBED_RP2040
// For the Arduino MBedOS Core, we must create Serial2
UART Serial2(8, 9, NC, NC);
#else
// For the Earl Philhower core ( https://github.com/earlephilhower )
// Serial2 is already defined.
#endif

void setup() {
  Serial.begin(9600);
  Serial1.begin(115200);
  Serial2.begin(115200);
  while (!Serial)
    ; // Serial is via USB; wait for enumeration
}

void loop() {
  Serial.println("This is port \"Serial\"");
  Serial1.println("1111111111111\r\nThis is port \"Serial1\"");
  Serial2.println("2222222222222\r\nThis is port \"Serial2\"");

  if (Serial1.read() > 0) {  // read and discard data from UART0
    Serial.println("Input detected on UART0");
  }
  if (Serial2.read() > 0) {  // read and discard data from UART1
    Serial.println("Input on UART1");
  }
  delay(2000);
}

标准ARDUINO写法

#include "Arduino.h"
#include "stdio.h"
#include "pico/stdlib.h"
#include "hardware/uart.h"

UART Serial2(8, 9, NC, NC);

void setup(){

Serial2.begin(9600);
// ...
Serial2.write("hello world");
}

void loop {

delay(100);

}

问题

Arduino: 1.8.13 (Linux), Board: "Raspberry Pi Pico, 2MB (no FS), 125 MHz, Disabled, None, Pico SDK"

Cheers

Russsh

sketch_jul07a:6:1: error: 'UART' does not name a type
6 | UART Serial2(8, 9, NC, NC);
| ^~~~

 

posted @ 2025-01-26 23:14  mcwhirr  阅读(163)  评论(0)    收藏  举报