Hi! I hace this weird issue I can´t get a solution: I´m building a 16 channel MIDI drum controller with an Arduino Mega, and I´m using the EEPROM memory to save a preset. The info to be saved are only ints so every saved data uses 2 bytes.
I noticed that when saving to the EEPROM the sistem put random numbers instead the ones I wanted, so I made a small program to check the memory, here is the test program:
// Pablo Martín
// pmartinchile@gmail.com
// www.pmartinchile.com / www.pmartinlab.com
//Librerías:
#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>
//------------------------------------------------------------------
//II.- Setup -------------------------------------------------------
//------------------------------------------------------------------
void setup(){
Serial.begin(115200);
//Matriz de Partes:
//Mapeo: MIN, MAX, NOTA General MIDI Drum (GM):
int notahh = 42;
int notabd = 36;
int notasn1 = 38;
int notasn2 = 40;
int notaT1LowFloorTom = 41;
int notaT1HighFloorTom = 43;
int notaLowTom = 45;
int notaLowMidTom = 47;
int notaHighMidTom = 48;
int notaHighTom = 50;
int notaChina = 52;
int notaSplash = 55;
int notaRideCym = 51;
int notaRideBell = 53;
int notaCrashCym = 49;
int notaCrashBell = 57;
//Mapeo: MIN, MAX, NOTA General MIDI Drum (GM):
int PARTES[48] = {70, 1020 , notahh, 70, 1020, notabd, 70, 1020 , notasn1, 70, 1020 , notasn2,200, 1020 , notaT1LowFloorTom,200, 1020 , notaT1HighFloorTom,200, 1020 , notaLowTom,200, 1020 , notaLowMidTom,200, 1020 , notaHighMidTom,200, 1020 , notaHighTom,100, 1020 , notaChina,100, 1020 , notaSplash,100, 1020 , notaRideCym,100, 1020 , notaRideBell,100, 1020 , notaCrashCym, 200, 1020 , notaCrashBell};
Serial.println("Writing to EEPROM: ");
for(int i =0; i<=47; i++){
EEPROM.put(2*i, PARTES[i]);
}
Serial.println("Read int from EEPROM: ");
int aux;
for(int i =0; i<=47; i++){
EEPROM.get(2*i, aux);delay(200);
Serial.println(aux); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
}
}//setup
//------------------------------------------------------------------
//III.- Loop -------------------------------------------------------
//------------------------------------------------------------------
void loop(){
}//void loop
It worked fine so I put the same one on the main code, but it didnt work. Adding delays worked for reading from the EEPROM but not for saving. Im working a 115200 baud, the libraries I´m using are:
//Librerías:
#include <MIDI.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>
What do you think that could be bugging the code?
Thanks!