TFT SPI ST7735B, Chars errors

Hello!

Im trying to make a scrolling graph displaying the humidity and temp.
But the string displaying the temp and humidity is not displaying the proper chars.
Can anyone help me?
Please see the attached image.

Edit: The graph is displayed incorrectly. Every other spot was skipped. Could this have with the other display faults to do?

#include <dht.h>


#include <TFT.h>  // Arduino LCD library
#include <SPI.h>
#include <Wire.h>

dht DHT;

 
 // pin definition for the Uno

#define sclk 52  // Don't change
#define mosi 51  // Don't change
#define CS   9
#define DC   8
#define RESET 7 

TFT TFTscreen = TFT(CS, DC, RESET);
#define DHT21_PIN 6
int Ctemp = 0;
int RF = 0;
char txtBuff[5];



  //I define TFTscreen.width() as wTFT
int wTFT = TFTscreen.width();  // or wTFT=160 for my TFT screen

  //I define TFTscreen.height() as hTFT
int hTFT = TFTscreen.height(); // or hTFT=120 for my TFT screen

int count;
int sensorArray[161];
int sensorArray2[161];

void setup(){
  // initialize the serial port
  Serial.begin(9600);

  // initialize the display
  TFTscreen.begin();

  // set TFT background colour to black
  TFTscreen.background(0, 0, 0);

  TFTscreen.setTextSize(1);

  //initialize the array by zeroing all its elements
  for (int count=0; count<=159; count++)  //counts up from 0 to 159
   {
    sensorArray[count] = 0; //this 'zeros' all array elements(?)
    sensorArray2[count] = 0; //this 'zeros' all array elements(?)
   }

}
  
void loop() {


  int chk = DHT.read21(DHT21_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
                
    //Serial.print("OK,\t"); 
    break;
    case DHTLIB_ERROR_CHECKSUM: 
                //lcd.print("Error chksum");
    break;
    case DHTLIB_ERROR_TIMEOUT: 
                //lcd.print("Error timeout"); 
    break;
    default: 
                //lcd.print("Error unknown"); 
    break;
  }

  

  String esRF = String(RF  + "%");
  String esCtemp = String(Ctemp + (char)247 + "C");
  

  TFTscreen.stroke(0, 0, 0);   //Erase old values from screen
  esRF.toCharArray(txtBuff, 5);
  TFTscreen.text(txtBuff, 0, 0);
  esCtemp.toCharArray(txtBuff, 5);
  TFTscreen.text(txtBuff, 40, 0);

  RF = DHT.humidity;    //get new values
  Ctemp = DHT.temperature;

  String sRF = String(RF + "%");        //Add integer to string
  String sCtemp = String(Ctemp + (char)247 + "C");

  TFTscreen.stroke(0, 255, 0);      //Print new values on screen
  sRF.toCharArray(txtBuff, 5);      //Convert string to char array for display
  TFTscreen.text(txtBuff, 0, 0);
  TFTscreen.stroke(0, 0, 255);
  sCtemp.toCharArray(txtBuff, 5);
  TFTscreen.text(txtBuff, 40, 0);
  
  int drawRF = map(RF, 0, 100, 0, 62);
  int drawC = map(Ctemp, -20, 60, 65, 127);

  
  sensorArray[0] = drawRF;
  sensorArray2[0] = drawC; 

  for ( int count = 1; count <= wTFT; count++ )  //this counts up from 1 to 160
      {
         

          TFTscreen.stroke(0, 0, 0);
          TFTscreen.point(count, sensorArray[count]);  //Erase prev. point

          TFTscreen.point(count, sensorArray2[count]);  //Erase prev. point
          
          TFTscreen.stroke(0, 255, 0);
          TFTscreen.point(count, sensorArray[count-1]);

          TFTscreen.stroke(0, 0, 255);
          TFTscreen.point(count, sensorArray2[count-1]);
   }  
     
  for (count=wTFT; count>=2; count--) // count down from 160 to 2 
   {
      sensorArray[count-1] = sensorArray[count-2];  //Shift history data downwards.
      sensorArray2[count-1] = sensorArray2[count-2]; 
   }
  delay(100);
  
}

Iv changed to Adafruit ST7735. Still same result.
TFTscreen.print("test")
works fine... Can not understand why I get all this corrupt data on the screen.

Hi

There could be serveral reasons:

  • The small upper circle is not there in the font
  • There is a confusion between UTF8 encoding (Arduino IDE encodes with UTF8, but UTF8 is not suported by print)
  • It is not clear what the String class does with “+ (char)value +”

My suggestions are:

  • Do not use “String” class. I am sure you can use .print() for your output only
  • Prefer “\x” instead of (char).
  • Ensure, that the font includes the upper circle (degree symbol). If this is not there in the Adafruit lib, consider ucglib (installable from the library manager of the IDE). All “full” fonts from ucglib should include the degree symbol. See here for example.

Oliver

Edit: From looking at the ucglib font map, i just noticed, that the degree symbol is at positon 176, whereas the symbol at 247 is indeed the division symbol which is also shown on you attached picture. So maybe the glyph code is wrong in your code.

Thanks for the reply!!!

Som changes… Please look at the TFTscreen.print

Still get the corrupt chars just trying to print an int value.

Look at the attached picture

#include <Adafruit_GFX.h>
#include <gfxfont.h>

