0

2.8 tft lcd how to display
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

2.8 tft lcd how to display

by everone on Mon Apr 11, 2016 3:42 pm

Hi,

so i have the 2.8 tft lcd shield with SD v2 and i dont know how to write code to use with it.
i want to make buttons and pages and display from my temp sensors and such.
where do i come up with say a primer on code for the device and how to use it.
ive tried to jut use code ive found on other project but it doesnt seem to work?
????????
Please help!!!!!!!

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by asteroid on Mon Apr 11, 2016 11:52 pm

Perhaps you can use the following to help get you started.

Code: Select all | TOGGLE FULL SIZE
/*
 Demonstrates button for use on a 2.8" TFT Touch Shield v2.(capacitive)
 Any of the four screen rotations may be used.
*/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>

// Default values for Adafruit shield v2.
#define TFT_DC 9
#define TFT_CS 10

// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// Rotations 0,2 = portrait  : 0->USB=right,upper : 2->USB=left,lower
// Rotations 1,3 = landscape : 1->USB=left,upper  : 3->USB=right,lower
boolean ButtonOn = false;
byte rotation = 3; //(0->3)
int x, y;
TS_Point p;
 
#define FRAME_X tft.width() - 120
#define FRAME_Y tft.height() - 60
#define FRAME_W 100
#define FRAME_H 50

#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W (FRAME_W/2)
#define REDBUTTON_H FRAME_H

#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
#define GREENBUTTON_Y FRAME_Y
#define GREENBUTTON_W (FRAME_W/2)
#define GREENBUTTON_H FRAME_H

void drawFrame()
{
  tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
}

void redBtn()
{
  tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
  tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
  drawFrame();
  tft.setCursor(GREENBUTTON_X + 12 , GREENBUTTON_Y + (GREENBUTTON_H/2) - 6);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.println("ON");
  ButtonOn = false;
}

void greenBtn()
{
  tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN);
  tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE);
  drawFrame();
  tft.setCursor(REDBUTTON_X + 8 , REDBUTTON_Y + (REDBUTTON_H/2) - 6);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.println("OFF");
  ButtonOn = true;
}

void setup(void)
{
  Serial.begin(9600);
  tft.begin();
  if (!ctp.begin()) {
    Serial.println("Unable to start touchscreen.");
    while (1);
  }

  tft.fillScreen(ILI9341_BLUE);
  tft.setRotation(rotation);
  redBtn();
}

void loop()
{
  if (! ctp.touched()) { 
    return;
  }
 
  p = ctp.getPoint();

 switch (rotation) {
  case 0:
   x = 240 - p.x;
   y = 320 - p.y;
  break;
  case 1:   // p.x, p.y reversed
   x = 320 - p.y;
   y = p.x;
  break;
  case 2:
   x = p.x;
   y = p.y;
  break;
  case 3:  // p.x, p.y reversed
   x = p.y;
   y = 240 - p.x;
  break;
 }

while (ctp.touched())
  {   
    if (ButtonOn)
    {
      if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
        if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
          Serial.println("Red btn hit");
          redBtn();
        }
      }
    }
    else //Button is off (ButtonOn == false)
    {
      if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
        if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
          Serial.println("Green btn hit");
          greenBtn();
        }
      }
    }
  } 
}

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8 tft lcd how to display

by everone on Tue Apr 12, 2016 1:29 am

thank you
i will look at it.

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by everone on Wed Apr 13, 2016 12:57 am

Thank you

That has gotten me off on a start. i am having difficulty finding out the next phase of displaying my information to the screen though.
see my sketch code.
what i want to do is refresh the pH value. if i add a delay and insert the code into the void loop() it refreshes the whole screen.
once i put pH in a box i want it to refresh in hurts if possible not seconds.
next is there a way to separate code into sections so it is one easier to read and two i can add different attributes to different sections?
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_FT6206.h>

// Default values for Adafruit sheild v2.
#define TFT_CS 10
#define TFT_DC 9

