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);
}

