View All Posts
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

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.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
  // 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!


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.
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!
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!
Decoding AVI Files for Fun and... - After some quality time with my ESP32 microcontroller, I've developed a version of the TinyTV and learned a lot about video and audio streaming along the way. Using Python and Wi-Fi technology, I was able to set up the streaming server with audio data, video frames, and metadata. I've can also explored the picture quality challenges of uncompressed image data and learned about MJPEG frames. Together with JPEGDEC for depth decoding, I've managed to effectively use ESP32's dual cores to achieve an inspiring 28 frames per second. Discussing audio sync, storage options and the intricacies of container file formats for video storage led me to the AVI format. The process of reading and processing AVI file headers and the listing subtype 'movi' allowed me to make significant headway in my project. All in all, I'm pretty chuffed with my portable battery powered video player. You can check out my code over on Github!
The PCBs are in production - what have I messed up? - After some stress and trepidation, I finally took the plunge and sent my PCB design off for manufacturing. My design centers around building a large seven-segment clock with LED filaments. Jumping hurdles such as voltages, pin usage, and limiting the load on my power supply, I've settled on the ESP32 as the system's heart and come up with a final circuit design. While doing this, I've quickly realized I could improve my layout and fixed a small mistake. Also, I've prepared for either types of LED filaments - the high-voltage ones or the larger, 3v ones. However, I did bungle up a couple of things on the enable line of the shift registers and board layout. But hey, this is a learning curve, right? Can't wait to get the boards and see what other exciting errors surface!

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!
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?
ESP32 SD Card Video Streaming - 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!
Is this the fastest ESP32 JPEG Decoder? - In my exploration for the fastest JPEG decoder for the ESP32, I trod a path from the original JPEG decoder library at 109 milliseconds, to the accelerated TJPEG decoder at 55 milliseconds, and finally the impressive JPEG dec library at 32 milliseconds. But wait, there's more. Along came a GitHub issue suggesting decoding JPEG with SIMD, efficiently working wonders at a decoding speed of just 20 milliseconds. However, it threw a curveball when it came to drawing. The decoding process doesn't overlap with the pixel transfer making it slower than expected. It does bring great benefits for streaming JPEGs though, as the decoding of the next frame can start while the current one is loading. But the space this library would expropriate, around 130 kilobytes, from the memory of an ESP32 module can be an issue. Yet, there are promising improvements marching on the horizon, so stay tuned for the upcoming enhancements!
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


> Image


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