Adafruit 684 with ESP32-WROVER

UoGTFranklin
Posts: 2
Joined: Sun Feb 19, 2023 4:08 pm

Adafruit 684 with ESP32-WROVER

Postby UoGTFranklin » Sun Feb 19, 2023 4:22 pm

Hello,

I am trying to use the Adafruit 684 SPI OLED module with an ESP32-WROVER module. Having already proven the OLED and code functioned using an Arduino UNO (guide available from Adafruit on this), I transferred over to ESP32 and changed pin definitions in the code for the SPI pins of the ESP32. I confirmed these were the correct pins using a basic sketch which printed to serial monitor which pins to use for each of the SPI signals.

I don't get good communication from the VSPI lines, and get corrupted data show on the OLED. If I initiate the OLED using SW SPI rather than the HW SPI I can communicate (e.g Adafruit_SSD1331 tft = Adafruit_SSD1331(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST);).

I don't fully understand why the code doesn't work when porting over to ESP32, there are plenty of examples online of others using ESP32 with the same libraries (TFT driver library, Adafruit_GFX.h and Adafruit_ImageReader.h) without issue but none of them mention making any changes. I feel that there must be some element of setup required to get the SPI working on the ESP32 but can't see anything obvious in the libraries.

Has anyone else tried to use an OLED or TFT display using the Adafruit libraries? As a target, I am looking to read .BMP images from an SD card and display them on the OLED module.

Please see below my code, which is an adapted version of the BreakoutSSD1331.ino example which is part of the Adafruit_ImageReader library:

[Codebox]#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_SSD1331.h> // Hardware-specific library
#include <SdFat.h> // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions

// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD

// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.

#define TFT_CS 4 // TFT select pin
#define TFT_RST -1 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 3 // TFT display/command pin
#define SD_CS 5 // SD card select pin
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_SCK 18


#if defined(USE_SD_CARD)
SdFat SD; // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
#else
// SPI or QSPI flash filesystem (i.e. CIRCUITPY drive)
#if defined(__SAMD51__) || defined(NRF52840_XXAA)
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS,
PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
#else
#if (SPI_INTERFACES_COUNT == 1)
Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
#else
Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
#endif
#endif
Adafruit_SPIFlash flash(&flashTransport);
FatVolume filesys;
Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys
#endif


Adafruit_SSD1331 tft = Adafruit_SSD1331(&SPI, TFT_CS, TFT_DC, TFT_RST);


void setup(void) {

ImageReturnCode stat; // Status from image-reading functions

Serial.begin(115200);

Serial.println(F("Initializing screen"));
tft.begin(); // Initialize screen

// Fill screen blue. Not a required step, this just shows that we're
// successfully communicating with the screen.
Serial.println("Filling screen BLUE");
tft.fillScreen(BLUE);
Serial.println("Screen fill complete");


// The Adafruit_ImageReader constructor call (above, before setup())
// accepts an uninitialized SdFat or FatVolume object. This MUST
// BE INITIALIZED before using any of the image reader functions!
Serial.print(F("Initializing filesystem..."));

// SD card is pretty straightforward, a single call...
if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
Serial.println(F("SD begin() failed"));
for(;;); // Fatal error, do not continue
}

Serial.println(F("OK!"));


// Load full-screen BMP file 'daffodil.bmp' at position (0,0) (top left).
// Notice the 'reader' object performs this, with 'tft' as an argument.
Serial.print(F("Loading daffodil.bmp to screen..."));
stat = reader.drawBMP("/daffodil.bmp", tft, 0, 0);
reader.printStatus(stat); // How'd we do?[/Codebox]

Who is online

Users browsing this forum: Google [Bot] and 62 guests