Page 1 of 1

Strange errors with TFT_eSPI

Posted: Wed Jun 02, 2021 1:40 pm
by Rubbernose
I want to show values an an ESP32 with TFT-Display. The values are stored in an array. The serial monitor shows the correct values, but the TFT display not. all examples are working propperly.

In my code are two errors!!!

1) on every 4th row is a huge value. Why?

If the part in the setup is uncommented, this error disappears.

2) the value on the TFT freezes
Why???

Code: Select all

int Drehmom[10];
int DrehmomPointer;

#include <TFT_SB_1.h>            //  own pins
TFT_eSPI tft = TFT_eSPI();       // by Bodemer

void setup() {
  tft.init();
  tft.fillScreen(TFT_BLACK);
  Serial.begin(57600);
/*
Drehmom[0]=0;
Drehmom[1]=0;
Drehmom[2]=0;
Drehmom[3]=0;
Drehmom[4]=0;  // 1061177988
Drehmom[5]=0;
Drehmom[6]=0;
Drehmom[7]=0;
Drehmom[8]=0;
Drehmom[9]=0;
*/
}

void loop() {
   
      DrehmomPointer++;
      if(DrehmomPointer > 8) {DrehmomPointer=1;}
             
      tft.drawNumber(DrehmomPointer, 100, 80, 6);

      //Drehmom[DrehmomPointer] = 5;     // stopps at 3
      //Drehmom[1] = 5;                  // ok
      //Drehmom[2] = 5;                  // ok
      //Drehmom[3] = 5;                  // stopps at 1
      //Drehmom[4] = 5;                  // ok
      //Drehmom[5] = 5;                  // ok
      //Drehmom[6] = 5;                  // ok
      //Drehmom[7] = 5;                  // ok
      Drehmom[8] = 5;                  // ok
      
      Drehmom[0] = Drehmom[1] + Drehmom[2] + Drehmom[3] + Drehmom[4] + Drehmom[5] + Drehmom[6] + Drehmom[7] + Drehmom[8]  ;
      
      Serial.print(" Pointer: ");Serial.print  (DrehmomPointer); Serial.print("\t");
      Serial.print(" Drehmom: ");Serial.println(Drehmom[DrehmomPointer]); 
      delay(50);
}
I changed the declaration as long, Pointer as Byte, instead drawNumber i tried drawString(String...). Without success.
Any ideas?[/Codebox]

Re: Strange errors with TFT_eSPI

Posted: Thu Jun 03, 2021 1:49 am
by ESP_Sprite
If anything, you declare Drehmom to have 10 entries (drehmom[0] to drehmom[9]), but then set entries 0 to 10.

Re: Strange errors with TFT_eSPI

Posted: Fri Jun 04, 2021 10:10 am
by Rubbernose
Yes, sorry for the [10]. That was from earlier experiments.
My solution was to change the order from:
int Drehmom[10];
int DrehmomPointer;

to
int DrehmomPointer;
int Drehmom[10];

Now it works, but i don't know why...

Re: Strange errors with TFT_eSPI

Posted: Sat Jun 05, 2021 7:49 am
by ESP_Sprite
Still sounds like you're overwriting Drehmom[10], which is out of bounds of the array as you defined it. By changing the order, you're overwriting something else instead, which is not immediately obvious but will lead you to problems later.

Re: Strange errors with TFT_eSPI

Posted: Sat Jun 05, 2021 10:23 am
by Rubbernose
No, ...