Digispark EEPROM Internal
Digispark EEPROM Internal
This page is to Setup and Config Digispark EEPROM Internal
Hardware and Software
Hardware
Digispark EEPROM Internal
Software
Arduino IDE
Sanki Notes
What I did was COPY the EEPROM FOLDER in the arduino avr directory to the digispark library directory.
ARDUNIO: 1.6.5
DIGISPARK: Software isntalled via Arduino (15/07/2015)
PC
SOURCE: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\
DESTINATION: C:\Users\{user.name}\AppData\Roaming\Arduino15\packages\digistump\hardware\avr\1.6.5\libraries\
MAC
SOURCE: \Applications\Arduino\hardware\arduino\avr\libraries\EEPROM\
DESTINATION: \users\{user.name}\Library\Arduino15\packages\digistump\hardware\avr\1.6.5\libraries\
Examples
This example is (.ino)
Examples
This example is eeprom_anything.h
/*
* This example is for Digispark Internal EEPROM
*
*
*
*/
#include <EEPROM.h>
#include "eeprom_anything.h"
#include <SoftSerial.h> /* Allows Pin Change Interrupt Vector Sharing */
//#include <TinyPinChange.h> /* Ne pas oublier d'inclure la librairie <TinyPinChange> qui est utilisee par la librairie <RcSeq> */
SoftSerial mySerial(5, 4); // RX, TX
// 自行定義struct,放入你想讀取的資料
struct dataType{
char name[10];
int age;
char gender;
float money;
float bank;
int hexCode;
};
void setup(){
mySerial.begin(9600);
dataType writeData; // 宣告結構變數,放入資料
#ifndef eeprom_anything_h
strcpy(writeData.name, "Arduino");
#define eeprom_anything_h
writeData.age = 9;
writeData.gender = 'M';
#include <Arduino.h>
writeData.money = 9876.54;
#include <EEPROM.h>
writeData.bank = 1234.56;
writeData.hexCode = 0xfa;
// 利用這兩個C++模板,讀寫整組資料
// 參數address是EEPROM位址,參數data是想讀寫的資料結構
mySerial.print("name: ");
template <class T> int EEPROM_writeAnything(int address, const T &data);
mySerial.println(writeData.name);
template <class T> int EEPROM_readAnything(int address, T &data);
mySerial.print("age: ");
mySerial.println(writeData.age);
// 函式模板的定義
mySerial.print("gender: ");
// 使用EEPROM程式庫寫入一個一個的byte
mySerial.println(writeData.gender);
template <class T> int EEPROM_writeAnything(int address, const T &data)
mySerial.print("money: ");
{
mySerial.println(writeData.money);
const byte *p = (const byte *)(const void *)&data;
mySerial.print("bank: ");
int i, n;
mySerial.println(writeData.bank);
for(i = 0, n = sizeof(data); i < n; i++)
mySerial.print("hexCode: 0x");
EEPROM.write(address++, *p++);
mySerial.println(writeData.hexCode, HEX);
return i;
}
template <class T> int EEPROM_readAnything(int address, T &data)
//------------------------------- Write -------------------------
{
// 寫入EEPROM,回傳值count代表總共寫入幾個byte
byte *p = (byte *)(void *)&data;
int count = EEPROM_writeAnything(0, writeData);
int i, n;
mySerial.print(count);
for(i = 0, n = sizeof(data); i < n; i++)
mySerial.println(" bytes written.");
*p++ = EEPROM.read(address++);
mySerial.println("---------------");
return i;
}
//------------------------------- Read -------------------------
// 讀取EEPROM,回傳值count代表總共寫入幾個byte
#endif
dataType readData;
count = EEPROM_readAnything(0, readData);
mySerial.print("name: ");
mySerial.println(readData.name);
mySerial.print("age: ");
mySerial.println(readData.age);
mySerial.print("gender: ");
mySerial.println(readData.gender);
mySerial.print("money: ");
mySerial.println(readData.money);
mySerial.print("bank: ");
mySerial.println(readData.bank);
mySerial.print("hexCode: 0x");
mySerial.println(readData.hexCode, HEX);
mySerial.print(count);
mySerial.println(" bytes read.");
}
void loop(){
}