//The FT6202 uses hardware I2C (SCL/SDA).
Adafruit_FT6206 ctp = Adafruit_FT6206();
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

    // Rotations 0,2 = portrait  : 0->USB=right,upper : 2->USB=left,lower
    // Rotations 1,3 = landscape : 1->USB=left,upper  : 3->USB=right,lower
    byte rotation = 1; //(0->3)
    int x, y;
   


void setup() {
  // put your setup code here, to run once:
 
  // Initialize serial communication at 9600 bits per second:
     Serial.begin(9600);
     tft.begin();
     ctp.begin();
     
}

void loop() {
  // Put your main code here, to run repeatedly:
 
  // Read the input on analog pin 0:
    double sensorValue = analogRead(A8);     // Get current sensorValue between 0-1000
    double Voltage = sensorValue*(5.0/1024.0);     // Convert sensorValue to voltage 0-5v
    double pH = (Voltage*3.56)-1.889;     // Convert voltage to pH
     
  // print out the value you read:
    Serial.println("SensorValue");
    Serial.println(sensorValue);     // Print sensorValue to serial
    Serial.println("Voltage");
    Serial.println(Voltage);     // Print Votage to serial
    Serial.println("pH");
    Serial.println(pH);     // Print pH to serial
    delay(4000);        // Delay in-between reads for stability

    tft.fillScreen(ILI9341_BLACK);
    tft.setRotation(rotation);
    tft.setCursor(0,0);
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(2);
    tft.println("Aqua Science pH Control v0");

    tft.setCursor(0,20);
    tft.setTextSize(2);
    tft.println("pH");

    tft.setCursor(30,20);
    tft.setTextSize(2);
    tft.println(pH);
 
}
Last edited by franklin97355 on Thu Apr 14, 2016 4:00 pm, edited 1 time in total.
Reason: Added missing [code] tags

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by asteroid on Wed Apr 13, 2016 12:14 pm

Suggestions:
1) Add a loop timer for sampling frequency. You can control the frequency by changing the constant ‘LoopTime’.
2) Use of .setTextColor() with separate colors for text and background will remove flash (as long as all pH strings are same length).
3) Learn to use functions to separate code into sections.
4) Use code blocks to post code to forum. (Paste code between ‘</>’ selected from menu bar )

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_FT6206.h>

// Default values for Adafruit sheild v2.
#define TFT_CS 10
#define TFT_DC 9

//The FT6202 uses hardware I2C (SCL/SDA).
Adafruit_FT6206 ctp = Adafruit_FT6206();
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// Rotations 0,2 = portrait : 0->USB=right,upper : 2->USB=left,lower
// Rotations 1,3 = landscape : 1->USB=left,upper : 3->USB=right,lower
byte rotation = 1; //(0->3)

// Display rectangle
#define DISPLAY_X 100
#define DISPLAY_Y 100
#define DISPLAY_W 100
#define DISPLAY_H 50

unsigned long LoopTimer = 0;
const int LoopTime = 100;
int sensorValue = 0;

void showpH(float pHValue)
{
 tft.setCursor(DISPLAY_X+20, DISPLAY_Y+12);
 tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
 tft.setTextSize(3);
// ** sprintf for floats not recommended ** //
// *** Use this instead *** //
 String str(pHValue, 3);  // <--- number of decimals
 tft.print(str);
}

void drawHeader()
{
 tft.setCursor(0,0);
 tft.setTextColor(ILI9341_WHITE);
 tft.setTextSize(2);
 tft.println("Aqua Science pH Control v0");

 tft.setCursor(DISPLAY_X-30,DISPLAY_Y+12);
 tft.setTextSize(3);
 tft.println("pH");
}
 
void setup()
{
 Serial.begin(9600);
 tft.begin();
 ctp.begin();
 tft.fillScreen(ILI9341_BLACK);
 tft.setRotation(rotation);
 drawHeader();
}

