ESP32-CAM TFT display and Wi-Fi trouble
Posted: 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:
And this is how I have set up the display pins in the User_Setup.h of the TFT_eSPI library:
This is my code:
- #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:
- #define TFT_MOSI 13
- #define TFT_SCLK 12
- #define TFT_CS 14
- #define TFT_DC 15
- #define TFT_RST -1