c++ - Arduino Nano 33 物联网软件序列号

标签 c++ arduino arduino-c++

我计划从旧的 5V Arduino Nano 转移到新的 Arduino Nano 33 IoT。我已经使用软件串行 (SoftwareSerial.h) 为旧的 5V Arduino Nano 编写了一个功能代码,以与 Sim800L 模块进行通信。但是,当我将开发板更换为新的 Arduino Nano 33 IoT 时,找不到软件串行库。

我曾尝试在“Sketch”下的“include library”菜单中找到它,但该库根本不存在。鉴于该产品太新了,我还没有找到任何有用的研究来帮助我解决这个问题。我对 EEPROM 库有同样的问题。

#include <SoftwareSerial.h>
#include <EEPROM.h>

有谁知道如何为新的 Nano 33 IoT 板添加 SoftwareSerial.h 和 EEPROM.h 库,或者知道用于新板的新库?

下面是我在编译时得到的错误信息:

Sim800L_V7.1:3:12: error: SoftwareSerial.h: No such file or directory

   #include <SoftwareSerial.h>

            ^~~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1
SoftwareSerial.h: No such file or directory

任何帮助将不胜感激 谢谢

最佳答案

没有可用于 Arduino Nano 33 IoT 的 SoftwareSerial.h,因为它不是必需的。该板提供更多功能:可分配给不同引脚的硬件序列号。

此功能由微 Controller Atmel SAMD21G 提供,称为 I/O 多路复用(详见 the data sheet Atmel SAM D21E / SAM D21G / SAM D21J 中的第 21 页)。微 Controller 提供 6 个 SERCOM,您可以将其分配给(几乎)任何引脚。

Arduino Nano 33 IoT 已经使用了一些 SERCOM:

  • SPI NINA 的 SERCOM2
  • 用于 MOSI/MISO 的 SERCOM3
  • 用于 I2C 总线的 SERCOM4
  • 用于串行调试 (USB) 的 SERCOM5

我们还有 SERCOM0 和 SERCOM1。

variant.cppvariant.h 文件中描述了引脚分配的详细信息。由于 Arduino 是开源的,您可以在 the GitHub repository for SAMD boards 上轻松找到它们。 .

对于 Arduino Nano 33 IoT,引脚分配描述如下:

通过阅读 variant.cpp,我们了解了引脚分配,尤其是 SAMD 引脚(PAxx 或 PBxx)与 Arduino 引脚之间的链接。

SAMD 引脚对于与 the data sheet Atmel SAM D21E / SAM D21G / SAM D21J 的端口功能多路复用链接很重要.

SERCOM 可以是经典替代。在数据表中,classic 在 C 列中,alternate 在 D 列中。SERCOM 由其索引和 pad 定义。例如:SERCOM0/PAD[3] 也称为 0.3

备注: RX 的焊盘定义为 0 到 3,而 TX 仅定义为 0 和 2。当您选择要使用的引脚时,这是一个重要的考虑因素。

For reference, see the table I used to select the SERCOM to assign.

理论够多了,去找解决方案吧......

在 Arduino Nano 33 IoT 的引脚 5 (RX) 和 6 (TX) 上添加一个硬件序列:

#include <Arduino.h>
#include "wiring_private.h"

Uart mySerial (&sercom0, 5, 6, SERCOM_RX_PAD_1, UART_TX_PAD_0);

// Attach the interrupt handler to the SERCOM
void SERCOM0_Handler()
{
    mySerial.IrqHandler();
}

void setup() {
  // Reassign pins 5 and 6 to SERCOM alt
  pinPeripheral(5, PIO_SERCOM_ALT);
  pinPeripheral(6, PIO_SERCOM_ALT);

  // Start my new hardware serial
  mySerial.begin(9600);
}

void loop() {
  // Do something with mySerial...
}

另一个例子,在 Arduino Nano 33 IoT 的引脚 13 (RX) 和 8 (TX) 上添加一个硬件序列:

#include <Arduino.h>
#include "wiring_private.h"

Uart mySerial (&sercom1, 13, 8, SERCOM_RX_PAD_1, UART_TX_PAD_2);

// Attach the interrupt handler to the SERCOM
void SERCOM1_Handler()
{
    mySerial.IrqHandler();
}

void setup() {
  // Reassign pins 13 and 8 to SERCOM (not alt this time)
  pinPeripheral(13, PIO_SERCOM);
  pinPeripheral(8, PIO_SERCOM);

  // Start my new hardware serial
  mySerial.begin(9600);
}

void loop() {
  // Do something with mySerial...
}

关于c++ - Arduino Nano 33 物联网软件序列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57175348/

相关文章:

arduino - 更改 LCD 引脚

c++ - AVR CTC 模式下的 16 位定时器

arduino - 为什么 Arduino 中的引脚定义声明为静态

c++ - 停止并恢复优化

java - Arduino Ping))) 传感器在显示一些结果后突然停止

c++ - 在 MS Windows 上的 Netbeans 6.1 C++ 中设置 wxWidget?

arduino - Digispark 读取大写锁定状态

c++ - 舍入平均值逐渐变差

android - 使用 native CocosDenshion、cocos2d-x 循环播放音效时,AudioFlinger 无法创建音轨,状态为 : -12 ,

c++ - 将包含不可复制对象的对插入 map