Display freezes when saving images to SD card #616
-
First of all, thank you for providing us with such a great library. I am currently working on building a project that will display the images from a camera on an LCD display and save the images to an SD card when I touch the screen. Using Adafruit's ST7789 driver and GFX library, as well as the XPT2046 touchscreen library, I have confirmed that basic functions work. So I changed the graphics library to LovyanGFX (I recently ran benchmarks of the major graphics libraries and I found LovyanGFX is the fastest in every category!), and now I'm facing an issue where the display and touchscreen stops working when accessing the SD card. I think this issue may be related to this comment by @lovyan03:
To simplify this issue, I ran the SavePNG, but it stopped after displaying And when I tried inserting // Initialize SD card interface
SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, SD_CS);
do {
SD.end();
delay(1000);
SD.begin(SDCARD_SS_PIN, SDCARD_SPI, SPI_READ_FREQUENCY);
} while (!saveToSD()); Please help me to solve this issue. Here is the information about my development environment. Development environment
My custom
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
There is one more thing that bothered me. When compiling, the following warning appears:
I think something is displayed correctly, so I don't know if that's a problem or not 🤔 |
Beta Was this translation helpful? Give feedback.
-
hi, thanks for your feedback 👍 the (shared) bus is already started by LovyanGFX so I wonder if you really need SPI.begin 🤔
maybe try this instead: void setup()
{
Serial.begin(115200);
lcd.init();
lcd.setColorDepth(24);
lcd.setColor(TFT_WHITE);
lcd.startWrite();
lcd.setAddrWindow(0, 0, lcd.width(), lcd.height());
for (int y = 0; y < lcd.height(); ++y)
{
for (int x = 0; x < lcd.width(); ++x)
{
lcd.writeColor( lcd.color888(x << 1, x + y, y << 1), 1);
}
}
lcd.print("PNG save test\n");
lcd.endWrite();
// no need to re-initialize SPI, comment this out
// SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, SD_CS);
// assume the SD is already inserted and avoid the debug hell of { do ... while() }
if( SD.begin( SD_CS, SPI, SPI_READ_FREQUENCY ) )
{
if( saveToSD() )
{
Serial.println("success !!");
lcd.drawPngFile(SD, filename, random(-20,20), random(-20, 20));
}
else
Serial.println("Failed to save to SD");
}
else
Serial.println("Failed to start SD");
}
void loop()
{
// leave empty
}
|
Beta Was this translation helpful? Give feedback.
-
Immediately after compiling and uploading, no output is displayed on the serial monitor. Therefore, usually, I open the serial monitor, turn the USB switch off and then on to check the message on serial monitor. In this case, the message "Failed to save to SD" was displayed. However, when I pressed the reset button on XIAO (which is very small and difficult to press), I found that the SD was working properly. Now, I open an empty sketch, activate the serial monitor in advance, and then compile and upload the target sketch. The bootloader resets XIAO immediately after uploading, so I can always confirm that the SD is working properly. Therefore, I found that pressing the reset button instead of manipulating the USB switch ensured that the SD always worked properly. Here is a photo of my testbed. The battery switch acts just like the USB switch whenever I'm not powered by USB. However, this is not an issue as nothing is saved to the SD card immediately after turning on the battery switch. Based on the above facts and my test results where a white square PNG image (128x128) was saved,
I can conclude the following:
So I would like to raise this discussion as an issue. Is that okay? |
Beta Was this translation helpful? Give feedback.
-
This issue was solved at #617 . |
Beta Was this translation helpful? Give feedback.
Immediately after compiling and uploading, no output is displayed on the serial monitor.
Therefore, usually, I open the serial monitor, turn the USB switch off and then on to check the message on serial monitor.
In this case, the message "Failed to save to SD" was displayed.
However, when I pressed the reset button on XIAO (which is very small and difficult to press), I found that the SD was working properly.
Now, I open an empty sketch, activate the serial monitor in advance, and then compile and upload the target sketch. The bootloader resets XIAO immediately after uploading, so I can always confirm that the SD is working properly.
Therefore, I found that pressing the reset button inst…