0

I have a new ATmega328P CH340G Arduino Uno R3 board.

When I input a two-digit number (like 29), after power off and power on, the board shows only one digit (only 9). I want to show two digits.

enter image description here

Can you help me?

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <EEPROM.h>

int addr = 5;

LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
 lcd.init();     
 Serial.begin(9600);
 // initialize the lcd 
 // Print a message to the LCD.
 lcd.backlight();
 lcd.setCursor(0,0);
 lcd.write(EEPROM.read(addr));
}

void loop() {
   if (Serial.available()) {
    while (Serial.available() > 0) {
      char myValue = Serial.read(); 
      EEPROM.write(addr,myValue);
      lcd.write(myValue);
    }
  }
}
dda
  • 6,030
  • 2
  • 25
  • 34
Reg Reg
  • 49
  • 4
  • 2
    Because you are always writing to the same `addr` (i.e. `5`) aren't you overwriting the previous character. What would happen if you write like this: `EEPROM.write(addr++, myValue);` (notice the `++` to increment the address) – Pawel Nov 28 '15 at 07:14

1 Answers1

0

You are always writing to the same addr (i.e. 5) so you are most likely overwriting the previous character. Try incrementing your address after a write like this:

EEPROM.write(addr++, myValue); 

(notice the ++ to increment the address)

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • I think that you need to calculate the address accordingly. (This applies is for write and write). I don't have a bigger picture of what you are trying to do but I think you just need to start reading from the left and read to the end of data. E.g. if you have a box that can only contain one item you cannot remove two items from it - this is how I understand the address and read/write work here. write - put an item to the box (overwriting existing if any), read checks what item in the box you have. You have a number of boxes one next to each other and addr tells you which box you want to use. – Pawel Dec 03 '15 at 17:29