Go Down

Topic: Database Library (Read 6342 times) previous topic - next topic


If your address pointer ever got larger than 256, you'd experience issues.  I made some additional changes to the library and posted them here:


I've successfully added 1300+, 45 byte records and retrieved them with no issues using the Extended Database Library and a 512 kilobyte AT24C1024 eeprom.


Anyone have a source and price for the AT24C1024 in DIP package? A quick check on goggle only showed datasheets.



I got mine at digikey for about $4 each.



I have just got EDB_24XX512 Example working with my  24AA1025.

The problem i'm having is storing Text in the database field.

Id = 1
Date = 24/03/2010
Time = 16:00
Value = 1023

I ether get the first letter of the string or a "0".

I have tried changing
Code: [Select]

struct LogEvent {
 int id;
 int Date;
 int Time;
 int Value;


Code: [Select]
struct LogEvent {
 int id;
 char Date;
 char Time;
 char Value;

What am I doing wrong?

Thanks in Advance

Coding Badly

Post the entire Sketch.


I have posted the original code with a basic tweak:

Changed the temp from "int" t0 "char"

Code: [Select]

Extended Database Library + 24XX512 EEPROM Demo Sketch

The Extended Database library project page is here:

The E24C1024 library project page is here:

#include "WProgram.h"
#include <EDB.h>
#include <E24C1024.h>

// Use the 24XX512 EEPROM as storage
#include <Wire.h>
#include <E24C1024.h> // Should be compatible with 24XX512 series in this instance

// From the 24XX512 datasheet:
// The Chip Select bits A2, A1 and A0 can be used to expand the
// contiguous address space for up to 4 Mbit by adding up to eight
// 24XX512 devices on the same bus.
// So, each device must be have their address pins wired as listed below to
// create a single, contiguous address space across one or more devices.
// Example - 1 device:
// Device connections: A0->GND, A1->GND, A2->GND
// Uncomment only the #define TABLE_SIZE 65536 line below.

// Example - 3 devices:
// Device 1 connections: A0->GND, A1->GND, A2->GND
// Device 2 connections: A0->GND, A1->+5V, A2->GND
// Device 3 connections: A0->+5V, A1->+5V, A2->GND
// Uncomment only the #define TABLE_SIZE 196608 line below.
// Uncomment the ONE line appropriate for your platform.  
//#define TABLE_SIZE 65536 // 1 device: A0->GND, A1->GND, A2->GND
//#define TABLE_SIZE 131072 // 2 devices: A0->+5V, A1->1, A2->GND
//#define TABLE_SIZE 196608 // 3 devices: A0->GND, A1->+5V, A2->GND
//#define TABLE_SIZE 262144 // 4 devices: A0->+5V, A1->+5V, A2->GND
//#define TABLE_SIZE 327680 // 5 devices: A0->GND, A1->GND, A2->+5V
//#define TABLE_SIZE 393216 // 6 devices: A0->+5V, A1->GND, A2->+5V
//#define TABLE_SIZE 458752 // 7 devices: A0->GND, A1->+5V, A2->+5V
//#define TABLE_SIZE 524288 // 8 devices: A0->+5V, A1->+5V, A2->+5V

// default to the smallest - 1 device
#ifndef TABLE_SIZE
#define TABLE_SIZE 65536

// The number of demo records that should be created.  This should be less
// than (TABLE_SIZE - sizeof(EDB_Header)) / sizeof(LogEvent).  If it is higher,
// operations will return EDB_OUT_OF_RANGE for all records outside the usable range.

// Arbitrary record definition for this table.  
// This should be modified to reflect your record needs.
struct LogEvent {
 int id;
 char temperature;

// Create an EDB object with the appropriate write and read handlers
EDB db(&E24C1024::write, &E24C1024::read);

// Run the demo
void setup()
 Serial.println("Extended Database Library + 24XX512 EEPROM Demo");

 // create a table with starting address 0
 Serial.print("Creating table...");
// db.create(0, TABLE_SIZE, (unsigned int)sizeof(logEvent));


void loop()

void recordLimit()
 Serial.print("Record Limit: ");

void deleteAll()
 Serial.print("Truncating table...");

void countRecords()
 Serial.print("Record Count: ");

void createRecords(int num_recs)
 Serial.print("Creating Records...");
 for (int recno = 1; recno <= num_recs; recno++)
   logEvent.id = recno;
   logEvent.temperature = '16:00'; //random(1, 125);
   EDB_Status result = db.appendRec(EDB_REC logEvent);
   if (result != EDB_OK) printError(result);

void selectAll()
 for (int recno = 1; recno <= db.count(); recno++)
   EDB_Status result = db.readRec(recno, EDB_REC logEvent);
   if (result == EDB_OK)
     Serial.print("Recno: "); Serial.print(recno);
     Serial.print(" ID: "); Serial.print(logEvent.id);
     Serial.print(" Temp: "); Serial.println(logEvent.temperature);  
   else printError(result);

void printError(EDB_Status err)
 Serial.print("ERROR: ");
 switch (err)
     Serial.println("Recno out of range");
     Serial.println("Table full");
   case EDB_OK:
     Serial.println("Unknown Error");

Coding Badly

Mar 24, 2010, 11:13 pm Last Edit: Mar 24, 2010, 11:15 pm by bcook Reason: 1
Got it.

You should start by building an understanding of how strings are stored and manipulated in Arduino (in C).  Declaring a variable "char" provides storage for a single character (or a signed single byte integer).  To store a "string" you have to declare a variable as an array of char.  There is a set of functions for manipulating strings (arrays of char).

This looks helpful...


i have tried every possible datatype:

array, string & int.

no matter how i store the data before saving it to the eeprom i et the same result.

only the first character  is saved.

off to work!! will try again tonight


I figured it out:

Database Structure:
Code: [Select]
struct LogEvent {
 int id;
 char name[9]; // allow u to store a 9 Character string

Database Read out:
Code: [Select]

     Serial.print(" Temp: "); Serial.print(logEvent.name[0]); Serial.print(logEvent.name[1]);  Serial.print(logEvent.name[2]);
     Serial.print(logEvent.name[3]); Serial.print(logEvent.name[4]);  Serial.print(logEvent.name[5]);Serial.print(logEvent.name[6]);

thanks for the help!!!!!


Serial.print(LogEvent.name); will print the entire array (assuming that it is properly NULL terminated). You don't need to print it one letter at a time.

What happens if there are fewer than 9 (valid) characters in the array?
The art of getting good answers lies in asking good questions.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131