在arduino运行时在arduino的内存中创建文件

时间:2015-11-21 09:47:05

标签: file arduino arduino-uno

在我的arduino项目中,我必须将一些整数(25个特定的)存储在arduino内存中的文件中(因为我有arduino UNO并且它没有SD卡的内置端口)并且下一步读取该文件 - 我开始arduino。

此外我的arduino未连接到PC或笔记本电脑,因此我无法使用PC或笔记本电脑的文件系统

那么有可能做到这一点吗?

1 个答案:

答案 0 :(得分:0)

Arduino Uno具有1KB的非易失性EEPROM存储器,您可以将其用于此目的。一个整数是2个字节,所以你应该能够以这种方式存储超过500个字节。

此示例草图应将10到5的几个整数写入EEPROM存储器:

#include <EEPROM.h>

void setup() {
  int address = 0;   //Location we want the data to be put.

  for (int value = 10; value >= 5; --value) 
  {
    // Write the int at address
    EEPROM.put(eeAddress, value)
    // Move the address, so the next value will be written after the first.
    address += sizeof(int);
  }
}

void loop() {
}

此示例是EEPROM.put documentation中的示例的精简版本。其他示例可以在documentation of the various EEPROM functions中找到。 关于这个主题的另一个很好的教程可以在tronixstuff找到。

顺便说一句,如果你需要更多内存,你也可以使用EEPROM内存库。这些是小型IC。它们的内存容量很低,价格非常低,通常从1KB到256KB。在现代计算方面并不多,但与默认情况下的1KB相比,这是一个巨大的扩展。