Wish Draw bitmap on TFT screen

derez

Expert
Licensed User
Longtime User
This link https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2/drawing-bitmaps shows how to draw a bitmap on adafruit tft screen.
I would like to use this capability but I don't know how to write the inline C for this function reader.drawBMP.
Also, are these definitions included in the b4r libraries (adafruit_GFX and mcufriends_kbv which are used in the existing drawing programs that I use) or needed in the code ? will they work together or contradict ?
B4X:
#define SD_CS   4 // SD card select pin
#define TFT_CS 10 // TFT select pin
#define TFT_DC  9 // TFT display/command pin
Thanks
 
Last edited:

derez

Expert
Licensed User
Longtime User
Sorry, wrong link. This link https://electropeak.com/learn/absol...o-tft-lcd-displays-by-arduino/#Basic_Commands shows demos with a function "drawRGBBitmap" in mcufriends_kbv library but I can't find it in the library's code (???) and it is also not exposed to B4R code. In the example the used bitmaps are stored as arrays so there should also be a method to create them from files. Complicated... also adding all the files will end by a too big application :(
 
Last edited:

derez

Expert
Licensed User
Longtime User
IMG.jpg

Both alternatives work when run from Arduino IDE. The bitmaps in the above picture need conversion from file to an array.

IMG2.jpg


In the mcufriends example the function showBMP is doing the conversion in real time, the files are in the SD card.

For me, the arrays solution is not good, if I need 7 bitmaps and they all are coded in the memory - the application will be giant.
With the mcufriends example - each bitmap is created when used but the size of the function seems too big.
 
Last edited:

derez

Expert
Licensed User
Longtime User
The conversion tool does not exist anymore, can't find the jar file. I checked too other tools in arduino code and got garbage...
 

derez

Expert
Licensed User
Longtime User
I reduced the sketch to minimum leaving two bitmaps:
B4X:
#include "Adafruit_GFX.h"    // Core graphics library
#include "MCUFRIEND_kbv.h"   // Hardware-specific library
MCUFRIEND_kbv tft;

#include "images.h"

void setup()
{
  Serial.begin(9600);
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.invertDisplay(true);
  tft.setRotation(1);
}
 
void loop(void)
{
 
  tft.drawBitmap(20, 20, Line1, 32, 40, 0xffff);//battery
  tft.drawBitmap(125, 25, Line3, 45, 45, 0xffff);//mail

}

The images data is attached, it should be with the ino file.

I request the inline C for the drawBitmap method, if it is different then the one in the link above.

EDIT: I used the same function and it works ! is it possible to find a way to use the same function for several bitmaps instead of duplicating it ?
 

Attachments

  • images.zip
    495 bytes · Views: 847
  • bmp_example_s.zip
    448 bytes · Views: 696
Last edited:

derez

Expert
Licensed User
Longtime User
I have to draw 11 bitmaps, all with the same height.
I made this sub in B4R:
B4X:
Private Sub DrawBitmap(img As Int,x As Int, y As Int,  Width As Int) ' the height is already set
    bmpx = x
    bmpy = y
    imageWidth = Width
    Select img
        Case 0
            RunNative("drawBitmap0", mcu.GFX)
        Case 1
            RunNative("drawBitmap1", mcu.GFX)
        Case 2
            RunNative("drawBitmap2", mcu.GFX)
        Case 3
            RunNative("drawBitmap3", mcu.GFX)
        Case 4
            RunNative("drawBitmap4", mcu.GFX)
        Case 5
            RunNative("drawBitmap5", mcu.GFX)
        Case 6
            RunNative("drawBitmap6", mcu.GFX)
        Case 7
            RunNative("drawBitmap7", mcu.GFX)
        Case 8
            RunNative("drawBitmap8", mcu.GFX)
        Case 9
            RunNative("drawBitmap9", mcu.GFX)
        Case 10
            RunNative("drawBitmap10", mcu.GFX)
    End Select
End Sub
I call for drawing an image with this:
B4X:
DrawBitmap(1, 180 ,355 ,  32)
In C I made this code * 11, for each bitmap the array and the function :
B4X:
static const unsigned char PROGMEM bmp0[] = {
   0xff, 0xff, 0xff, 0xfc,
    0xff, 0xff, 0xff, 0xfc,
  ...
    0xff, 0xff, 0xff, 0xfc,
    0xff, 0xef, 0xff, 0xfc
};

void drawBitmap0(B4R::Object* o) {
   B4R::B4RAdafruitGFX* bgfx = (B4R::B4RAdafruitGFX*)o->data.PointerField;
   bgfx->gfx->drawBitmap(b4r_main::_bmpx, b4r_main::_bmpy, bmp0,b4r_main::_imagewidth
      , b4r_main::_imageheight, 1);
}

Something like the select in B4R for the C code ?
 

derez

Expert
Licensed User
Longtime User
Thank you, Erel.
I completed the change to have DayofWeek in Hebrew on the clock using 11 bitmaps the size of 45x60, the size of the complete code is 99% !

Strange thing - although the bitmaps are monochrome , made of black text on white background, I have the letters in red !
The bitmaps were coded to invert the colors in order to have black background. I realized that the white color of the letters is actually transparent like a mask so I draw a color rectangle to be used as background and on it the bitmap !

upload_2019-11-5_10-21-3.png
 
Last edited:

derez

Expert
Licensed User
Longtime User
If I put all the bitmaps' arrays in a file and add an include line for this file in the inline C part, where should the file be ?
 
Top