How to display a single bitmap using an mcufriend display

I have googled this subject to near death(!) and whilst I can find many topics that discuss around this problem, I have still failed to achieve my goal.....so need help please!

I'm using a mega with an mcufriend shield which all works very nicely drawing text and graphics. The text is very 'blocky' (I think for memory saving reasons) and is not good from a professionalism point of view so I would like to display a simple screen logo instead. This will be 'painted' during the setup routine and left as is, once the main programme is running. At the moment. high memory usage for this is not an issue.

I have read most of the works of the great Dave Prentice (that I can find), but STILL can't get this to work. Dave if you are still out there, help, I need you (please!).

I have copied and much modified Dave's drawBitmap_kbv (this is way over complex for my needs and have successfully trimmed it back so that it just displays one of the tractor images (no Mariylns etc!) and so the sktech is basically what I need, except it's the wrong image!

My problem/lack of understanding therefore lies in how to load my bit map into memory - using an SD card just for a one off screen logo would be silly. I have created a .c file using the rinky dinky convertor and it seems fine, but how do I insert this into either my own .h file or into the bitmap_RGB.h file used by drawBitMap?

Thoroughly confused here, so some gentle prodding in the correct direct would be greatly appreciated please!

(Apologies, I had major difficulty in choosing a category for this question....something to do with mcufriend displays would seems the best, but there isn't a category for this apparently. Apologies if I have posted in the wrong place!

Please show your code and your current bitmap file you have issues with.

Unfortunately Dave is no longer under us.

Let me see if I understand this correctly.

You've looked at the example that comes with MCUFRIEND_kbv that demonstrates how to display bitmaps from memory.

You've trimmed the example back to use a single bitmap.

You've successfully used the converter that is referenced in that example to create your own bitmap.

But you can't figure out how to replace the example bitmap in the example with yours?

Am I understanding your problem correctly?

I appreciate your response, but the problem is not in my code - I simply don't how to load a bitmap file so that the sketch can access it to display it using Dave's files.

Dave's bitmap is this: tractor10_96x64 and this file lives in a file "bitmap_RGB.h" that is included at the beginning of the sketch so my code is arguably this: (Actually it's Dave's code much slimmed down by me).


#include "bitmap_RGB.h"

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x8410
#define ORANGE  0xE880

void setup()
{
   uint16_t ID = tft.readID();
    tft.begin(ID);
    tft.setRotation(1);
    tft.fillScreen(BLACK);
   int w = 128, h = 64;
    tft.drawRGBBitmap(0, 0, tractor10_96x64, 96, 64);
}

And this works nicely with Dave's created tractor10_96x64 image that resides within "bitmap_RGB.h".

My problem is is that if I add my logo to Dave's bitmap_RGB.h file the compiler says 'No such file'

If I try to create my own .h file, my sketch can't see it so there is clearly something wrong with the way I am creating these. How do I create them and where should I put them so that the sketch can read them (polite answers only please!)

What I need therefore is someone to tell me how to set this up rather than to critique my code (which works! - I just don't have the back ground set up correct).

Yes, that's it as far as I can see. I've posted what code I have in a previous answer, but it's not the code that's the problem..it is as you understand.

Please show the bitmap_RGB.h after adding your bitmap to it. Without seeing that I can't understand where the problem.

You don't need to load this file.
All what you need are:

  • Create a new .h file in the same folder, where your .ino file is. Name the file with any name convenient for you, for example logo_bitmap.h
  • Add your bitmap data array to the file this way:
#include <avr/pgmspace.h>
const uint16_t logo_96x64[0x1800] PROGMEM ={ ....
  • In your arduino code edit the lines where the bitmap file is included:
#include "logo_bitmap.h"

and the line where the array is loading, changing the name of data array according to the array in your file:

tft.drawBitmap(x, y, logo_96x64, 96, 64, BLUE);

I think @b707 summed up this trivial operation nicely. And possibly adjust the bitmap dimensions in the drawBitmap call if the new bitmap differs in size from the old one.

It's HUGE!

I'll have to chop out most of the hex data to show you the structure....

I'm not sure that is the problem either though.....I don't think I am putting this file in the right place...I found David's version deep deep down the directory structure in a temp folder and so I think I'm trying to use a working folder rather than the actual file. Do you know where such a file should live so that is can be accessed properly please?

Ok thanks...let me look at this.....will be the day after tomorrow now though.

Many thanks,

Probably just doing something daft (aka blundering about in the dark!)

Hi @damienwalker ,

as @b707 explained you just have to create a separate directory, copy the files into this and convert your bitmap into the appropriate format.

If you google for tractor10_96x64 you find this page

https://github.com/prenticedavid/MCUFRIEND_kbv/blob/master/examples/drawBitmap_kbv/bitmap_RGB.h

where David uploaded a file called bitmap_RGB.h. It contains the image data and provides a link to an online tool that does the required conversion:

// several programs can convert BMP, JPG, PNG images to C arrays of pixels
// these used the utility bundled with UTFT. 
// Online tool at http://www.rinkydinkelectronics.com/t_imageconverter565.php

Good luck!
ec2021

This is the beginning of the file generated by the ImageConverter at the rinkydinkelectronics.com. (Original jpg image is from the Adafruit_ImageReader library).

The original image file is wales.jpg, the file generated by the ImageConverter is wales.c.
The wales.c file is directly usable, with only two changes. Change the file extension from .c to .h, and change the "const unsigned short" to "const uint16_t".

// Generated by   : ImageConverter 565 Online
// Generated from : wales.png
// Time generated : Tue, 11 Feb 25 00:25:42 +0100  (Server timezone: CET)
// Image Size     : 67x41 pixels
// Memory usage   : 5494 bytes


#if defined(__AVR__)
    #include <avr/pgmspace.h>
#elif defined(__PIC32MX__)
    #define PROGMEM
#elif defined(__arm__)
    #define PROGMEM
#endif

const unsigned short wales[2747] PROGMEM={

Place the wales.h file in the same folder as your Arduino sketch, then use the following line to include it in the code:

#include "wales.h"

Notice the image size of 67x41, that is the size you will need in the function call:

    tft.drawRGBBitmap(0, 0, wales, 67, 41);

How large is your image? Even with a Mega you are going to be limited to a small portion of a 240x320 display unless you want to do some library modifications to use the upper part of PROGMEM for storing the image.

Hi David, many thanks for that.... I'm not really sure about what I was doing previously but it was all based on the David Prentice sketch I downloaded and modified. The result of that was the sketch and associated include files were not placed in the same folder by me (at least not knowingly!) and so as I had found his image files buried in my file structure in a temp folder, I think I was trying to put mine there too...all whilst scratching my head over why this so difficult! Someone else said that the image should be with the .ino.....doh! It simply did not occur to me!

Once I had made that not so enormous step and fixed a number of other self inflicted errors I discovered that my file was indeed too large. Some amount of fiddling later and it is all sorted. I discovered the change from const unsigned short the hard way unfortunately, but thank you for that, if I had monitored my emails rather than having my head stuck in my arduino, you would have saved me lot of further bother!

Incidently, I haven't changed from a .c file...and it works fine.

Really appreciated everybody's support....baldness was rapidly approaching!

Best regards,

Damien

One question about your comment

Are you using the setTextSize() function to scale up a font? That will result in blocky looking characters, because it just scales up each pixel to a block of pixels. To get nice looking characters at a larger size, it is necessary to have a font file that has been encoded at the desired size. The MCUFRIEND_kbv library uses the font files from the Adafruit GFX library, which has a selection of sizes for many of the fonts, as well as a fontconvert utility for generating custom fonts. Unfortunately the larger the font size, the more memory it takes to store, but that can be minimized by removing characters that are never used. That can be very useful if you only need to display numbers, or only need a handful of letters, etc.

Dear All

As now may be obvious as a result of my response to David_2018, I have fixed my problem with all your assistance - thank you.

Cause: Major blindspot!

Background: I downloaded a relevant sketch by Dave Prentice and whilst I can't now recall how I did it, I didn't create the sketch by the conventional File-> New Sketch method...all of that must have occurred automatically as a result of the way I downloaded it. The consequence was that I didn't know where the bitmap called for by David's sketch was, I certainly didn't download it and 'put it in the same folder as my .ino'!. Unfortunately, when I searched for it, I could only find it buried multiple levels down in my file structure in a temp folder.

Result: One very confused programmer.

Verdict: Mountain out of a molehill....it is indeed trivial!
Method: Put the bitmap in the same folder that contains the sketch file (.ino) and the call for it will find it there. Doh! Simples!

Yes to using setTextSize() function...because that was all I knew about when I started this development. I understand about creating a better sized font but have struggled to find a suitable font small enough. If I recall correctly, the Adafruit fonts listed are all way too big (and are still rather too blocky. I shall redouble my efforts! It's actually a numeric display I am creating so could possibly truncate a font file to just cover the numbers if memory size becomes an issue.

Thanks again for your advice...hopefully I'm not on top of this and can concentrate on the hardware again.

Just to add a little more detail:

  1. Convert required bitmap to a hex file using an online UTFT converter such as imageconverter565.php from here: Rinky-Dink Electronics
    This returns a .c file. Save this to the same folder where your sketch lives.

  2. Find the following line in the .c file:
    const unsigned short [nnnn] PROGMEM={
    Change it to:
    const uint16_t [nnnn] PROGMEM={

  3. #include this .c file in your sketch

  4. Edit the draw command in your sketch to call for as in 2) above:
    drawRGBBitmap(55, 0, ****l, 200, 45);

(where 55,0 and 200, 45 are my start XY position and size of the bitmap)

And that should work.