My sample codes provided by supplier of lcd can only display less than 64k of pic array data ,but i want to use the whole flash memory for my codes & many pictures display but now i am stucked with only can use less than 64k of my flash memory for pictures!
My Arduino Mega 2560 using PROGMEM array to display pictures on Lcd hangs when my sketch + PROGMEM arrays gets my sketch larger
I not sure if i need to change GUI_paint.cpp's "pgm_read_byte" to a 32bit commands to access the whole 256k addresses of flash.
My Lcd iS 2.4 inch Lcd.
My LCD_mega2560.ino filemainly uses these 4 files for display pics on Lcd :
image.h
image.cpp
GUI_paint.h
GUI_paint.cpp
I extracted parts of code for your easy viewing. Codes below from GUI_paint.h
If you do this on a Arduino Mega: Serial.println(sizeof(size_t));
then it prints "2". That means it uses two bytes for the index and size of an array. That is okay if the array is in SRAM. That means it can not deal with data in Flash that is larger than 64kbyte.
If you have multiple sections in Flash (and each is less than 64kbyte), then all the F() and memcpy_P() functions can no longer be used. You have to check all the libraries that they don't use those functions.
There is a workaround, but it needs code that runs during runtime.
The "pgm_get_far_address()" returns a 32-bit value for the address during runtime. That value is not a pointer for the compiler, but it can be used as a pointer for pgm_read_byte_far() and strncpy_PF().
After writing this, I noticed that I wrote this already in the link of post #2 by Whandall. Well, better do something twice in a good way than half in a bad way.
As far as I know, the Wokwi simulator behaves the same for this situation as in the real world. What kind of display are you using ? Wokwi has a ILI9341 display.
This might be the right time to upgrade to a Raspberry Pi Pico or a ESP32.
Arduino runs on a Raspberry Pi Pico and on a ESP32. It should be mostly in the same way as with your Arduino Mega.
A Wokwi simulation with the display and a ESP32: https://wokwi.com/projects/342032431249883731.
I think that the Adafruit library is often used, but there is also a lcdgfx library: https://wokwi.com/projects/308022099088245312.
I don't know how to use the SPI bus with a Raspberry Pi Pico and if the Adafruit library is compatible with it. If everything is compatible then it should work.
void Paint_DrawImage_FP(const uint_farptr_t image, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image)
{
int i, j;
for (j = 0; j < H_Image; j++) {
for (i = 0; i < W_Image; i++) {
if (xStart + i < LCD_WIDTH && yStart + j < LCD_HEIGHT) //Exceeded part does not display
Paint_SetPixel(xStart + i, yStart + j, (pgm_read_byte_far(image + j * W_Image * 2 + i * 2 + 1)) << 8 | (pgm_read_byte_far(image + j * W_Image * 2 + i * 2)));
//Using arrays is a property of sequential storage, accessing the original array by algorithm
//j*W_Image*2 Y offset
//i*2 X offset
//pgm_read_byte()
}
}
}
image.h with the pointers and (I hope) the correct attribute for far program memory (been a while since I've done this, and I usually define the attribute as PROGMEM_FAR to make it easier to use).
All are ok except it returned an error saying that array size too large.
But i thought your code is to make it able to handle large arrays?
Kindly advice. Thks
Fyi i added an asterisk * in front of "image," shown below that your code does not have, so i not sure if this is affecting it ? The original code does have an asterisk *image,
i tried your suggestions and the compiler returned error:
""""exit status 1
Compilation error: size of array 'gImage_3D_batt10percent' is too large"""
i tried smaller arrays and it can compile up to 55% but images shown on Lcd are either mostly scrambled or cut off.
i tried to search internet for solution but still can resolve this. But why the codes that are supposed to handle larger array addresses turns out cant handle this same array?
Any idea whats wrong?. Thks
I did not change the name or type of the arrays themselves, and the changes I made to image.h are in addition to the lines you already had declaring the arrays.
The asterisk should not be there, uint_farptr_t is already a reference to a pointer.
Something else you can do to save a considerable amount of memory. It looks like you are using 12-bit color in the code, stored as two bytes per pixel, with only 41 different colors being used. The size of each image would be halved if you used an array to store the actual color codes, and the image file itself stored the index to the color.
Hi David
At setup() need remove _farptr. Then your code seems to compile ok now but its still the same as my original issue when sketch reach 28% it hangs. Any views on this?
PiPico, RP2040, is relatively new to the scene and example code is being created for Javascript, C++ (Arduino), and microPython and CircuitPython: the later being driven by Adafruit.
Yes, I think so. Should there be something else on the display ?
I checked the pins for the SPI bus and the ones in DEV_Config.h, I think they are right.
In the right-upper corner of the Wokwi page is a percentage that shows how fast your browser can run the simulation. If that is way below 100%, then try the Chrome browser.
When the simulation is not running, click on the display, then click on the question mark, then you go to the "Docs" and there are examples, so you can see what others made.
U using any PROGMEM in image.h? As u mentioned your codes are in addition of mine.
Any _farptr for LCD_mega2560 tab under setup() ? For example, do u use gImage_3D_batt100percent or gImage_3D_batt100percent_farptr ?
NICE Wokwi great setup with codes.
but Wokwi doesn't show the sketch's % flash memory consumption though.
Seems there is something wrong with your codes, as in some images are not displayed even when sketch is 10% where those not displayed were originally displaying well with different combination of pictures set to display at setup(). And when sketch is larger than 30% or 40% then all images will display fizzy images.