RobTillaart / I2C_EEPROM

Library for I2C EEPROM - 24LC512, 24LC256, 24LC64/32/16/08/04/02/01.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

24LC32A

damarcrazy opened this issue · comments

Best regard. Please I want to ask you for help to be able to upload a matrix of pointers using an arduino uno with an eeprom 24LC32A or larger and then display it on LCD
Thanks in advance for your support.

#include <I2C_eeprom.h>
#include "Arduino.h"
#include <Wire.h>                                     // libreria de comunicacion por I2C
#include <LiquidCrystal_I2C.h>                        // libreria para LCD por I2C

I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC32);

uint32_t start, diff;

/***********************************************************
   Base de datos de palabras y frases
 ***********************************************************/
const char* palabras[] = {
  "Maquillarse",
  "Playa",
  "Erizo",
  "Macarena",
  "Cirujano",
  "Huracan",
  "Facebook",
  "Estreñimiento",
  "Accidente de coche",
  "Criminal",
  "El presidente",
  "Chivato",
  "Club de lucha",
  "Hipo",
  "Jefe",
  "Detective",
  "Ipad",
  "Hacer galletas",
  "Chiste",
  "Puta",
  "Peluca",
  "Oveja negra",
  "Avion",
  "Macho",
  "Bebe",
  "Rayo de sol",
  "Brindis",
  "Limbo",
  "Cuchara",
  "Sorpresa",
  "Claque",
  "Bañar a un gato",
  "Cambiar pañal",
  "Pasear al perro",
  "Levantar pesas",
  "Jugar a las cartas",
};


/***********************************************************
   Inicializacion y funcion principal
 ***********************************************************/

LiquidCrystal_I2C lcd(0x27, 16, 2);                   //Crear el objeto lcd  direccion  0x27 y 16 columnas X 2 filas

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(3, INPUT_PULLUP);
  ee.begin();
  if (! ee.isConnected())
  {
    lcd.setCursor(0,0); lcd.print(F("ERROR:No hay acceso con la memeoria..."));
    while (1);
  }

  ee.writeBlock(0, (uint8_t *) &palabras, 50);
  //ee.writeBlock(60, (uint8_t *) &data3, sizeof(data3));
 // dumpEEPROM(0, 128);

}

void loop() {
  
}

updated your post with syntax highlighting => readability

will be later this week before I have time to dive into this problem.

tIP: You need to make a for loop and go over all the entries of the palabras table.

@damarcrazy
I assume the goal is to write the 40 or so strings into EEPROM first, is that correct?

Storing run time pointers in EEPROM makes no sense as in theory and practice there is no guarantee that the
data will be on the same addresses.

wrote a small test sketch, please give it a try and post the output

it should write the words to EEPROM and read them back.
They are stored in format | length0 | word0 | length1 | word1 | length2 ...... | length36 | word36 |

//
//    FILE:  test.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: test
//    DATE: 2021-08-25
//     URL: https://github.com/RobTillaart/

#include "Wire.h"
#include "I2C_eeprom.h"

I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC32);

const char* palabras[36] = {
  "Maquillarse",
  "Playa",
  "Erizo",
  "Macarena",
  "Cirujano",
  "Huracan",
  "Facebook",
  "Estreñimiento",
  "Accidente de coche",
  "Criminal",
  "El presidente",
  "Chivato",
  "Club de lucha",
  "Hipo",
  "Jefe",
  "Detective",
  "Ipad",
  "Hacer galletas",
  "Chiste",
  "Puta",
  "Peluca",
  "Oveja negra",
  "Avion",
  "Macho",
  "Bebe",
  "Rayo de sol",
  "Brindis",
  "Limbo",
  "Cuchara",
  "Sorpresa",
  "Claque",
  "Bañar a un gato",
  "Cambiar pañal",
  "Pasear al perro",
  "Levantar pesas",
  "Jugar a las cartas",
};


void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println(__FILE__);

  Wire.begin();
  ee.begin();

  Serial.println("POS\tLEN\tTXT");

  uint32_t position = 0;  // start position, could be any value
  for (int i = 0; i < 36; i++)
  {
    Serial.print(position);
    Serial.print("\t");
    Serial.print(strlen(palabras[i]) + 1);
    Serial.print("\t");
    Serial.println(palabras[i]);

    // write length + 1 for '\0' = end of string character)
    uint8_t length = strlen(palabras[i]) + 1;
    ee.writeByte(position, length);
    position++;

    // write the string itself after the length
    ee.writeBlock(position, (uint8_t *) palabras[i], length);
    position = position + length;
  }

  position = 0;
  for (int i = 0; i < 36; i++)
  {
    char buffer[24];

    // read the length
    uint8_t length = ee.readByte(position);
    position++;

    // read back the string
    ee.readBlock(position, (uint8_t *) &buffer, length);
    position = position + length;

    Serial.print(length);
    Serial.print("\t");
    Serial.println(buffer);
  }
}

void loop()
{
}

// -- END OF FILE --

searching for the n-th entry looks something like

void search(uint8_t n)
{
  if (n >= 36) return;

  // find n-th entry
  uint32_t position = 0;
  for (uint8_t i = 0; i < n; i++) position += ee.readByte(position);

  // read and print it
  char buffer[40];
  uint8_t length = ee.readByte(position);
  ee.readBlock(position, (uint8_t *) &buffer, length);
  Serial.print(n);
  Serial.print("\t");
  Serial.println(buffer);
}

I have no eeprom nearby to test, :)

Any progress made?

Any progress?

As there is no progress I close this issue. Please reopen if needed.