Storing string to Esp EEPROM

but every time you reset the code you store 000000 in the location, so how will you retrieve the last number stored when it keeps getting overwritten?

how do i read the precious value. also how do i store the string "000000000" to preferences ?
how can i store the new value in preference everytime i change?
please help me. thank you

thats what i dont know how to do
so i thought of using eeprom but its not working
if you have any idea. please help me. thank you

like, once i just type any number, it just gets stored in the variable text for Temporarily also i have checked in the serial monitor, printing "text". since its not stored anywhere, after i restart its again goes back to "000000000"

if you want to store new numbers in text then stop storing the same old 00000 again and again.

remove

  preferences.end();


preferences.putString("text", text1);

where does the new number to be stored come from?

post the new code with the thingies removed.

i dont know , how do i do that

if you do not know the source of the new number then how am I supposed to know? Anyways, I'll just make stuff up.

 if (is_button_pressed(TYPING_BUTTON)) {
    if (text[pos] == '9') text[pos] = '/';
    text[pos]++;
prefrences.putString( "text", text);

oh yea i can try this way, thank you so much, i will try this.

simple as

even now when i am restarting , i am not able to see the previous numbers,
here is the code

#include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <array>
#include <Adafruit_GFX.h>
#include <Preferences.h>

Preferences preferences;

#define TYPING_BUTTON 15
#define BACKSPACE_BUTTON 4
#define POSITION_BUTTON 17
#define BUTTON_DELAY 250

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


char text[] = "0000000000";
unsigned int pos = 0;
unsigned long next_pos_time;
const byte maxPos = sizeof text - 1;
bool typing = false;
const char* text1 = text;
void displayText(const char* c) {
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setCursor(0, 50);
  oled.setTextSize(2);

  oled.print(c);

  oled.display();
}

bool is_button_pressed(uint8_t pin) {
  return digitalRead(pin) == LOW;
}

void setup() {
  Serial.begin(115200);
  delay(2000);

  pinMode(TYPING_BUTTON, INPUT_PULLUP);
  pinMode(BACKSPACE_BUTTON, INPUT_PULLUP);
  pinMode(POSITION_BUTTON, INPUT_PULLUP);

  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("SSD1306 allocation failed");
    return;
  }
  Serial.println();


  oled.clearDisplay();
  oled.display();
}
int i;
void loop() {
  oled.setCursor(0, 0);
  displayText(text);
  if (typing && next_pos_time <= millis()) {
    typing = false;
    pos++;
  }
  if (is_button_pressed(BACKSPACE_BUTTON)) {
    if (typing) {
      typing = false;
      text[pos] = '/';
    } else if (pos > 0) {
      pos--;
    }


    text[pos] = '/';
    delay(BUTTON_DELAY);
  }
  if (is_button_pressed(TYPING_BUTTON)) {
    if (text[pos] == '9') text[pos] = '/';
    text[pos]++;
    preferences.begin("credentials", false);

    preferences.putString("text", text);
    preferences.end();



    next_pos_time = millis() + 1250;
    typing = true;
    delay(BUTTON_DELAY);
  }
}

please help me. thank you

do you know waht that does?

have you bothered to look at File|Examples|Preferences?

Anyways, I'm not getting anywhere. Perhaps someone else can lend a hand. I'm out.

yes i have done now, and i have tried that also and still is not working

i am sorry for that

Basically

In setup

Open the preferences namespace
Check if the data you are interested in is already there. If so read it in your buffer
If not create it with the default value of your buffer

In loop

Whenever the data is modified store it again (overwrite)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.