【问题标题】:Why do sketches take up so much space and memory in arduino?为什么草图在 arduino 中占用如此多的空间和内存?
【发布时间】:2016-09-27 09:28:01
【问题描述】:

当我编译我的程序时,我收到了这条消息

Sketch 使用 7,074 字节 (21%) 的程序存储空间。最大值为 32,256 字节。 全局变量使用 1,033 字节 (50%) 的动态内存,为局部变量留下 1,015 字节。最大值为 2,048 字节。

这条消息说明了什么?

这是我的代码

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

void setup() {
    Serial.begin(9600); // Initialize serial communications with the PC
    SPI.begin();            // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522 card
    Serial.println("Scan PICC to see UID and type...");
}

void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;//go to start of loop if there is no card present
    }

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;//if ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
    }

    // Dump debug info about the card. PICC_HaltA() is automatically called.
    mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

我也在闪烁的 LED 长针 13 上收到此消息

【问题讨论】:

  • 不看代码不好说。然而,大程序内存使用是 Arduino 框架“通用性”的代价。大量使用RAM 可能是由字符串文字引起的,而没有使用_FlashStringHelper 和F("literals")。其中一些被 Arduino Framework 使用(据我所知,大约是 200B)。
  • 已上传代码

标签: arduino iot arduino-uno


【解决方案1】:

如果您查看此question,您会发现,“扫描 PICC 以查看 UID 和类型...”等常量字符串将使用 SRAM(动态内存)而不是闪存(程序存储空间)。

【讨论】:

    【解决方案2】:

    这是一条消息,通知您 arduino 的内存状态。

    【讨论】:

    • 好的。所以它不是错误,也不会影响工作?
    猜你喜欢
    • 2012-02-12
    • 2017-01-07
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 2011-06-24
    • 2013-12-03
    • 2013-01-01
    • 2016-12-26
    相关资源
    最近更新 更多