Scott Penrose

Teensy EEPROM Config

Scott is an expert software developer with over 30 years experience, specialising in education, automation and remote data.

Storing config in EEPROM is easy and works in most environments. No need to be Teensy, or even Arduino, but here is my Teensy specific data.

#!C
#include <EEPROMex.h>
struct CONFIG {
	byte mode;
	int displayBright;		// -255 .. 255 (negative = inverse)
	unsigned long test;
	unsigned int displayInterval;	// How often to update display params?
	unsigned int environmentReadInterval;	// Read Temperature / Humidity
	unsigned int environmentLogInterval;	// Log / Display temperature / humidity
};
CONFIG config = { 0, 0, 0, 0, 0 };	// You can set defaults...

void setup() {
	EEPROM.setMemPool(0, 2048);  // EEPROMex did not know Teensy 3.1 default EEPROM size
	readConfig();

	// Display current
	Serial.print("Config test = ");
	Serial.println(config.test);

	// Increment each time starts up
	config.test++;
	writeConfig();
}

void loop() {
}

void readConfig() {
	EEPROM.readBlock( 0, config );
}

void writeConfig() {
	EEPROM.writeBlock( 0, config );
}

  • Arduino
  • Teensy