用arduino开发梅树派Raspberry Pi Pico

Raspberry Pi Pico 是开发板中的现代王红(“网红”,改王红吧、发文助手说不正规),网上涉及它的内容非常多,原始材料可到RaspberryPI站点上看,从入门到精通应有尽有,完全开源,不用操心某些站点又是入会又是收费的下载点儿资料。我挑重要的说,更多的东西网上说的比我说的好,去查查就得了。

开发软件主要是MicroPython和C/C++,板上有个BOOTSEL钮,把它按住了然后插上micro-usb线,Windows 就增加虚拟串口,国内本地化的一般使用的是CH340芯片,必要时装一下它的驱动。启动后增加一个U盘,上面有两个文件,是两个大小1KB的文件,有板子的信息在里面。

可以把Micro-python的解释器固件考到这盘上,考贝完成后板子重启就找不到它到哪了,但是用爱沙尼亚大学Thonny开发的话,会发现它并在上面运行micropython程序,或许将来也会有luatos等其它脚本解释器,现在好像还没有。

下面说一下用arduino如何开发它

arduino环境下开发它是直接开发,没有什么解释器在其中了。

首先下载arduino 20,开源的不收费,然后默认安装即可(略)。运行arduino,然后在BOARDS MANAGER中要安装一个Arduino Mbed OS RP2040

 安装好后 Mbed OS后,选串口,再选板子。

 然后呢,我们测试一下ADC循环采集 AnalogOutSerial.ino , 会发现这程序与板子关系不大了,其它板子也是这么个写法儿,语言是一样的。

/*
  Analog input, analog output, serial output

  Reads an analog input pin, maps the result to a range from 0 to 255 and uses
  the result to set the pulse width modulation (PWM) of an output pin.
  Also prints the results to the Serial Monitor.

  The circuit:
  - potentiometer connected to analog pin 0.
    Center pin of the potentiometer goes to the analog pin.
    side pins of the potentiometer go to +5V and ground
  - LED connected from digital pin 9 to ground through 220 ohm resistor

  created 29 Dec. 2008
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial
*/

// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

char buff[50];

void setup() {
  // initialize serial communications at 9600 bps:
  //Serial.begin(9600);
  Serial.begin(115200);
}
void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the Serial Monitor:
  //Serial.print("sensor = ");
  sprintf(buff, "sensor = %d \t\t output = %d", sensorValue, outputValue);
  Serial.println(buff);
  //Serial.print("\t\t output = ");
  //Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(1);
}

 然后编译并烧录它(或叫下载)到板子上,做法是点那个右键头。

 然后呢,下载成功。

 有不成功的吗?有!我先是用Micropython写的循环采集,板子插到arduino下烧录不通,这些拔下USB线,按着BOOTSEL再插上,再进行烧录就成功了。

成功后,arduino的serial monitor即显示循环采集的数据

一共五个通道,最后一个是板子自己的内部测温值,其它四个在板子上由GP0-GP3引入。 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
树莓Pico开发板可以使用Arduino IDE进行编程。以下是使用Arduino IDE进行树莓Pico开发板编程的步骤: 1. 安装Arduino IDE:首先,您需要下载并安装Arduino IDE。您可以从Arduino官方网站上下载适用于您的操作系统的最新版本。 2. 安装RP2040支持库:树莓Pico开发板使用RP2040芯片,因此您需要安装RP2040支持库。在Arduino IDE中,打开“工具”菜单,选择“开发板”子菜单,然后选择“开发板管理器”。在搜索栏中输入“RP2040”,找到“Arduino Mbed OS RP2040 Boards”并点击“安装”。 3. 配置开发板:在Arduino IDE中,打开“工具”菜单,选择“开发板”子菜单,然后选择“Raspberry Pi Pico”。接下来,选择正确的端口和上传速度。 4. 编写代码:在Arduino IDE中,打开一个新的空白文件,编写您的树莓Pico开发板的Arduino代码。您可以使用Arduino语言和库来编写代码,就像在其他Arduino开发板上一样。 5. 上传代码:将树莓Pico开发板连接到计算机,并确保选择了正确的端口。然后,点击Arduino IDE工具栏上的“上传”按钮,将代码上传到树莓Pico开发板上。 请注意,树莓Pico开发板与传统的Arduino开发板略有不同,因此某些功能和库可能不可用或需要特殊配置。您可以参考树莓Pico开发板的文档和示例代码,以了解更多关于使用Arduino IDE进行树莓Pico开发板编程的详细信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值