Changing a sketch to work in the UTFT Libary "2.8" LCD display")

Hey everyone, Ive manged to get my 2.8" LCD TFT display working. and ive set the code ready to merge it with a basic temp and humid sketch DHT11.

But im not sure how to merge the serial.print to GLCD.print as it keeps coming up with errors.

Can anyone help me merge from the temp sketch to the LCD sketch i have prepared to show the temp and humid in the space provided.

Thank you

Temperature sketch

#include "DHT.h"

DHT dht;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");

  dht.setup(2); // data pin 2
}

void loop()
{
  delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();

  Serial.print(dht.getStatusString());
  Serial.print("\t");
  Serial.print(humidity, 1);
  Serial.print("\t\t");
  Serial.print(temperature, 1);
  Serial.print("\t\t");
  Serial.println(dht.toFahrenheit(temperature), 1);
}

LCD SKETCH thats needs glcd.print added

#include <UTFT.h>
#include "DHT.h"
DHT dht;

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];


UTFT myGLCD(ITDB28,A5,A4,A3,A2);   
  


void setup()
{
  myGLCD.InitLCD();

  myGLCD.clrScr();
    dht.setup(2);
}

void loop()
{
 
 
 delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();
 
 
 
 
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);

  myGLCD.setFont(BigFont);
  myGLCD.print("TEMPERATURE", CENTER, 2);
   
  myGLCD.setFont(BigFont);
  myGLCD.print(" !\"#$%&#", CENTER, 60); ,--- ////temp printed in the ""
  
  myGLCD.setFont(BigFont);
  myGLCD.print("HUMIDITY", CENTER, 135);
  
   myGLCD.setFont(BigFont);
  myGLCD.print("sdgsdg", CENTER, 180); //// Humid printed in the ""

  while(1) {};
}

Thanks to anyone that can help :smiley:

But im not sure how to merge the serial.print to GLCD.print as it keeps coming up with errors.

But, the errors are going to remain a secret? Not if you want help.

Ops, sorry i forgot.

Temp_and_humid_LCD_display.ino: In function 'void loop()':
Temp_and_humid_LCD_display:32: error: no matching function for call to 'UTFT::print(const char*)'
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:140: note: candidates are: void UTFT::print(char*, int, int, int)
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:141: note:                 void UTFT::print(String, int, int, int)
Temp_and_humid_LCD_display:43: error: no matching function for call to 'UTFT::print(float&, int, int, int)'
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:140: note: candidates are: void UTFT::print(char*, int, int, int)
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:141: note:                 void UTFT::print(String, int, int, int)

and the sketch the error came from.

#include <UTFT.h>
#include "DHT.h"
DHT dht;

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];


UTFT myGLCD(ITDB28,A5,A4,A3,A2);   
  


void setup()
{
  myGLCD.InitLCD();

  myGLCD.clrScr();
    dht.setup(2);
}

void loop()
{
 
 
 delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();
 myGLCD.print(dht.getStatusString());
 
 
 
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);

  myGLCD.setFont(BigFont);
  myGLCD.print("TEMPERATURE", CENTER, 2);
   
  myGLCD.setFont(BigFont);
  myGLCD.print(humidity, 1, CENTER, 135); ////temp printed in the ""
  
  myGLCD.setFont(BigFont);
  myGLCD.print("HUMIDITY", CENTER, 135);
  
   myGLCD.setFont(BigFont);
  myGLCD.print("sdgsdg", CENTER, 180); //// Humid printed in the ""

  while(1) {};
}

sorry and thanks :slight_smile:

Is there some part of the error messages that you don't understand? Serial.print() and UTFT.print() are not interchangeable functions. The serial output doesn't care where to print. The UTFT does.

But im not using serial.print cause at the moment my other sketch prints to serial,
thats just serial.print(humidity,1);
but when i try to add GLCD:print(humidity, 1, center, 70);

Temp_and_humid_LCD_display.ino: In function 'void loop()':
Temp_and_humid_LCD_display:43: error: expected `)' before numeric constant
Temp_and_humid_LCD_display:43: error: no matching function for call to 'UTFT::print(float&, int, int)'
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:140: note: candidates are: void UTFT::print(char*, int, int, int)

and if i just put

Serial.print(dht.getStatusString());

that in to my UTFT sketch and change it to myGLCD.print(dht.getStatusString());

i recieve

Temp_and_humid_LCD_display.ino: In function 'void loop()':
Temp_and_humid_LCD_display:34: error: no matching function for call to 'UTFT::print(const char*)'
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:140: note: candidates are: void UTFT::print(char*, int, int, int)
C:\Users\mhsec\Desktop\Arduino-1.0.5\Arduino\libraries\UTFT/UTFT.h:141: note:                 void UTFT::print(String, int, int, int)

how do i get it so it prints the temperature on my LCD display.

Im guessing i tell it where to print by adding the( , Center, 70)

Please tell me if im going about this the wrong way, im just trying to learn and have no clue :confused:

Im guessing i tell it where to print by adding the( , Center, 70)

Sort of. The ", Center, 70" bit does. The () are required for any function call.

The "problem" is that the UTFT class you are using is pretty dumb. It does not know how to print a float. So, you must convert the float to a string first, using dtostrf().

Thanks for the reply,

I would have no clue how to do that as i am extremely new to all this.

I would just like it so i can have the temp and humid sensor on my wall.

Can you explain a bit more on how i would to this, it would be much appreciated.

Thank you, and cheers for your help :smiley:

Can you explain a bit more on how i would to this

Sure. But, so can google. And google is endlessly patient about providing examples.

I would have no clue how to do that as i am extremely new to all this.

Getting other people to write your code is not how to correct that situation.

hmm seem to be stuck again :confused:

#include <UTFT.h>
#include "DHT.h"
DHT dht;

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

 float h = dht.getHumidity();
  float t = dht.getTemperature();

char tempF[6];
dtostrf(t, 6 2, tempF);
UTFT myGLCD(ITDB28,A5,A4,A3,A2);   
  


void setup()
{
  myGLCD.InitLCD();
Serial.begin(9600);
  myGLCD.clrScr();
    dht.setup(2);
}

void loop()
{
 
 
 delay(dht.getMinimumSamplingPeriod());
 Serial.print(dht.getStatusString());
 
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);

  myGLCD.setFont(BigFont);
  myGLCD.print("TEMPERATURE", CENTER, 2);
   
  myGLCD.setFont(BigFont);
    myGLCD.print(h, 1), CENTER, 70);
  
  myGLCD.setFont(BigFont);
  myGLCD.print("HUMIDITY", CENTER, 135);
  
   myGLCD.setFont(BigFont);
  myGLCD.print("sdgsdg", CENTER, 180); //// Humid printed in the ""

  while(1) {};
}

PaulS:
The "problem" is that the UTFT class you are using is pretty dumb. It does not know how to print a float. So, you must convert the float to a string first, using dtostrf().

Another solution would be to try reading the manual (included in the UTFT download) where one can find useful information, like how to print floats with printNumF()...

/Henning

hmm seem to be stuck again

Well, the solution is obvious. Or, it might be if you described what your problem is now.