Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Mirko Pavleski
Published © GPL3+

ELECROW Crow Panel 2.8-ESP32 HMI Display TFT_eSPI examples

A few simple Arduino examples of using this low-cost compact esp32 + tft touch display module

BeginnerFull instructions provided2 hours389
ELECROW Crow Panel 2.8-ESP32 HMI Display TFT_eSPI examples

Things used in this project

Hardware components

CrowPanel 2.8"-ESP32 HMI 320x240 Display SPI TFT LCD Touch Screen
×1
ds18b20 waterproof temperature sensor
×1
SparkFun RGB LED Breakout - WS2812B
SparkFun RGB LED Breakout - WS2812B
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Schematics

RGB led module schematic

...

Code

Leds Example

C/C++
..
#include "TFT_eSPI.h"
#include "TFT_eWidget.h"

TFT_eSPI tft = TFT_eSPI();
uint16_t cal[5] = { 286, 3478, 196, 3536, 2 };

const int led1 = 25;
const int led2 = 32;

ButtonWidget btn1 = ButtonWidget(&tft);
ButtonWidget btn2 = ButtonWidget(&tft);
ButtonWidget* btns[] = { &btn1, &btn2 };

void btn1_pressed(void) {
  if (btn1.justPressed()) {
    bool state = !btn1.getState();
    btn1.drawSmoothButton(state, 2, TFT_WHITE, state ? "ON" : "OFF");
    digitalWrite(led1, state ? HIGH : LOW);
  }
}

void btn2_pressed(void) {
  if (btn2.justPressed()) {
    bool state = !btn2.getState();
    btn2.drawSmoothButton(state, 2, TFT_WHITE, state ? "ON" : "OFF");
    digitalWrite(led2, state ? HIGH : LOW);
  }
}

void initButtons() {
  uint16_t w = 100;
  uint16_t h = 50;
  uint16_t x = (tft.width() - w) / 2;
  uint16_t y = tft.height() / 2 - h - 10;

  btn1.initButtonUL(x, y, w, h, TFT_WHITE, TFT_BLACK, TFT_RED, "LED1", 2);
  btn1.setPressAction(btn1_pressed);
  btn1.drawSmoothButton(false, 2, TFT_BLACK);

  y = tft.height() / 2 + 10;
  btn2.initButtonUL(x, y, w, h, TFT_WHITE, TFT_BLACK, TFT_GREEN, "LED2", 2);
  btn2.setPressAction(btn2_pressed);
  btn2.drawSmoothButton(false, 2, TFT_BLACK);
}

void handleButtons() {
  uint8_t nBtns = sizeof(btns) / sizeof(btns[0]);
  uint16_t x = 0, y = 0;
  bool touched = tft.getTouch(&x, &y);
  for (uint8_t b = 0; b < nBtns; b++) {
    if (touched) {
      if (btns[b]->contains(x, y)) {
        btns[b]->press(true);
        btns[b]->pressAction();
      }
    } else {
      btns[b]->press(false);
      btns[b]->releaseAction();
    }
  }
}

void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);

  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(TFT_BLACK);
  tft.setTouch(cal);
  
  initButtons();
}

void loop() {
  handleButtons();
  delay(50);
}

Thermometer example

C/C++
..
#include <OneWire.h> 
#include <DallasTemperature.h>
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
//#include <WiFi.h>

#define TFT_BLACK 0x0000 // black
#define ONE_WIRE_BUS 25 

OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h

void setup(void) 
{ 
  tft.init();
  tft.setRotation(3);
  Serial.begin(9600); 
  sensors.begin(); 

} 
void loop(void) 
{ 
  Serial.print(" Requesting temperatures..."); 
  sensors.requestTemperatures(); // Send the command to get temperature readings 
  Serial.println("DONE"); 
  delay (1000);

  tft.fillScreen(TFT_YELLOW);
  tft.setCursor(20, 0, 2);
  tft.setTextColor(TFT_BLUE,TFT_YELLOW);  
  tft.setTextSize(3);
  tft.println("Temperature is: "); 
  tft.setCursor(60,180, 2);
  tft.setTextColor(TFT_BLUE,TFT_YELLOW);  
  tft.setTextSize(3);
  tft.println("Degrees C ");

  tft.setCursor(40, 75, 4);
  tft.setTextColor(TFT_BLUE,TFT_YELLOW);  
  tft.setTextSize(4);
  tft.println(sensors.getTempCByIndex(0)); 

  delay(2000); 
}

Library

C/C++
Modified User_Setup.h for this display module
No preview (download only).

Credits

Mirko Pavleski

Mirko Pavleski

153 projects • 1300 followers

Comments