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:
  1. #include "image.h"
  2. #include <SPI.h>
  3. #include <TFT_eSPI.h>
  4. TFT_eSPI tft = TFT_eSPI();
  5. #include <TJpg_Decoder.h>
  6.  
  7. #include <WiFi.h>  
  8. #include <PubSubClient.h>
  9. const char* ssid = "****";
  10. const char* password = "****";
  11.  
  12. void setup_wifi() {
  13.   delay(10);
  14.  
  15.   Serial.println();
  16.   Serial.print("Connecting to ");
  17.   Serial.println(ssid);
  18.  
  19.   WiFi.mode(WIFI_STA);
  20.   WiFi.begin(ssid, password);
  21.  
  22.   while (WiFi.status() != WL_CONNECTED) {
  23.     delay(500);
  24.     Serial.print(".");
  25.   }
  26.  
  27.   randomSeed(micros());
  28.  
  29.   Serial.println("");
  30.   Serial.println("WiFi connected");
  31.   Serial.println("IP address: ");
  32.   Serial.println(WiFi.localIP());
  33. }
  34.  
  35.  
  36. bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
  37. {
  38.    // Stop further decoding as image is running off bottom of screen
  39.   if ( y >= tft.height() ) return 0;
  40.  
  41.   // This function will clip the image block rendering automatically at the TFT boundaries
  42.   tft.pushImage(x, y, w, h, bitmap);
  43.  
  44.   // Return 1 to decode next block
  45.   return 1;
  46. }
  47.  
  48.  
  49. void setup() {
  50.   delay(500);
  51.   Serial.begin(115200);
  52.   delay(500);
  53.  
  54.   Serial.print("TFT_MOSI: ");
  55.   Serial.println(TFT_MOSI);
  56.   Serial.print("TFT_SCLK: ");
  57.   Serial.println(TFT_SCLK);
  58.   Serial.print("TFT_CS: ");
  59.   Serial.println(TFT_CS);
  60.   Serial.print("TFT_DC: ");
  61.   Serial.println(TFT_DC);
  62.   Serial.print("TFT_RST: ");
  63.   Serial.println(TFT_RST);
  64.  
  65.   tft.begin();
  66.   tft.setRotation(1);  // 0 & 2 Portrait. 1 & 3 landscape
  67.   tft.fillScreen(TFT_BLACK);
  68.   tft.setCursor(0,0);
  69.   tft.setTextColor(TFT_WHITE);
  70.   tft.setTextSize(1);
  71.   delay(5000);
  72.  
  73.   TJpgDec.setSwapBytes(true);
  74.   TJpgDec.setJpgScale(1);
  75.   TJpgDec.setCallback(tft_output);
  76.  
  77.   delay(1000);
  78.   setup_wifi();
  79.  
  80. }
  81.  
  82.  
  83. void loop()
  84. {
  85.   TJpgDec.drawJpg(tft.getViewportX(), tft.getViewportY(), image, sizeof(image));
  86. }

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

  1. #define TFT_MOSI  13
  2. #define TFT_SCLK  12
  3. #define TFT_CS    14
  4. #define TFT_DC    15
  5. #define TFT_RST  -1

lbernstone
Posts: 829
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: No registered users and 47 guests