void loop() {
 
 if (millis() > LoopTimer)
 {
 LoopTimer += LoopTime;
 // Read the input on analog pin 8:
 sensorValue = analogRead(A8); // Get current sensorValue between 0-1000
 float Voltage = sensorValue*(5.0/1024.0); // Convert sensorValue to voltage 0-5v
 float pH = (Voltage*3.56)-1.889; // Convert voltage to pH
 showpH(pH);
// Could be removed later
 Serial.print("SensorValue = ");
 Serial.println(sensorValue); // Print sensorValue to serial
 Serial.print("Voltage = ");
 Serial.println(Voltage); // Print Votage to serial
 Serial.print("pH = ");
 Serial.println(pH); // Print pH to serial
 }

}

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8 tft lcd how to display

by everone on Wed Apr 13, 2016 8:08 pm

Thank you for this and the tips. Ill look into it and see what I can gather from it. It works well but I need to understand the why and how it works. That's the most important thing for me. I am curious right off why you used float instead of double. Aren't they the same on Arduino?

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by asteroid on Wed Apr 13, 2016 10:21 pm

>I am curious right off why you used float instead of double. Aren't they the same on Arduino?

Habit, I guess. Why ask for more than you need? Each byte is precious on these small systems. However, you are correct; they both use up 32 bits (4 bytes) on Arduino (except for Due which uses 64 bits for double). I don't believe that the two requirements are the same on other platforms (i.e. one is 32 bit, the other is 64 bit). Floats have 6-7 digits of precision, which should be adequate for your purposes. You could try it both ways and see if it makes any difference in your readings.

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8 tft lcd how to display

by everone on Thu Apr 14, 2016 5:29 am

I do realize the difference between the two pertaining to other systems. I tested against the two and don't seem to be getting any different readings. So for the Arduinos sake I guess there is no real difference in value for me. But I'm not going to mess with it.
Thanks again.

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by everone on Wed Jan 16, 2019 7:34 pm

So im opening this back up. im still looking to implement buttons in this sketch.
Code: Select all | TOGGLE FULL SIZE
 *  Im using double in this sketch to gain more precition
 */



//
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// Color definitions
#define BLACK    0x0000
#define BLUE     0x001F
#define RED      0xF800
#define GREEN    0x07E0
#define CYAN     0x07FF
#define MAGENTA  0xF81F
#define YELLOW   0xFFE0
#define WHITE    0xFFFF

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);








void setup() {

  // Begin Serial Comm
  Serial.begin(9600);
  Serial.println("ILI9341 Test!");

  //Begin TFT
  tft.begin();

  // Read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);


  //set screen rotation
  tft.setRotation(1);
 
  //fill screen black
  tft.fillScreen(BLACK);
 
  //set text wrap
  tft.setTextWrap(true);

  // Display text
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.println("Hello World!");

  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.println("Welcome to the first");

  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println("Version of our Watering");

  tft.setTextColor(BLUE);
  tft.setTextSize(4);
  tft.println("System");

  delay(4000);
 
  tft.fillScreen(BLACK);
 
 

 

}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 10:
   double sensorValue = analogRead(A10);     //get current sensorValue between 0-1000
   double Voltage = sensorValue*(5.0/1024.0);     //convert sensorValue to voltage 0-5v
   double pH = (Voltage*3.56)-1.889;     //convert voltage to pH
  // print out the value you read:
  Serial.println("SensorValue");
  Serial.println(sensorValue);
  Serial.println("Voltage");
  Serial.println(Voltage);
  Serial.println("pH");
  Serial.println(pH);

  tft.setCursor(1,0);
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.println("GrayMatter");
  tft.setCursor(25,25);
  tft.println("Growers");
 
 
  tft.drawRoundRect(210,10,90,45,25,WHITE);
  tft.setCursor(230,15);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("pH =");
  tft.setCursor(230,33);
  tft.println(pH); // print pH value 0-14

  tft.drawRoundRect(210,65,90,45,25,WHITE);
  tft.setCursor(230,70);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("Temp");
  tft.setCursor(230,88);
  tft.println("87f"); // print temp value F

  tft.drawRoundRect(210,120,90,45,25,WHITE);
  tft.setCursor(230,125);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("Hum =");
  tft.setCursor(230,143);
  tft.println("75%"); // print Humidity value %

  tft.drawRoundRect(210,175,90,45,25,WHITE);
  tft.setCursor(230,180);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("cO2 =");
  tft.setCursor(230,198);
  tft.println(pH); // print cO2 value ppm
  delay(10000);        // delay in between reads for stability
 
  tft.fillScreen(BLACK);

 
}

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by asteroid on Thu Jan 17, 2019 3:30 am

