I have an Adafruit 3.5 TFT touch display connected to a Mega. I have copied a bit map to the on board SD card and use that as a background for a opening screen. The tutorials, and other info I have found, say I can load that BMP from the flash memory in the TFT. But I can't find anything that tells me how do I copy the BMP to the flash memory. I also want to make sure it is being copied to the TFT flash and not the Mega flash.
How do I copy the bit map to the flash memory on the TFT and then display it on the display?
What size and format BMP ?
What Arduino ?
I did mention it is a Mega but more specifically it’s a ATmega2560. I have a Adafruit 3.5" TFT 320x480 + Touchscreen Breakout Board w/MicroSD Socket - HXD8357D, PRODUCT ID: 2050
I tried to load my sketch for you but it exceeds the number characters allowed in a post so I’ve only shown the libraries I’ve included
// EOflow Demo
#include <SdFat.h> // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions
And I’ve attached the bitmap
thanks for the help
It doesn't look like the bitmap was attached to my last reply. I just noticed that .bmp files are not allowed. To answer your question it is a .bmp file, 450KBs
Which library? "Adafruit_HX8357.h"
What size and format BMP ? .bmp file, 450KB
What Arduino ? mega2560
Your 450kB .BMP is probably 320x480 with 24-bit colour.
Too big to fit in 256kB Flash memory of a MEGA2560.
Even if you convert it to 16-bit RAW pixels or even 16-bit color BMP it would need 300kB Flash.
If you convert it to a .JPG file (with 90% quality) it will fit in 32kB Flash.
You could store 7 or 8 320x480 JPG in Flash.
Note that a mega2560 will take about 5 seconds to decode and display the JPG array in Flash.
Quite honestly, your SD card can hold an unlimited number of .BMP files.
And you don't need a 256kB Arduino. A 32kB Uno can support SD + TFT.
Now you can see why I asked about size,colors of your image and power of Arduino.
Valuable information David thank you and you're right about the TFT size. A bit of background as to why I asked this question. I am making a test system for a company that wants to evaluate a device they manufacture. Through the TFT they can enter test data like test number, serial number and so forth. I thought it would be cool to put their logo on the main screen. The problem is I am also using a data logging shield that has a RTC and SD card. Because I have 2 SD cards, one on the TFT and the other in the shield I am having troubles with the 2 SD libraries required. I had posted the other day about this and was told to see if I could use the flash and eliminate one of the SD cards.
I'll assume that I can not define 2 instances for the 2 SD cards using the same library, can I?
On the other hand it's not overly important to display their logo, just trying to add a bit of splash. I can just remove that and stop creating my own headaches.
Thanks again for your help
Logos are not always full-colour. Not always 320x480.
320x480x1 i.e. monochrome needs 19.2kB. Easy to fit in a Mega2560.
320x480x4 i.e. 16-colour needs 76.8kB. Possible to fit in a Mega2560.
320x480x8 i.e. 256-colour needs 153.6kB. Possible to fit in a Mega2560.
Two SD cards seems profligate. But you could put them on the same SPI bus.
You just do SD.begin(SD1_CS) or SD.begin(SD2_CS) when you change SD.
Some graphics can look good with a 16-colour Palette.
Even photos look good with a 256-colour Palette.
Life is simpler if you had just posted an "example" Logo. Obviously not the commercially sensitive Logo.
Here’s the logo I started with, I don’t think it’s a problem to share it. To get this I did a screenshot of their website, then cropped out the logo. The logo only takes up less than a quarter of the screen so I went into Paint and added a blue background to fill the screen. Now from what you’ve told me it would be better to fill the screen with Cyan color, then load this logo, next add my control buttons. I’ve saved it as a .png file and it’s only 13 kb as opposed to the first one that is 450 kb. (back to creating my own headaches, mostly from lack of information)
This should be able to load into the flash then I don’t have to worry about the dual SD card conflicts
Your .PNG is 421x109 and "looks" monochrome.
In practice, graphics packages use "anti-aliasing" to round off the curved lines. i.e. using pixels that are part-blue and part-white.
I suggest that you put it into IrfanView and play around with "number of colours"
I bet that a 16-colour version would look good on your TFT.
Or just go for the 2-colour monochrome version. Display 5.9kB array from Flash with Adafruit_GFX :
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap,
int16_t w, int16_t h, uint16_t color, uint16_t bg),
I suggest that you play around with IrfanView or equivalent on your PC.
Save as .BMP with various numbers of colours on your PC. Copy to SD. See what they look like on the TFT. Personally, I "display all BMP" in a SD directory. (Or display files with names that match a pattern)
When you have decided, we can show you how to store and display from Flash.
Awesome, let me play around with InfraView a bit and see what I come up with, maybe a day or two
So I had a bit of time between chores and downloaded InfanView. I took the original logo bit map, which does have 16 million colors and converted it to 16 colors. I did that by selecting "image/decrease color depth" I assume that's how to do it as when I go to "image/information" it does say 16 colors. I loaded that into the TFT and it doesn't show, I tried making it 256 colors and that also doesn't show. Did I not change the color level correctly?
I loaded the original in and it looks fine, loads much faster that the full screen bitmap. Although this file is 134 KB and the 16 color is only 22 KB. Would be better to use that but it doesn't show on the screen.
After you have reduced logo_421x109x24.bmp to 256 colors, increase to 16M colors and save as BMP (with descriptive name e.g. logo_421x109x8.bmp
create and save logo_421x109x4.bmp (16 colors) and logo_421x109x1.bmp (2 colors)
Your SD program probably only understands 16M color .BMP
My SD program understands several different formats.
The simplest thing for you is to play with colors, sizes, etc on the PC but return to standard 24-bit (16M color) for saving.
IrfanView tends to give you BLACK and WHITE for 2-colors. You can edit the 2 Palette colors to match your Blue and White.
So what am I trying to do? Reduce the file size but keep it at 16m colors? If I go from 16m to 16 then back to 16m does that reduce the size or just The amount of colors it’s trying to display? The original logo, at 16m, does load up and looks good, light blue background with off white text. The file is 134 kb, I tried looking into the datasheet for the tft to see how big the flash memory is but don’t see that. Wouldn’t it be better to load the bmp into the memory on the tft rather than the mega?
Thanks for sticking with me and your patience
I was suggesting that you experiment with lower-color-resolution pictures on the PC. To see what they look like.
Your SD program only displays 24-bit BMP files. So I suggested that you saved the low-colour BMP as 24-bit.
Then you can see what it looks like on the TFT.
I gave you a detailed explanation about size and colors.
If you want a 2-color, 16-color, 256-color BMP in Flash, I can show you how to do it.
There is no point in me showing you code for everything.
You choose 2, 16 or 256 color. I will show you.
I've played around with the logo, in a couple of different photo editors. tried going from 16 m colors to 16 to 256, changed the pixel size and for the most part when I put it back to 16m, the only format the TFT will display, the file size is 134KB's. I've settled on a black and white version with dimensions of 421 x 109.
As mentioned I would prefer to load the BMP into the flash on the TFT display but I have not been able to get any info on doing that or even the flash memory size from Adafruit, actually the first time I have not been able to get an answer from them.
You had mentioned loading into the flash on the mega. I assume, because I don't know, that would be the same memory that the complied sketch goes into. When I compile the current sketch it tells me I have used 12%, 32,142 bytes of 253,952 bytes max. Will that be where the BMP will go? Will the 134KB of the BMP compile to less than that? My program is mostly complete but I may not want to use up a lot of memory just for a bit map.
I have been getting some tremendous help with this issue from a tesla member, and hopefully he will continue to help. This is a great forum, I have had many issues resolved by this community.
Also I have learnt, by a reply to this same issue that I posted on the Adafruit forum, that the flash memory is on the TFT display, it is not it is in the controller. As the tesla member had said that was where he would show me how to load my bit map.
I'm a typical engineer who doesn't read the directions well
I was expecting you to play in IrfanView. And produce a set of BMP files to view on PC or TFT
Anyway, I have done it for you.
12-Nov-19 08:50 92,050 BMP_16.bmp
12-Nov-19 08:40 6,166 logo2_1.bmp
12-Nov-19 09:21 6,166 logo2_1C.bmp
12-Nov-19 09:21 137,830 logo2_1Cx24.bmp
12-Nov-19 08:41 137,830 logo2_1x24.bmp
12-Nov-19 08:10 137,830 logo2_24.bmp
12-Nov-19 08:13 23,226 logo2_4.bmp
12-Nov-19 08:13 137,830 logo2_4x24.bmp
12-Nov-19 08:11 47,294 logo2_8.bmp
12-Nov-19 08:12 137,830 logo2_8x24.bmp
The files with “24” in the name are 24-bit colour. And your BMP program should show them on the TFT.
Personally, I would choose the 16-color logo2_4x24.bmp
It is anti-aliased. The curves look nice. It takes 23kB of Flash. And a complex function to display it (which will take a few kB of Flash).
OTOH, the 2-color logo2_1Cx24.bmp does not look too bad (from a distance)
It is only the monochrome logo2_1x24.bmp from IrfanView with the BLACK color replaced with your “special Blue”
You can create a GFX bitmap via online sites e.g. http://skaarhoj.com/FreeStuff/GraphicDisplayImageConverter.php
And display it with regular Adafruit_GFX methods. Even specifying your White foreground and “special Blue” background colours.
bmps3.zip (46.9 KB)
Thanks so much for all of your work. I obviously misunderstood that you wanted me to create all the different types of files, see my previous post about not understanding where the flash memory was. Also I was unfamiliar with IrfanView and didn't spend enough time to learn more. I will become more familiar with it.
I will play around with the files tonight and see what I can do.
Thanks again for your help and patience
I was not really expecting you to create all those files.
Just start with original 24-bit logo2_24.bmp.
Make 8-bit, 4-bit, 1-bit images on the PC.
Observe the appearance on the PC.
Choose the two "best". Save in 24-bit BMP. Copy to your SD card.
Then observe the appearance on the TFT.
4-bit (16-color) looks perfect.
But 1-bit (2-color) does not look too bad.
I am amazed by how good a 16-color palette works even with some colour photos.
And how good a 4-bit Grayscale (16 shades) looks on a TFT or OLED.