I thought I'd share a quick hack I put together to get bitmaps to display on the 2.8" TFT LCD. It's not that elegant of a solution, involves a few steps, but it works. Here's what I do:
1) Open bitmap in your favorite image editor, flip the canvas horizontally, save bitmap
2) Run the saved bitmap through this mismash of quickly thrown together MATLAB code (or port to your favorite language). You'll notice one way I'm saving space on the Arduino is not to bother writing out pixels which are the color of the background. Just do a tft.fillScreen with your color first, then display the bitmap (getting to this soon).
- Code: Select all
function bmpToPixels
img = imread('c:\userinput.bmp');
fid = fopen('C:\userinput.txt','w');
fprintf(fid,'FLASH_ARRAY(uint8_t,XVals,');
counter=0;
for x=1:(size(img,1))
for y=1:(size(img,2))
R = img(x,y,1);
G = img(x,y,2);
B = img(x,y,3);
if(R ~= 255 & G ~= 255 & B ~= 255)
counter=counter+1;
fprintf(fid,'%d,',x);
end
end
end
fprintf(fid,');\n\n// Counter: %d',counter);
fprintf(fid,'\n\nFLASH_ARRAY(uint8_t,YVals,');
for x=1:(size(img,1))
for y=1:(size(img,2))
R = img(x,y,1);
G = img(x,y,2);
B = img(x,y,3);
if(R ~= 255 & G ~= 255 & B ~= 255)
fprintf(fid,'%d,',y);
end
end
end
fprintf(fid,');\n\nFLASH_ARRAY(uint8_t,RVals,');
for x=1:(size(img,1))
for y=1:(size(img,2))
R = img(x,y,1);
G = img(x,y,2);
B = img(x,y,3);
if(R ~= 255 & G ~= 255 & B ~= 255)
fprintf(fid,'%d,',R);
end
end
end
fprintf(fid,');\n\nFLASH_ARRAY(uint8_t,GVals,');
for x=1:(size(img,1))
for y=1:(size(img,2))
R = img(x,y,1);
G = img(x,y,2);
B = img(x,y,3);
if(R ~= 255 & G ~= 255 & B ~= 255)
fprintf(fid,'%d,',G);
end
end
end
fprintf(fid,');\n\nFLASH_ARRAY(uint8_t,BVals,');
for x=1:(size(img,1))
for y=1:(size(img,2))
R = img(x,y,1);
G = img(x,y,2);
B = img(x,y,3);
if(R ~= 255 & G ~= 255 & B ~= 255)
fprintf(fid,'%d,',B);
end
end
end
fclose(fid);
end
3) Open the resulting file and copy/paste the output into your Arduino code.
4) Add these two functions to your Arduino code (note: I found these online somewhere in a Google search, I don't claim to have written them but I've lost the URL where I found them) :
- Code: Select all
uint16_t RGB24toRGB565(uint8_t r, uint8_t g, uint8_t b) {
return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8);
}
void bmpPixelDraw(uint16_t x, uint16_t y,uint8_t r, uint8_t g, uint8_t b){
uint16_t color = RGB24toRGB565(r,g,b);
tft.drawPixel(x,y,color);
}
5) You now have the bitmap data stored in five easily accessible 1-dimensional arrays (one for X values, one for Y values, one for red value, one for green value, one for blue value , all that's left is to loop through it and turn your pixels on as such:
- Code: Select all
for(uint16_t z=1;z < VALUE_FROM_COUNTER_LINE_IN_TEXT_FILE; z++ ){
PP(XVals[z],YVals[z],RVals[z],GVals[z],BVals[z]);
}
Hooray! Bitmaps on the 2.8" TFT LCD. Now only if this darn Duemilanov had more than 32k of memory.......

