View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
#ADAFRUIT_ST7789 LIBRARY #ARDUINO #CODING #ESP32-S3 #HARDWARE SPI #SOFTWARE SPI #SPI #TROUBLESHOOTING

A few people commented on my Arduino Nano ESP32 video around the speed of the display updates. A kind commenter pointed out the issue - the default constructor of the Adafruit_ST7789 library uses software SPI when you use custom pins.

With the ESP32-S3 we can use any pins for hardware SPI - but the library assumes that it needs to use software SPI which makes things really slow.

The fix is to use the hardware SPI constructor of the library. This doesn’t seem to be documented particularly well - at least I can’t find any good references. But for future me, here’s the code:

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>             // Arduino SPI library
 
// ST7789 TFT module connections
#define TFT_CS    10
#define TFT_DC    9
#define TFT_SCLK  13
#define TFT_MOSI  11
#define TFT_RST   8

Adafruit_ST7789 *_tft = NULL;

void setup(void) {
  Serial.begin(115200);
  Serial.print(F("Hello! ST77xx TFT Test"));
 
  SPIClass *spi = new SPIClass(HSPI);
  spi->begin(TFT_SCLK, -1, TFT_MOSI, TFT_CS);
  tft = new Adafruit_ST7789(spi, TFT_CS, TFT_DC, TFT_RST);
  // 80MHz should work, but you may need lower speeds
  _tft->setSPISpeed(80000000);
  // this will vary depending on your display
  _tft->init(240, 280, SPI_MODE0);

Have a look at the video to see the difference in action - it’s pretty mind blowing!

#ADAFRUIT_ST7789 LIBRARY #ARDUINO #CODING #ESP32-S3 #HARDWARE SPI #SOFTWARE SPI #SPI #TROUBLESHOOTING

Related Posts

A Faster ESP32 JPEG Decoder? - An intriguing issue appeared in the esp32-tv project that deals with speeding up JPEG file decoding using SIMD (Single Instruction Multiple Data) instructions, showing immense performance boost. However, there were some notable differences in speed when it comes to drawing the images versus simply decoding them. The problem was found to be with the DMA drawing mechanism and the way the new fast library decodes the image all at once. But despite this hiccup, by overlapped decoding and displaying process, a high frame rate can still be achieved. Joined me in this dissecting process and my initial tests showing approximately 40 frames per second display rate, on our journey to find the most efficient way to get images on screens.
ESP32-S3 USBMSC - Can we make it faster? - After lots of tinkering, I've managed to improve the speed of writing to the SD Card of my ESP32-TV considerably, but it's still not as fast as I'd like. The Arduino 'readRaw' and 'writeRaw' functions were the culprits, they can only write one sector at a time! After bypassing this and using IDF functions, writing speed improved by 70%. I also experimented with writing to the SD Card in the background, which ironically yielded even better results. However, it's still slower than I'd like, so I've got a crazy new plan: using a cheap IC (GL823) for SD card interfacing and a USB multiplexer switch to swap connections between ESP32 and GL823. It's a wild ride, but that's how we make progress!
Self Organising WS2811 LEDs - I've successfully used addressable WS2811 LED strings and an ESP-CAM board to create an adjustable lighting system. The best part is that the image processing code can be duplicated in JavaScript which allows you to use a plain dev board to drive the LEDs instead of needing a camera on your ESP32 board. If you want to replicate this project, you'll need your own ESP32 dev board and some addressable LEDs. After figuring out the location of each LED in 2D space, it's easy to map from each LED's x and y location onto a pattern you want to show on the frame buffer. Desiring to keep it accessible, I've posted detailed instructions and my sample code on GitHub, making sure anyone with basic knowledge can undertake this fun technological DIY project!
A Potentially Explosive Error - Just received the new PCBs for the ESP32-TV project and they're looking sharp with only a tiny resistor tweak needed. But I discovered a sneaky, undocumented resistor causing a conflict between the ESP32 and USB2244 over the USB connection. Fixed that, but there's a bigger issue lurking in the design - check the schematic in the video and see if you can spot it before I reveal the explosive mistake!
Connecting up the MCP23S17 and HD44780U based LCD - Ever wondered how to hook up an LCD display with your Raspberry Pi without using up all your GPIO pins? With the right tools, such as the MCP23S17 and wiringPi, you can effortlessly keep your I2C, UART, and SPI functionalities free for other worthwhile endeavors. This blog post truly proves that the GPIO is quite flexible with the I2C or SPI pins and setting up the MCP23S17 is as simple as connecting the pins. And with support for 5v LCD modules, I can assure you that this setup is definitely lit!

Related Videos

I Feel the Need – The Need for Hardware SPI… - An insightful iteration on my Arduino Nano esp32 video. Despite criticism regarding the slow display update speed, a solution was found thanks to the helpful fellow, Nick. Turns out, the software SPI was the cause of the issue. A quick tweak in the code and voilà, we've got ourselves an SPI clock whizzing at 80 megahertz. Quite the speed boost for just a few lines of code alteration!
ESP32 SD Card Speedup With a Couple of Lines of Code - In this video, we explore the disappointingly slow data writing speed of the ESP32 when reading and writing to an SD card in our TinyTV project. With 500 kilobytes/sec reading and a dismal 270 kilobytes/sec writing, we embark on an adventure to find a solution. After ditching the Arduino code in favor of IDF functions, we discover incredible improvements. Seeing potential risks, I propose a truly bonkers plan: using a IC to interface SD cards with USB with a USB multiplexer switch and another switch to alternate between ESP32 and the GL823. This could be a total disaster, but I'm game for the challenge. Stay tuned to see if it works out!
Arduino Nano ESP32 - It's nice - But probably not for me. - In this video, I took a deep dive into the Arduino Nano ESP32 and compared it with other available boards in the market. Despite its seemingly high cost as compared to the options on AliExpress, its overall quality, fantastic documentation, and the fact that it fits neatly into the Arduino ecosystem makes it a good buy, especially if you've already invested in the Arduino Nano and its shields. The board has a few interesting peculiarity, including the use of a NORA-W106 module, a switch mode step-down converter for power, and an RGB LED. However, I was disappointed to find out it doesn't come with built-in battery charging. The pin labelling and remapping could definitely cause some confusion, especially if you're transitioning from other ESP32 boards. It's a fairly decent ESP32-S3 board if that's what you're after. But given a choice, I'm keener on the Unexpected Maker boards or the cheap boards on AliExpress.
Streaming Video and Audio over WiFi with the ESP32 - In this video, we dive into a hardware hack combining several components to create my version of the TinyTV, complete with a remote control, and video streaming over Wi-Fi. We challenge the speed of image display, using different libraries and tweaking performance for optimal results. We explore Motion JPEG or MJPEG to decode and draw images quickly, and even reach about 28 frames per second. We also catered audio using 8-bit PCM data at 16kHz, and deal with syncing both video and audio streams. Finally, we add some interactive elements allowing us to change channels and control volumes, with a classic static animation thrown in for good measure. There's a few hiccups along the way, but that's part of the fun, right?
Streaming Video From an SD Card on the ESP32. - In this video, we successfully navigated the convoluted process of setting up movie file playback from an ESP32 with an SD card. There were a few bumps along the way, such as confusing USB data pins and the intricacies of various video container formats, but our quirky PCBWay board came through. Discussed an ingenious method of creating a simple custom video container format with ffmpeg that can be effortlessly parsed by the ESP32. And yes, even though the tiny TV guys use AVI files, we pushed boundaries and learned a thing or two about list chunks, sub formats, and hex dumps. The result? We achieved smooth audio playback and video frame skipping for an optimal balance. Check out the streaming version on WiFi for more fun!
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts