ESP32-CAM TFT display and Wi-Fi trouble

genti91
Posts: 1
Joined: Thu Jun 06, 2024 3:17 pm

ESP32-CAM TFT display and Wi-Fi trouble

Postby genti91 » Thu Jun 06, 2024 3:33 pm

Hi, I am trying to use my esp32-cam with a TFT display and Wi-Fi at the same. If I use the display on its own it works fine and when I use Wi-Fi on its own it also works fine, but when I try to use them together it doesn't work.

This is my code:

Code: Untitled.cpp Select all

#include "image.h"
#include <SPI.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
#include <TJpg_Decoder.h>

#include <WiFi.h>
#include <PubSubClient.h>
const char* ssid = "****";
const char* password = "****";

void setup_wifi() {
delay(10);

Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

randomSeed(micros());

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}


bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
// Stop further decoding as image is running off bottom of screen
if ( y >= tft.height() ) return 0;

// This function will clip the image block rendering automatically at the TFT boundaries
tft.pushImage(x, y, w, h, bitmap);

// Return 1 to decode next block
return 1;
}


void setup() {
delay(500);
Serial.begin(115200);
delay(500);

Serial.print("TFT_MOSI: ");
Serial.println(TFT_MOSI);
Serial.print("TFT_SCLK: ");
Serial.println(TFT_SCLK);
Serial.print("TFT_CS: ");
Serial.println(TFT_CS);
Serial.print("TFT_DC: ");
Serial.println(TFT_DC);
Serial.print("TFT_RST: ");
Serial.println(TFT_RST);

tft.begin();
tft.setRotation(1); // 0 & 2 Portrait. 1 & 3 landscape
tft.fillScreen(TFT_BLACK);
tft.setCursor(0,0);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(1);
delay(5000);

TJpgDec.setSwapBytes(true);
TJpgDec.setJpgScale(1);
TJpgDec.setCallback(tft_output);

delay(1000);
setup_wifi();

}


void loop()
{
TJpgDec.drawJpg(tft.getViewportX(), tft.getViewportY(), image, sizeof(image));
}

And this is how I have set up the display pins in the User_Setup.h of the TFT_eSPI library:

Code: Untitled.cpp Select all

#define TFT_MOSI  13
#define TFT_SCLK 12
#define TFT_CS 14
#define TFT_DC 15
#define TFT_RST -1

lbernstone
Posts: 1132
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32-CAM TFT display and Wi-Fi trouble

Postby lbernstone » Fri Jun 07, 2024 2:17 am

WiFi initialization is the most power intense activity for a esp32. Try init'ing wifi before you power up the display.
For better assistance, explain what "doesn't work" means.

Who is online

Users browsing this forum: Qwantbot and 1 guest