#include <Adafruit_ST7735.h>

#include <dht.h>


//#include <TFT.h>  // Arduino LCD library
#include <SPI.h>
#include <Wire.h>

dht DHT;

 
 // pin definition for the Uno

#define sclk 76  // Don't change
#define mosi 75  // Don't change
#define CS   9
#define DC   8
#define RESET 7 



Adafruit_ST7735 TFTscreen = Adafruit_ST7735(CS,  DC, RESET);
//TFT TFTscreen = TFT(CS, DC, RESET);
#define DHT21_PIN 6
int Ctemp = 0;
int RF = 0;
char txtBuff[5];



  //I define TFTscreen.width() as wTFT
int wTFT = TFTscreen.width();  // or wTFT=160 for my TFT screen

  //I define TFTscreen.height() as hTFT
int hTFT = TFTscreen.height(); // or hTFT=120 for my TFT screen

int count;
int sensorArray[161];
int sensorArray2[161];

void setup(){
  // initialize the serial port
  Serial.begin(9600);

  // initialize the display
  TFTscreen.initR(INITR_BLACKTAB);

  // set TFT background colour to black
  //TFTscreen.background(0, 0, 0);
  TFTscreen.fillScreen(0x0000);
  //TFTscreen.setTextSize(2);

  //initialize the array by zeroing all its elements
  for (int count=0; count<=159; count++)  //counts up from 0 to 159
   {
    sensorArray[count] = 0; //this 'zeros' all array elements(?)
    sensorArray2[count] = 0; //this 'zeros' all array elements(?)
   }

}
  
void loop() {


  int chk = DHT.read21(DHT21_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
                
    //Serial.print("OK,\t"); 
    break;
    case DHTLIB_ERROR_CHECKSUM: 
                //lcd.print("Error chksum");
    break;
    case DHTLIB_ERROR_TIMEOUT: 
                //lcd.print("Error timeout"); 
    break;
    default: 
                //lcd.print("Error unknown"); 
    break;
  }

  

  String esRF = String(RF  + "%");
  String esCtemp = String(Ctemp + (char)247 + "C");
  

  //TFTscreen.stroke(0, 0, 0);   //Erase old values from screen
  esRF.toCharArray(txtBuff, 5);
  //TFTscreen.text(txtBuff, 0, 0);
  esCtemp.toCharArray(txtBuff, 5);
  //TFTscreen.text(txtBuff, 40, 0);

  RF = DHT.humidity;    //get new values
  Ctemp = DHT.temperature;

  String sRF = String(RF + "%");        //Add integer to string
  String sCtemp = String(Ctemp + (char)247 + "C");

  //TFTscreen.stroke(0, 255, 0);      //Print new values on screen
  //sRF.toCharArray(txtBuff, 5);      //Convert string to char array for display
  TFTscreen.setTextColor(ST7735_GREEN);
  TFTscreen.setCursor(0, 0);
  TFTscreen.print("Humid");
  TFTscreen.setCursor(0, 12);
  TFTscreen.print(RF);
  
  //sCtemp.toCharArray(txtBuff, 5);
  TFTscreen.setTextColor(ST7735_RED);
  TFTscreen.setCursor(40, 0);
  TFTscreen.print("Temp");
  TFTscreen.setCursor(40, 12);
  TFTscreen.print(Ctemp);
  
  int drawRF = map(RF, 100, 0, 0, 62);
  int drawC = map(Ctemp, -20, 60, 65, 127);

  
  sensorArray[0] = drawRF;
  sensorArray2[0] = drawC; 

  for ( int count = 1; count <= wTFT; count++ )  //this counts up from 1 to 160
      {
         

          //TFTscreen.stroke(0, 0, 0);
          TFTscreen.drawPixel(sensorArray[count], count, ST7735_BLACK);  //Erase prev. point
          TFTscreen.drawPixel(sensorArray2[count], count, ST7735_BLACK);  //Erase prev. point


          //TFTscreen.point(count, sensorArray2[count]);  //Erase prev. point
          
          //TFTscreen.stroke(0, 255, 0);
          TFTscreen.drawPixel(sensorArray[count-1], count, ST7735_GREEN);

          //TFTscreen.stroke(0, 0, 255);
          TFTscreen.drawPixel(sensorArray2[count-1], count, ST7735_RED);
   }  
     
  for (count=wTFT; count>=2; count--) // count down from 160 to 2 
   {
      sensorArray[count-1] = sensorArray[count-2];  //Shift history data downwards.
      sensorArray2[count-1] = sensorArray2[count-2]; 
   }
  delay(100);
  
}

 TFTscreen.setTextColor(ST7735_GREEN);
  TFTscreen.setCursor(0, 0);
  TFTscreen.print("Humid");
  TFTscreen.setCursor(0, 12);
  TFTscreen.print((float)DHT.humidity);
  
  //sCtemp.toCharArray(txtBuff, 5);
  TFTscreen.setTextColor(ST7735_RED);
  TFTscreen.setCursor(40, 0);
  TFTscreen.print("Temp");
  TFTscreen.setCursor(40, 12);
  TFTscreen.print((float)DHT.temperature);

This do not work either

Solved…
For some reason… When I add TFTscreen.fillScreen(0x0000); every loop in main loop then the text displays properly…
the refresh time for the code will be set to about 1 hour so it will work. Even if its ugly…