Examples > TFT

Esplora TFT Temperature Display

This example for the Esplora with an Arduino TFT screen reads the temperature with the onboard thermisistor, and prints it out on screen.

Hardware Required

  • Arduino Esplora
  • Arduino TFT screen

Circuit

Attach the TFT screen to the socket on your Esplora, with the label "SD Card" facing up.

Code

To use the screen you must first include the SPI and TFT libraries. Don't forget to include the Esplora library as well.

#include <Esplora.h>
#include <TFT.h>
#include <SPI.h>

To update the screen with text, you'll need to store dynamic content in a char array.

char tempPrintout[3];

In setup(), initialize the screen and clear the background. Set the color for the font with stroke(), and write any static text to the screen. In this case, you'll write "Degrees in C :". This will stay at the top of the screen and not change as long as the sketch runs. Before entering the loop(), set the text size so you can really see the temperature stand out.

void setup(void) {
  EsploraTFT.begin();
  EsploraTFT.background(0,0,0);

  EsploraTFT.stroke(200,20,180);
  EsploraTFT.setTextSize(2);
  EsploraTFT.text("Degrees in C :\n ",0,0);
  EsploraTFT.setTextSize(5);
}

In loop(), read the temperature in Celsius with Esplora.readTemperature(DEGREES_C), storing it in a string. Convert the string content to a char array, storing it in the global array you declared int he beginning of your program.

void loop() {

  String temperature = String(Esplora.readTemperature(DEGREES_C));
  temperature.toCharArray(tempPrintout, 3);

Set the text color (this would be a good place to change the color of the text depending on the value from the thermometer), and print it to the screen below the static text.

EsploraTFT.stroke(255,255,255);
  EsploraTFT.text(tempPrintout, 0, 30);

Wait for one second, then erase the text you just wrote, so you can update it in the next run through loop().

delay(1000);
  // erase the text for the next loop
  EsploraTFT.stroke(0,0,0);
  EsploraTFT.text(tempPrintout, 0, 30);
}

The complete sketch is below :

SORRY, There is an error at our code repository, please inform to web@arduino.cc