Hello, I am trying to save a String from Serial to EEPROM and print on the Oled screen, if I move from the conditional "IF" the print command immediately gives an error and I have to reset my Seeeduino XIAO Samd21.
#include <FlashAsEEPROM_SAMD.h> // work whit flash eeprom
#include <Wire.h> //display oled
#include <Adafruit_GFX.h> //display oled
#include <Adafruit_SSD1306.h> //display oled
#include <Fonts/FreeSansBoldOblique9pt7b.h> //font to oled
#define SCREEN_WIDTH 128 // OLED display width, in pixels //display oled
#define SCREEN_HEIGHT 32 // OLED display height, in pixels //display oled
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); //display oled
String myString; // To save in eeprom
String a; // To read and print in eeprom
int button_del = 7; // To delete eeprom
void setup() {
pinMode(button_del, INPUT_PULLUP);
Serial.begin (9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed")); //display oled
for(;;);
}
display.clearDisplay(); //clear display oled
}
void loop() {
if (Serial.available() || digitalRead(button_del) == LOW){
myString=Serial.readString();
EEPROM.put (0, myString);
delay (4);
a=EEPROM.get (0,myString); //If I move this line out of the
//conditional so that it is read from the EEPROM it gives an error.
Serial.print (a); //Test "OK" only one word, THIS IS BAD since I need the top line outside the IF to load on startup.
}
if (digitalRead(button_del) == LOW) {
a=""; //OK clear the screen, I don't know if it clears
display.clearDisplay(); //the eeprom and I don't know if it is actually recorded.
EEPROM.update (0, 0);
}
display.clearDisplay();
display.setFont(&FreeSansBoldOblique9pt7b);
display.setTextSize(1);
display.setTextColor(WHITE);
a.toUpperCase();
display.setCursor(0, 15);
display.print(a);
display.display();
}