Pages: [1]   Go Down
Author Topic: Changing a sketch to work in the UTFT Libary "2.8" LCD display")  (Read 1191 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Uk Arduino Member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
#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
Code:

#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-grin
Logged

Lewis Joyce

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Uk Arduino Member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ops, sorry i forgot.

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

Code:

#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 smiley
Logged

Lewis Joyce

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Uk Arduino Member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
Code:
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

Code:
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.
Logged

Lewis Joyce

London
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Uk Arduino Member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :/
Logged

Lewis Joyce

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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().
Logged

London
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Uk Arduino Member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin
Logged

Lewis Joyce

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

London
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Uk Arduino Member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm seem to be stuck again :/

Code:
#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) {};
}
Logged

Lewis Joyce

Oslo, Norway
Offline Offline
Full Member
***
Karma: 6
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
hmm seem to be stuck again
Well, the solution is obvious. Or, it might be if you described what your problem is now.
Logged

Pages: [1]   Go Up
Jump to: