Multiple SPI Buses Outnumber Budget Yellow Display Unit
Article:The Cheap Yellow Display, despite being a budget-friendly ESP32 board with an older model chip and 4 MB of memory, has earned a slot in our community's heart due to its versatile collection of on-board peripherals. However, optimizing this hardware isn't always a walk in the park, as [Mark Stevens] discovered when constructing an environmental data logger. The snag? The display, touch sensor, and SD card each operated on different SPI busses, with the software only recognizing two of them. But fear not! Our ingenious hero concocted a side-splittingly simple DIY hardware modification that could benefit numerous creators embarking on similar projects.
It's child's play, really—merge the LCD and SD card onto the same SPI bus, while preserving their separate chip select lines. Don't fret, as it only requires a teeny track removal and a spot of wiring. Nothing that'll leave you panting or crimson-faced. Plenty of reasons to be captivated by this affordable board—it's stable ground for innovation, and advancements for it are genuinely exciting! If you're craving to get started, allow us to stoke the flames of inspiration.
Wondering how to connect both the LCD and the SD card to the same SPI bus on the ESP32 Cheap Yellow Display board? Let's break it down:
Step 1: Identify the SPI Pins
The SPDT switch (on/off/on or normally open/normally closed/normally coupled) offering a selection of positions is perfect to connect the LCD and SD card to the same SPI bus. However, on the ESP32, you'll want to pin the SCK signal for the shared SPI bus to IO18.
Step 2: Configure the TFT Display
Familiarize yourself with the TFT_eSPI library for seamless communication with your TFT display. Ensure the TFT setup is on point:
- Use TFT_eSPI to control the TFT display.
- Specify the correct pins and driver type (e.g., ILI9341 or ST7789) in the User_Setup.h file, depending on the panel's driver IC.
Step 3: Configure the SD Card
The microSD card requires a dedicated chip select (CS) pin and, typically, a distinct CS pin from the TFT display. Here's how to set up the SD card:
- Employ a library like SD or SDFat for SD card operations.
- Define the CS pin for the SD card in your code.
Step 4: Handle SPI Bus Sharing
To share the SPI bus between the LCD and SD card, handle the CS pins correctly: only one device should be active at a time (i.e., set its CS pin low while the others are high).
Example Code Snippet
```cpp
// Define the SPI pinsconst int TFT_CS = 5; // CS pin for TFT displayconst int SD_CS = 13; // CS pin for SD cardconst int SPI_MOSI = 23;const int SPI_MISO = 19;const int SPI_SCK = 18;
// Initialize the TFT displayTFT_eSPI tft = TFT_eSPI();
void setup() { // Initialize the TFT display with the correct pins tft.begin(); tft.setSwapBytes(true); // Depending on the display configuration tft.fillScreen(TFT_BLACK);
// Initialize the SD card if (!SD.begin(SD_CS)) { Serial.println("SD card initialization failed!"); return; } Serial.println("SD card initialized.");}
void loop() { // Your main loop code here}```
Step 5: Ensure Correct CS Pin Management
In your code, make sure to set the CS pin high for the inactive device and low for the active device before sending data.
By connecting your LCD and SD card to the same SPI bus on the ESP32 Cheap Yellow Display board, you'll unleash a torrent of inventive possibilities! Happy tinkering!
- To merge the LCD and SD card onto the same SPI bus on the ESP32 Cheap Yellow Display board, you need to connect them using an SPDT switch, with the SCK signal for the shared SPI bus pinned to IO18.
- With the LCD and SD card connected to the same SPI bus, it's essential to manage their chip select (CS) pins correctly in the code, ensuring that only one device is active at a time, with its CS pin set low while the others are high.