>im still looking to implement buttons in this sketch

Could you be more specific about what you are trying to do? I ran the sketch on a Mega 2560 with capacitive 2.8" shield and it ran ok. I see 4 button appearing ovals on the right hand side which is used to display data with intermittent screen redraws. These structures do not respond to touch; are you wanting to use them as push buttons in addition to displaying data?

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8 tft lcd how to display

by everone on Thu Jan 17, 2019 1:25 pm

Thank you for your response.

So in the sketch you notice that I have some data being displayed in rounded rectangles.
that's on the right hand side of the screen. on the left some text is displayed and then under that I would like to implement some buttons. they will just be on off buttons that control some relays to turn lights and fans on. so on -off buttons to turn on relays that's what im looking for.

I would like to refresh only the data and not the whole screen. and I would like to refresh the data fast enough not to get a blink.

thanks again.

everone
 
Posts: 31
Joined: Tue Mar 29, 2016 1:23 am

Re: 2.8 tft lcd how to display

by asteroid on Fri Jan 18, 2019 12:19 am

> buttons to turn on relays that's what im looking for.
>I would like to refresh only the data and not the whole screen. and I would like to refresh the data fast enough not to get a blink.

Buttons could be used to turn on devices; turning off devices will require more code ( which can be added once you understand the following ). Please ignore the C++ warnings ( which can be fixed if you're willing to go into Adafruit_GFX library ).

Code: Select all | TOGGLE FULL SIZE
/*
 *  Im using double in this sketch to gain more precision
 */
 
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Adafruit_FT6206.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// Color definitions
#define BLACK    0x0000
#define BLUE     0x001F
#define RED      0xF800
#define GREEN    0x07E0
#define CYAN     0x07FF
#define MAGENTA  0xF81F
#define YELLOW   0xFFE0
#define WHITE    0xFFFF

unsigned long LoopTimer = 0;
const int LoopTime = 5000; // This regulates reading frequency

const byte row = 2;
const byte col = 2;
#define _numBtns row*col

char outStr[6];

// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_GFX_Button btn[_numBtns];

// Rotations 0,2 = portrait  : 0->USB=right,upper : 2->USB=left,lower
// Rotations 1,3 = landscape : 1->USB=left,upper  : 3->USB=right,lower
#define _rotation  1 //(0->3)
 
char *titleStr[_numBtns] = {"Btn0","Btn1","Btn2","Btn3"};

uint16_t x, y;
 TS_Point p;
 
 void btnGrid() {
   int left, top;   
   int l = 10;   // left
   int t = 70;   // top
   int w = 80;   // width
   int h = 50;   // height
   byte hg = 20; // horizontal spacing
   byte vg = 20; // vertical spacing
   byte id = 0;
   for(byte j = 0; j < row; j++){
    for (byte i = 0; i < col; i++){
     left = l + i*(w + vg);
     top = t + j*(h + hg);
     btn[id].initButtonUL( &tft, left, top, w, h, WHITE, GREEN, BLACK,titleStr[id], 2 );
     btn[id].drawButton(false);
     id++;
    }
  }
 }

 void btnHandler(byte id)
 {
  // inverted
  btn[id].drawButton(true);
  tft.setCursor(30, 210);
  tft.setTextSize(2);
  tft.print("btn hit = ");
  tft.println(id);
  delay(400);
  // normal
  btn[id].drawButton(false);
  // erase text
  tft.fillRect( 30, 210, 150, 20, BLACK );
 }

void splashScreen() {
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  tft.println("Hello World!");

  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.println("Welcome to the first");

  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println("Version of our Watering");

  tft.setTextColor(BLUE);
  tft.setTextSize(4);
  tft.println("System");

  delay(4000);
 
  tft.fillScreen(BLACK); 
}

void setup() {
  Serial.begin(9600);
  Serial.println("ILI9341 Test!");
  tft.begin();
  if (! ctp.begin()) {  // may pass in 'sensitivity' coefficient
    Serial.println("Couldn't start FT6206 touchscreen controller");
    while (1);
  }
  // Read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
 Serial.println("===================================");
  //set screen rotation
  tft.setRotation(_rotation);
 
  //fill screen black
  tft.fillScreen(BLACK);
 
  //set text wrap
  tft.setTextWrap(true);

// Splash screen can be added later - slows down testing
  //splashScreen();
 
 // header
  tft.setCursor(1,0);
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.println("GrayMatter");
  tft.setCursor(25,25);
  tft.println("Growers");
 // pH
  tft.drawRoundRect(210,10,90,45,25,WHITE);
  tft.setCursor(230,15);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("pH =");
  // temp
  tft.drawRoundRect(210,65,90,45,25,WHITE);
  tft.setCursor(230,70);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("Temp");
  // humidity
  tft.drawRoundRect(210,120,90,45,25,WHITE);
  tft.setCursor(230,125);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("Hum =");
  // CO2
  tft.drawRoundRect(210,175,90,45,25,WHITE);
  tft.setCursor(230,180);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.println("cO2 =");
 
 btnGrid();
}

// the loop routine runs over and over again forever:
void loop() {
 
if (millis() > LoopTimer) {
   LoopTimer = LoopTimer + LoopTime;
 // read the input on analog pin 10:
   double sensorValue = analogRead(A10);     //get current sensorValue between 0-1000
   double Voltage = sensorValue*(5.0/1024.0);     //convert sensorValue to voltage 0-5v
   double pH = (Voltage*3.56)-1.889;     //convert voltage to pH
   //Serial Monitor output : print out the value you read:
  Serial.print("SensorValue: ");
  Serial.println(sensorValue);
  Serial.print("Voltage: ");
  Serial.println(Voltage);
  Serial.print("pH: ");
  Serial.println(pH);
  Serial.println("===================================");
  // Screen output (data only)
 // Left pads with zeroes
  sprintf(outStr,"%03d",pH);
  tft.setTextSize(2);
  tft.setTextColor(WHITE, BLACK);
// pH
  tft.setCursor(230,33); 
  tft.println(pH); // print pH value 0-14 
// temp
  tft.setCursor(230,88);
  tft.println("87f"); // print temp value F
// hum
  tft.setCursor(230,143);
  tft.println("75%"); // print Humidity value %
// CO2
  tft.setCursor(230,198);
  tft.println(pH); // print cO2 value ppm   
  }
   
 if (! ctp.touched()) { 
  return;
 }
 p = ctp.getPoint();

 // x,y touch coordinates depend upon screen rotation
 switch (_rotation) {
  case 0:
   x = 240 - p.x;
   y = 320 - p.y;
  break;
  case 1:   // p.x, p.y reversed
   x = 320 - p.y;
   y = p.x;
  break;
  case 2:
   x = p.x;
   y = p.y;
  break;
  case 3:  // p.x, p.y reversed
   x = p.y;
   y = 240 - p.x;
  break;
 }
 
 while (ctp.touched()) {
   // If touch occurred inside of button, do something
   for (byte z = 0; z < _numBtns; z++) {
    if(btn[z].contains(x,y)) {
      btnHandler(z);
    }
   }
  }
}

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8 tft lcd how to display

by asteroid on Fri Jan 18, 2019 1:55 am

Correction: Please REM out the following line in the loop: // sprintf(outStr,"%03d",pH); and //char outStr[6]; at the top of the file. They are not needed and do nothing as is.

asteroid
 
Posts: 295
Joined: Tue Oct 22, 2013 9:10 pm

Please be positive and constructive with your questions and comments.