Strange errors with TFT_eSPI

Rubbernose
Posts: 5
Joined: Sat Oct 03, 2020 4:43 pm

Strange errors with TFT_eSPI

Postby Rubbernose » Wed Jun 02, 2021 1:40 pm

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]
Last edited by Rubbernose on Sat Jun 05, 2021 10:24 am, edited 1 time in total.

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: Strange errors with TFT_eSPI

Postby ESP_Sprite » Thu Jun 03, 2021 1:49 am

If anything, you declare Drehmom to have 10 entries (drehmom[0] to drehmom[9]), but then set entries 0 to 10.

Rubbernose
Posts: 5
Joined: Sat Oct 03, 2020 4:43 pm

Re: Strange errors with TFT_eSPI

Postby Rubbernose » Fri Jun 04, 2021 10:10 am

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...

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: Strange errors with TFT_eSPI

Postby ESP_Sprite » Sat Jun 05, 2021 7:49 am

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.

Rubbernose
Posts: 5
Joined: Sat Oct 03, 2020 4:43 pm

Re: Strange errors with TFT_eSPI

Postby Rubbernose » Sat Jun 05, 2021 10:23 am

No, ...

Who is online

Users browsing this forum: No registered users and 121 guests