New library for Mega and low cost HX8357B/C and ILI9481 480 x 320 displays

I have updated the HX8357 library here to include an example which draws bitmaps off an SD Card. The test images are stored in the "extras" folder within the library.

Also new member functions have been added to draw outline ellipses and filled ellipses, a new example is included.

@lightcalamar

The display is doing exactly what you would expect.

The code in loop() runs repeatedly so you are drawing text, clearing the display and then repeating this over and over again.

Put this at the end of the loop and the code will "stop" there until the Arduino is rebooted:

while(1);

If you look at the simple "blink" example sketch and understand how the LED is flashed on and off you will grasp what is happening.

Hello,

I started using your library with Arduino Due. You have done a great job! It works great!

I think I have discovered a small bug though.

I use the following commands to print a String

tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawCentreString(charBuf,240,25,2);

It works ok.

If I then use the function

tft.setTextSize(6);

and then run the same 2 commands

tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawCentreString(charBuf,240,25,2);

the text that it draws is not of size 2, as it is defined in the function but 6. In order this to work we have to call the tft.setTextSize(2) in order the font to be printed at a size of two.

tft.setTextSize(2);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawCentreString(charBuf,240,25,2);

Thank you very much for providing this great library!

@nickthegreek82

I can't reproduce the bug, check if the sketch is writing past the end of the charBuf array when filling it... Can you post a complete simplified example sketch that fails?

Hello, the library is working well with an Arduino Mega and this LCD:

http://www.aliexpress.com/item/Free-shipping-3-2-inch-TFT-LCD-screen-module-Ultra-HD-320X480-for-Arduino-MEGA-2560/32255199317.html

In my application I would like to turn the LCD off using code, but there does not seem to be any command for this in this library, any ideas?

@kiwiwarwick

It depends what you mean by "off".

If you want to save power then ideally we would turn off the LEDs, but unfortunately the backlight LEDs are hard wired on the PCB tot he 5V power line.

The TFT driver can be put into a power down state via a command but the LED's are the big consumer.

It would be possible to hack the board and add a transistor to control the LED power but that required some electronics hardware knowledge and additional parts.

bodmer:
@kiwiwarwick

It depends what you mean by "off".

If you want to save power then ideally we would turn off the LEDs, but unfortunately the backlight LEDs are hard wired on the PCB tot he 5V power line.

The TFT driver can be put into a power down state via a command but the LED's are the big consumer.

It would be possible to hack the board and add a transistor to control the LED power but that required some electronics hardware knowledge and additional parts.

Thanks for the quick reply, I was wanting to save power on a battery based project, I did want to shut off the backlight. I'll look at using a transistor to shut off the entire system, including the Mega (it's just a backup for if a user forgets to turn it off after use). Thanks again.

HI, I have a ili9481 lcd tft 3.5 inch and I tried it with your library and it doesn't work.

this is link to my product, LINK

And when I do with mcufriend_kvb library get_ID, I get 0x0000. So I am very confused.

And maybe this picture will help
(blob:https%3A//drive.google.com/e6f067cc-b319-44d5-a3f7-1de921c99a59)

I hope wefind an answer

You have posted in Bodmer's library thread.

You have a regular Mcufriend UNO shield with an ILI9481 controller. This particular shield does NOT have a Touch Panel.

The URL for your "picture" does not seem to do anything.

Your shield should work straight out of the box with the MCUFRIEND_kbv library.
First off, you should plug the shield into your Uno or Mega2560.

If you still have a problem, please post a photo of your shield mated with your Arduino.
Post the message on a MCUFRIEND_kbv thread.

David.

So , the seller replied to me and I got it half-working with his modified adafruit library. The colours work but fillscreen(BLACK); doesn't work.

Your product link works. It shows a shield that I actually possess and I have tested.
As I said, your picture link does not work.

If your product link does not match your shield, anything might work or not.

David.

No, the picture in product link matches my shield exactly

@ladicek

The Mega variant of the library does not support that display as it has an 8 bit interface.

The Due library does support that display in 8 bit mode, but I am guessing you do not have a Due to try.

I have tested your Library and work fine for my tft display HX8357B on Mega2560.
the display is on ebay. http://www.ebay.it/itm/3-2-Inch-320-X-480-TFT-LCD-Display-Module-Support-Arduino-Mega2560-/121959156813?hash=item1c65550c4d:g:6kkAAOSwYmZXE1cM

I want to know if we can use shift registars with this lcd to save IO pins on Mega 2560?
on SPI or I2C Interface.

asghar144:
I want to know if we can use shift registars with this lcd to save IO pins on Mega 2560?
on SPI or I2C Interface.

Yes, but you would need to build a suitable circuit and make significant changes to the library or write your own. I don't think it would be worth the effort and display updates would end up being quite slow in comparison to the faster 16 bit parallel interface. It would be easier to find a suitable SPI display and compatible library.

The Mega has a lot of digital I/O pins so I am surprised you are running out!

The library has been updated to work with mcufriend 3.5" displays that use a 16 bit interface and the ILI9486 driver. More details on the display in this thread. Note that the PCB in this case indicates a ILI9488 driver but that is misleading.

I want make a cursor line on the tft screen. It is a line with inverse colors.
Need a function that returns the color of the pixel on the screen.
Something like this: TColor GetColor(int x,int y);
How to do it?

It is very simple to make an inverse cursor if you can read the screen.
Unfortunately, most of these 16-bit shields are write-only.

So you would have to keep a copy of whatever you wrote onto the screen. And then write the inverse.
This would be ok if you have a big RAM to store your screen contents. e.g. 320x480x16 bits = 307200 bytes.

If your cursor position is always known, you can get away with a smaller buffer e.g. the length of the cursor x 2 bytes. Just redraw the background. Much like in the analog meter examples. e.g. repaint the old background, draw the new meter needle.

You can implement your idea easily on Mcufriend Uno shields with my library. No extra RAM is needed but it will be quicker if you do it in say 16-pixel chunks.

David.

@roman12

An inverse colour is a "NOT" of all bits, so !TFT_RED will display as cyan.

Thus you can simply set the text foreground and background colours as the inverse of the text you would otherwise print at the cursor. The cursor can be simply a "space" or an underscore "_". If you really want you can even flash the cursor by overprinting with normal and inverse colours in a delay loop.

bodmer:
@roman12

An inverse colour is a "NOT" of all bits, so !TFT_RED will display as cyan.

Thus you can simply set the text foreground and background colours as the inverse of the text you would otherwise print at the cursor. The cursor can be simply a "space" or an underscore "_". If you really want you can even flash the cursor by overprinting with normal and inverse colours in a delay loop.

Need is the graphics cursor (a vertical inverse line over the graph of a function). That is needed a function of reading the color of a specific point of the video memory. But if screen video memory is write-only, the question is removed.