Error value on EEPROM.Update

Greeting all.

this is my first posting in the forum.

I work on a P10 LED Display project which is need to store data into EEPROM. data is a series of integer value.

The problem is data being stored in EEPROM is different from data supposed to be stored.
This problem occurs when using bluetooth HC-06 and FTDI232 and however, didn’t occur when I use cheap USB-TTL Prolific for sending a serial data.

I attached data being sent and data received and here is my arduino code:

/
void setup() {

  Serial.begin(9600);    // xxSESUAI dengan baudrate standar dari Bluetooth HC-06
  Serial.println(F("Inisialisasi OK"));
  dmd.begin();            // start dmd
  dmd.selectFont(FONT);       // jenis font yang digunakan, dapat ditambah sesuai kebutuhan
  dmd.setBrightness(brightnessVal);     // tingkat brightness P10, maks 255, gunakan power supply eksternal
  pinMode(uploadButtonPin, INPUT_PULLUP);
  pinMode(buttonStart_Pin, OUTPUT);

  // check if the upload button have pressed, if so, then proceed upload mode

  if (digitalRead(uploadButtonPin) == LOW) {
    delay(600);
    Serial.print(F("Upload"));
    int address = 0;
    int bufferangka;
    int x = 0;
    unsigned long totalByteCount;
    int smallestFraction;
    boolean readFirstByte = true;
    boolean uploadProgress = true;
    box2.clear();
    box3.clear();
    box2.print(F("upload"));
    box3.print(F("waiting.."));
    Serial.print(F("ready to upload"));
    while (uploadProgress) {
      while (Serial.available() > 0) {
        bufferangka = Serial.read();
        while (readFirstByte) {
          Serial.print(F("Upload begin.."));                 //---------------------------------------------------------------------------------------------//
          totalByteCount = (((bufferangka - 60) * 30) + 10); // penjelasan 01 :                                                                             //
          smallestFraction = totalByteCount / 10;            // bufferangka-60 dikarenakan APP INVENTOR tidak bisa mengirim data langsung dalam bentuk byte //
          readFirstByte = false;                             // sehingga data angka diubah menjadi printable char terlebih dahulu dengan basis 60, sesuai   //
          box2.clear();                                      // angka jam, dimulai dari ascii number 60 (atau char <) sebagai 0 dst dan selanjutnya dari    //
          box3.clear();                                      // sisi arduino dikonversi kembali menjadi byte yang sesuai dengan dikurangi 60                //
          box2.print("uploading.");                          //---------------------------------------------------------------------------------------------//
        }
        if (bufferangka == 126) {                            //---------------------------------------------------------------------------------------------//
          box3.clear();                                      // penjelasan 02 :                                                                             //
          box3.print(F("100%"));                             // INT 126 (char ~) digunakan untuk stopper Serial.read karena APP INVENTOR hanya bisa         //
          delay(1500);                                       // mengirimkan data berupa printable char                                                      // 
          box2.clear();                                      //---------------------------------------------------------------------------------------------//
          box3.clear();
          box2.print(F("upload"));
          box3.print(F("completed"));
          delay(3000);
          box2.clear();
          box3.clear();
          box2.print(F("please"));
          box3.print(F("restart."));
          Serial.print(F("upload completed"));
          while (true) {}
        }                                                                                                 //--------------------------------------------------//
                                                                                                          // penjelasan 03                                    //
        if ((x >= 0 && x < 10) || ((x - 34) % 27 == 0) || ((x - 35) % 27 == 0) || ((x - 36) % 27 == 0)) {  // untuk mengisi address EEPROM 1 sd 9,             //
          EEPROM.update(address + x, bufferangka - 60);                                                   // serta data jam, menit dan detik lomba            //
        }                                                                                                 // digunakan -60, keterangan lihat di penjelasan 01 //
        else {                                                                                            //--------------------------------------------------//
          EEPROM.update(address + x, bufferangka);
        }
        box3.clear();
        if ((x / smallestFraction * 10) < 10) {
        box3.print(F("  "));
        }
        else if ((x / smallestFraction * 10) < 100) {
        box3.print(F(" "));
        }
        box3.print(x / smallestFraction * 10); box3.print(F("%"));
        Serial.print(x/smallestFraction*10);Serial.print(F("%"));
        x += 1;
        delay(5);
      }
    }
  }

  Wire.begin();
  clock.begin();
  setSyncProvider(syncProvider);    // sinkronisasi TimeLib dengan DS3231
  if (timeStatus() != timeSet)
    box.print(F("Unable to sync with the RTC"));
  totalRow = EEPROM.read(0);                 // ambil data panjang file untuk cek akhir perlombaan
  if (EEPROM.read(1) == 1)  {       // resuming event if any
    resumeEvent = true;
    showMessage = 5;
    row = EEPROM.read(2);
    Serial.print(EEPROM.read(6)); Serial.print(F("\t")); Serial.print(EEPROM.read(7)); Serial.print(F("\t")); Serial.print(EEPROM.read(8)); Serial.print(F("\t")); Serial.print(EEPROM.read(9)); Serial.println();
    timerStart = (EEPROM.read(6) * pow(2, 24)) + (EEPROM.read(7) * pow(2, 16)) + (EEPROM.read(8) * pow(2, 8)) + EEPROM.read(9);
    Serial.println(F("Resume Lomba"));
    Serial.print(F("Baris ke : ")); Serial.println(row);
    Serial.print(F("Waktu Mulai :")); Serial.println(timerStart);
    Serial.println(F("-----------------------------------------"));
  }
  thisTime = (unsigned long) now();              // internal time keeping, gunakan data waktu dari TimeLib
  // send signal to app to enable start timer button

}

I use arduino pro mini and HC06 bluetooth module, also FTDI232 and USB-TTL.
Programs for sending data by cable is using Processing and for sending by bluetooth is using App Inventor.

I don’t think that programs work unwell since its OK when using USB-TTL.

Any information and help is much appreciated.

Kind Regards,

Ari.

EEPROM.update(address + x, bufferangka - 60);

bufferangka is an int, so takes 2 bytes of storage

However, you only ever increment x by 1 in the code so second and subsequent updates to address + x will overwrite one of the bytes of the int value previously written.

To make things worse you use EEPROM.read() in your code which only retrieves a byte anyway rather than an int.

Does bufferangka need to be an int or could it be a byte ?

UKHeliBob:

EEPROM.update(address + x, bufferangka - 60);

bufferangka is an int, so takes 2 bytes of storage

However, you only ever increment x by 1 in the code so second and subsequent updates to address + x will overwrite one of the bytes of the int value previously written.

To make things worse you use EEPROM.read() in your code which only retrieves a byte anyway rather than an int.

Does bufferangka need to be an int or could it be a byte ?

My post shouldn't be here
I should examine harder before I post.

For bluetooth I found my problem lying on my App Inventor side, while for FT323, I just remove DTR cable and data well received by Arduino.

Plus all you've told above, I now realize how messy my sketch is. :smiley: :smiley:

Still need a lot of learning and a work hard.

Thank you.