I am getting this error message: "exit status 1
no matching function for call to 'TFT::text(String&, int, int)'"
I am not a professional and this is my biggest project yet. What am I doing wrong? Here is my code:
//Libraries
#include <DHT.h>;
#include <TFT.h> // Hardware-specific library
#include <SPI.h>
//Constants
#define DHTPIN 6 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define CS 10
#define DC 9
#define RESET 8
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
TFT myScreen = TFT(CS, DC, RESET);
//Variables
int led = 7;
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
String screenHum = ""; //stores humidity in string
String screenTemp = ""; //stores temp in string
void setup()
{
Serial.begin(9600);
dht.begin();
myScreen.begin();
myScreen.background(0,0,0); // clear the screen with black
delay(1000); // pause for dramatic effect
}
void loop()
{
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
if(hum < 70 && temp < 27){
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
//convert float to string
screenHum.concat(hum);
screenTemp.concat(temp);
myScreen.stroke(255,0,255);
myScreen.setTextSize(0);
myScreen.setTextSize(2);
myScreen.text("Humidity:",0,0);
myScreen.text(screenHum,0,0);
myScreen.text("%",0,0);
myScreen.text(" %",0,0);
delay(2000); //Delay 2 sec.
}
I am basically just trying to make a temperature & humidity monitor using the Arduino TFT screen.
b707
November 24, 2022, 2:57pm
2
This means that you can't use myScreen.text() function with String type. Convert your Strings to c-strings first:
myScreen.text(screenHum.c_str(),0,0);
But this is not the only mistake. For example, you create your screenHum string by concatenating a moisture value with them. The first time it will give the correct result - for example "55%". But you do it in a loop without clearing the old values. So then the new humidity values will stick to the old ones and the display will not be at all what you thought : "55%66%45%..."
Thank you, the code doesn't display any errors now, but the screen is just saying 30.37 and over and over like: 30.3730.3730.37 (I deleted the humidity and % text for testing purposes)
b707
November 24, 2022, 3:05pm
4
see my suggestion at the end of post 2
Thanks! So (a part of the) modified code now looks like this:
screenHum.concat(hum);
screenTemp.concat(temp);
myScreen.stroke(255,0,255);
myScreen.setTextSize(0);
myScreen.setTextSize(2);
myScreen.text(screenHum.c_str(),0,0);
myScreen.text(" %",0,0);
screenHum = "";
screenTemp = "";
delay(2000); //Delay 2 sec.
But the old and new values are still overlapping each other.
b707
November 24, 2022, 3:09pm
6
Please show your revised code in full
I didn't change anything else, i will but i can't right now
Hi again, here is the code:
//Libraries
#include <DHT.h>;
#include <TFT.h> // Hardware-specific library
#include <SPI.h>
//Constants
#define DHTPIN 6 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define CS 10
#define DC 9
#define RESET 8
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
TFT myScreen = TFT(CS, DC, RESET);
//Variables
int led = 7;
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
String screenHum = ""; //stores humidity in string
String screenTemp = ""; //stores temp in string
void setup()
{
Serial.begin(9600);
dht.begin();
myScreen.begin();
myScreen.background(0,0,0); // clear the screen with black
delay(1000); // pause for dramatic effect
}
void loop()
{
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
if(hum < 70 && temp < 27){
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
//convert float to string
screenHum.concat(hum);
screenTemp.concat(temp);
myScreen.stroke(255,0,255);
myScreen.setTextSize(0);
myScreen.setTextSize(2);
myScreen.text(screenHum.c_str(),0,0);
myScreen.text(" %",0,0);
screenHum = "";
screenTemp = "";
delay(2000); //Delay 2 sec.
}
b707
November 24, 2022, 5:45pm
9
What do you see in the screen with this code?
thanks for the help, I fixed it, I saw the numbers overlapping but I put in the line:
myScreen.background(0,0,0);
and that fixed my issue.
b707
November 24, 2022, 6:34pm
11
so please indicate the thread as solved