IoT|硬體|設備|Arduino EEPROM 記憶儲存
介紹
電子抹除式可複寫唯讀記憶體(Electrically- Erasable Programmable Read-Only Memory)
Arduino 板上的微控制器有512 位元組的 EEPROM 存儲器:當開發板關閉時(就像一個小型硬盤驅動器)開始記憶(即是保存這些數值)。這個解決方案可以節省執行時間,因為每一個寫操作需要3.3毫秒;EEPROM也有每個單位置100.000的寫週期的限
不同設備 EEPROM 有不同容量
| Arduno Duemilanove | 
512b EEPROM storage 
 | 
Arduino Uno 
 | 
1kb EEPROM storage 
 | 
Arduino Mega 
 | 
4kb EEPROM storage 
 | 
官方提供了一些 Examples,裡面有完整的程式碼
* EEPROM.update()
 * EEPROM library reference
 * EEPROM Iteration – Programming examples on how to go through the EEPROM memory locations.(明白怎樣到達EEPROM存儲本地。)
 * EEPROM Put – Put values in EEPROM using variable semantics (differs from EEPROM.write() ).(用變量來把一些數值放到EEPROM里。)
範例程式
#include <EEPROM.h>
#include "eeprom_anything.h"
struct dataType {
  char name[10];
  int age;
};
void setup() {
  Serial.begin(115200);
  dataType d; // 宣告結構變數,放入資料
  strcpy(d.name, "Arduino");
  d.age = 9;
  Serial.print("name: ");
  Serial.println(d.name);
  Serial.print("age: ");
  Serial.println(d.age);
  // 寫入EEPROM,回傳值count代表總共寫入幾個byte
  int count = EEPROM_writeAnything(0, d);
  Serial.print(count);
  Serial.println(" bytes written.");
}
void loop() {
  // 讀取EEPROM,回傳值count代表總共寫入幾個byte
  dataType d;
  EEPROM_readAnything(0, d);
  Serial.print("name: ");
  Serial.println(d.name);
  Serial.print("age: ");
  Serial.println(d.age);
  while (1) {
  }
}
[資源]
1.EEPROM Library 介紹(包含各種 EEPROM 範例)
留言
張貼留言