首页 文章

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

提问于
浏览
0

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

此外我的arduino没有连接到PC或笔记本电脑,所以我不能使用PC或笔记本电脑的文件系统

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

1 回答

  • 0

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

    此示例草图应将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相比,这是一个巨大的扩展 .

相关问题