I am trying to build a mini camera with Seeedstudio XIAO-ESP32-S3-Sense and Waveshare Pico 240x135 ST7789 display.
I have configured the User_Setup for the display using the Round Display example on the seeedstudio website.
User setup is included as a comment in the following code.
The code works in this order:
setup(): initializes camera, sd card, display and shutter button pin
loop(): it gets a frame from camera buffer
2.a. passes it to the TFT display using pushScaledFrame()
2.b. if the shutter button is pressed, it instead passes the frame to captureAndSave()
2.c. returns the frame to camera buffer and loop repeats
The code works fine and displays the camera output initially, but the board crashes when shutter is pressed. As per the seeedstudio website both the SD card and TFT display share the same SPI pins (GPIO9 for MOSI, GPIO7 for SCLK) and that other SPI functions (TFT display in my case) cannot be used simultaneously with the SD card. The website also points to another github page by MjRovai which states that the SPI conflict can be resolved by defining SD_CS_PIN 21 in the code.
I did that, but the code still doesnât work.
I have confirmed that the rest of my code works properly by commenting out the initDisplay() in setup() and pushScaledFrame() in loop() to completely turn off the display. Then the image is captured and saved to SD card without any issue when the shutter button is pressed.
I am new to programming with microcontrollers and could really use some help.
So sounds like your close, Youâll get it. It does work.
What output do you get /or See when you run the UserSelect_Setup.ino in the tools for the TFT_eSPI lib.
Run that code and verify via the Serial output âthat it is set the way you think it isâ. (probably not) This is where everyone gets hung up. Run that code and report back.
You can check also some of the Round Display Demoâs I have posted with code and different configs for TFT_eSPI.lib
I didnât find the exact UserSelect_Setup.ino that you mentioned but instead run another test file:
Arduino\libraries\TFT_eSPI\examples\Test and diagnostics\Read_User_Setup\Read_User_Setup.ino
This is the serial output:
TFT_eSPI ver = 2.5.43
Processor = ESP32
Frequency = 240MHz
Transactions = Yes
Interface = SPI
Display driver = 7789
Display width = 135
Display height = 240
R0 x offset = 52
R0 y offset = 40
MOSI = GPIO 9
SCK = GPIO 7
TFT_CS = GPIO 2
TFT_DC = GPIO 4
TFT_RST = GPIO 1
Font GLCD loaded
Font 2 loaded
Font 4 loaded
Font 6 loaded
Font 7 loaded
Font 8 loaded
Smooth font enabled
Display SPI frequency = 40.00
Yep, Excellent , I must be losing itâŚWith the Setup Select ,LOL
You ran the correct one.
I see it says the driver is the correct config.
The pins would be next, there are caveats when using the Round display with TFT_eSPI.lib, Seeed has also the Round_Display.lib that does some of it behind the scene.
easiest may be to switch the shutter button io pin. There are jumpers to remove or bridge to cut if you want a custom setup.
I see you commented out some portion to run , what about trying it with the round display lib ? and display it on the round screen first.
I feel like the SD pin should be left as it is though, and work out the display part seperatly, maybe read captured image from the SD you saved and display it
only as a display only test?
First few lines of the compiler output are as follows,
FQBN: esp32:esp32:XIAO_ESP32S3:PSRAM=opi
Using board âXIAO_ESP32S3â from platform in folder: C:\Users\witz\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7
Using core âesp32â from platform in folder: C:\Users\witz\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.7
.
.
.
.
Serial port COM5
ConnectingâŚ
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
.
.
.
.
Also, just so that we are on the same page, the initDisplay() on my code works fine. It shows Display OK on the TFT display at the start, holds for two seconds and switches to the camera stream (which is called in the loop).
Ok, SO good to know.
Looks like you are returning the same frame buffer twice when the shutter is pressed.
In captureAndSave():
and again in the Loop ? 'esp_camera_fb_return(fb)`;
Fix that it should work, but also
Do not use GPIO21 for LED control while the SD card is mounted, because that pin is the SD card CS on XIAO ESP32S3 Sense. AFAIK
HTH
GL PJ
You appear to be clobbering the frame buffer ?
Iâd also make the SPI setup explicit before initializing either device:
SPI.begin(7, 8, 9, -1);
SPI bus contention could be problem #2 that will set it.
Then:
initialize TFT
initialize SD with SD.begin(21)
let loop() be the only place that returns the frame.