This is a re-implementation of the database library originally written by Madhusudana das found here:
http://www.arduino.cc/playground/Code/DatabaseLibrary
This version increases the maximum number of records allowed in a database from 256 records (byte) to 4,294,967,295 theoretical records (unsigned long). When using with an AT24C1024, you are limited to the amount of records that will fit into the maximum available EEPROM storage (128 kilobytes for 1 device, up to 512 kilobytes for 4 devices). The maximum record size was also increased from 256 bytes (byte) to 32,767 bytes (int).
With these changes, it is now possible to use this library in conjunction with an external EEPROM such as the AT24C1024 via the AT24C1024 EEPROM Library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
The Extended Database library project page is here:
http://www.arduino.cc/playground/Code/ExtendedDatabaseLibrary
Both libraries may be downloaded here:
Any comments/suggestions/improvements are welcome.
Example sketch:
This sketch will create 2000 records on an AT24C1024 EEPROM and then output them to the serial port.
/*
EDB.pde
Extended Database Library + AT24C1024 EEPROM Demo Sketch
The Extended Database library project page is here:
http://www.arduino.cc/playground/Code/ExtendedDatabaseLibrary
The AT24C1024 library project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
*/
#include "WProgram.h"
#include <Wire.h>
#include <E24C1024.h>
#include <EDB.h>
#include "string.h"
EDB db;
#
#define LOG_TABLE 0
#define CREATE_RECORDS true
#define RECORDS_TO_CREATE 2000
struct LogEvent {
int id;
char date[11];
char time[9];
int temperature;
} logEvent;
void setup()
{
Serial.begin(9600);
Serial.println("EEPROM DB Library Demo");
Serial.println();
randomSeed(analogRead(0));
if (CREATE_RECORDS)
{
db.create(LOG_TABLE, (int)sizeof(logEvent));
Serial.print("Creating Records...");
for (int j = 1; j <= RECORDS_TO_CREATE; j++)
{
logEvent.id = j;
int m = random(1, 12);
int d = random(1, 31);
int h = random(1, 12);
int i = random(59);
int s = random(59);
sprintf(logEvent.date, "2009-%02d-%02d", m, d);
sprintf(logEvent.time, "%02d:%02d:%02d", h, i, s);
logEvent.temperature = random(1, 125);
db.append(EDB_REC logEvent);
if (!(j % 100)) Serial.print(".");
}
Serial.println("DONE");
}
db.open(LOG_TABLE);
Serial.print("Record Size: "); Serial.println(db.recSize());
Serial.print("Record Count: "); Serial.println(db.nRecs());
delay(1000);
selectAll();
}
void loop()
{
}
void selectAll()
{
if (db.nRecs()) Serial.println("-----");
for (unsigned int i = 1; i <= RECORDS_TO_CREATE; i++)
{
db.read(i, EDB_REC logEvent);
Serial.print("RecNum: "); Serial.println(i);
Serial.print("ID: "); Serial.println(logEvent.id);
Serial.print("Date: "); Serial.println(logEvent.date);
Serial.print("Time: "); Serial.println(logEvent.time);
Serial.print("Temp: "); Serial.println(logEvent.temperature);
Serial.println("-----");
}
}