Not able to display Image on ili9846 display.

Hi Everyone, I am new to arduino and I have been assigned to work on that without any prior experience. I am trying one example which displays Image from sd card which is on the backside of the LCD display module. My LCD display hardware is ili9486 and i am using arduino uno board. Below is the code which i have loaded on the board. it is compiling and loading successfully. i am also able to initialize the sd card. its able to get the image file from sd card and say drawing. but there is no image being displayed on lcd screen. I have also attached the image which i am trying to load. Please someone help me with this.

// include the necessary libraries
#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Arduino LCD library

// pin definition for the Uno
#define sd_cs 10
#define lcd_cs 10
#define dc 9
#define rst 8

// pin definition for the Leonardo
//#define sd_cs 8
//#define lcd_cs 7
//#define dc 0
//#define rst 1

TFT TFTscreen = TFT(lcd_cs, dc, rst);

// this variable represents the image to be drawn on screen
PImage logo;

void setup() {
// initialize the GLCD and show a message
// asking the user to open the serial line
TFTscreen.begin();
TFTscreen.background(255, 255, 255);

TFTscreen.stroke(0, 0, 255);
TFTscreen.println();
TFTscreen.println(F(“Arduino TFT Bitmap Example”));
TFTscreen.stroke(0, 0, 0);
TFTscreen.println(F(“Open serial monitor”));
TFTscreen.println(F(“to run the sketch”));

// initialize the serial port: it will be used to
// print some diagnostic info
Serial.begin(9600);
while (!Serial) {
// wait for serial port to connect. Needed for native USB port only
}

// clear the GLCD screen before starting
TFTscreen.background(255, 255, 255);

// try to access the SD card. If that fails (e.g.
// no card present), the setup process will stop.
Serial.print(F(“Initializing SD card…”));
if (!SD.begin(sd_cs)) {
Serial.println(F(“failed!”));
return;
}
Serial.println(F(“OK!”));

// initialize and clear the GLCD screen
TFTscreen.begin();
TFTscreen.background(255, 255, 255);

// now that the SD card can be access, try to load the
// image file.
logo = TFTscreen.loadImage(“arduino.bmp”);
if (!logo.isValid()) {
Serial.println(F(“error while loading arduino.bmp”));
}
}

void loop() {
// don’t do anything if the image wasn’t loaded correctly.
if (logo.isValid() == false) {
return;
}

Serial.println(F(“drawing image”));

// get a random location where to draw the image.
// To avoid the image to be draw outside the screen,
// take into account the image size.
int x = random(TFTscreen.width() - logo.width());
int y = random(TFTscreen.height() - logo.height());

// draw the image to the screen
TFTscreen.image(logo, x, y);

// wait a little bit before drawing again
delay(1500);
}

Below is the message i am getting on the serial monitor.

20:49:31.306 → Initializing SD card…OK!
20:49:33.865 → File size: 1451854
20:49:33.865 → Image Offset: 54
20:49:33.899 → Header size: 40
20:49:33.899 → Bit Depth: 24
20:49:33.933 → Image size: 793x610
20:49:33.933 → drawing image
20:49:35.397 → drawing image
20:49:36.905 → drawing image
20:49:40.347 → drawing image
20:49:41.847 → drawing image
20:49:43.350 → drawing image
20:49:44.858 → drawing image
20:49:46.373 → drawing image
20:49:48.046 → drawing image
20:49:49.552 → drawing image
20:49:51.058 → drawing image
20:49:52.565 → drawing image
20:49:54.074 → drawing image
20:49:55.574 → drawing image

Please post alink to the actual display that you have bought. e.g. Ebay sale.

The "TFT.h" library is for SPI ST7735 displays. And it is pants.

David.

Hi David,

Thanks for the Reply. Below is the link from where the display was bought.

I understand your point. but the display, sd card is getting initialized with the example.

Please let me know how to proceed. if you can give me an example code to display an image for the same, it would be of great help in understanding for me. i am completely new to arduino.

Below code which i got from examples in arduino ide works on the display.

// UTFT_Demo_480x320
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution
// of 480x320 pixels.
//
// This program requires the UTFT library.
//

//################################################
// GLUE class that implements the UTFT API
// replace UTFT include and constructor statements
// remove UTFT font declaration e.g. SmallFont
//################################################

#include <UTFTGLUE.h> //use GLUE class and constructor
UTFTGLUE myGLCD(0,A2,A1,A3,A4,A0); //all dummy args

// Declare which fonts we will be using
//extern uint8_t SmallFont; //GLUE defines as GFXFont ref

// Set the pins to the correct ones for your development shield
// ------------------------------------------------------------
// Arduino Uno / 2009:
// -------------------
// Standard Arduino Uno/2009 shield : ,A5,A4,A3,A2
// DisplayModule Arduino Uno TFT shield : ,A5,A4,A3,A2
//
// Arduino Mega:
// -------------------
// Standard Arduino Mega/Due shield : ,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Mega : ,38,39,40,41
//
// Remember to change the model parameter to suit your display module!
//UTFT myGLCD(CTE32HR,38,39,40,41);

void setup()
{
randomSeed(analogRead(0));

// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}

void loop()
{
int buf[478];
int x, x2;
int y, y2;
int r;

// Clear the screen and draw the frame
myGLCD.clrScr();

myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 479, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 306, 479, 319);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
myGLCD.setBackColor(64, 64, 64);
myGLCD.setColor(255,255,0);
myGLCD.print(“http://www.RinkyDinkElectronics.com/”, CENTER, 307);

myGLCD.setColor(0, 0, 255);
myGLCD.drawRect(0, 14, 479, 305);

// Draw crosshairs
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(239, 15, 239, 304);
myGLCD.drawLine(1, 159, 478, 159);
for (int i=9; i<470; i+=10)
myGLCD.drawLine(i, 157, i, 161);
for (int i=19; i<220; i+=10)
myGLCD.drawLine(237, i, 241, i);

// Draw sin-, cos- and tan-lines
myGLCD.setColor(0,255,255);
myGLCD.print(“Sin”, 5, 15);
for (int i=1; i<478; i++)
{
myGLCD.drawPixel(i,159+(sin(((i*1.13)*3.14)/180)*95));
}

myGLCD.setColor(255,0,0);
myGLCD.print(“Cos”, 5, 27);
for (int i=1; i<478; i++)
{
myGLCD.drawPixel(i,159+(cos(((i*1.13)*3.14)/180)*95));
}

myGLCD.setColor(255,255,0);
myGLCD.print(“Tan”, 5, 39);
for (int i=1; i<478; i++)
{
myGLCD.drawPixel(i,159+(tan(((i*1.13)*3.14)/180)));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(239, 15, 239, 304);
myGLCD.drawLine(1, 159, 478, 159);

// Draw a moving sinewave
x=1;
for (int i=1; i<(47815); i++)
{
x++;
if (x==479)
x=1;
if (i>479)
{
if ((x==239)||(buf[x-1]==159))
myGLCD.setColor(0,0,255);
else
myGLCD.setColor(0,0,0);
myGLCD.drawPixel(x,buf[x-1]);
}
myGLCD.setColor(0,255,255);
y=159+(sin(((i
0.7)3.14)/180)(90-(i / 100)));
myGLCD.drawPixel(x,y);
buf[x-1]=y;
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some filled rectangles
for (int i=1; i<6; i++)
{
switch (i)
{
case 1:
myGLCD.setColor(255,0,255);
break;
case 2:
myGLCD.setColor(255,0,0);
break;
case 3:
myGLCD.setColor(0,255,0);
break;
case 4:
myGLCD.setColor(0,0,255);
break;
case 5:
myGLCD.setColor(255,255,0);
break;
}
myGLCD.fillRect(150+(i20), 70+(i20), 210+(i20), 130+(i20));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some filled, rounded rectangles
for (int i=1; i<6; i++)
{
switch (i)
{
case 1:
myGLCD.setColor(255,0,255);
break;
case 2:
myGLCD.setColor(255,0,0);
break;
case 3:
myGLCD.setColor(0,255,0);
break;
case 4:
myGLCD.setColor(0,0,255);
break;
case 5:
myGLCD.setColor(255,255,0);
break;
}
myGLCD.fillRoundRect(270-(i20), 70+(i20), 330-(i20), 130+(i20));
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some filled circles
for (int i=1; i<6; i++)
{
switch (i)
{
case 1:
myGLCD.setColor(255,0,255);
break;
case 2:
myGLCD.setColor(255,0,0);
break;
case 3:
myGLCD.setColor(0,255,0);
break;
case 4:
myGLCD.setColor(0,0,255);
break;
case 5:
myGLCD.setColor(255,255,0);
break;
}
myGLCD.fillCircle(180+(i20),100+(i20), 30);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some lines in a pattern
myGLCD.setColor (255,0,0);
for (int i=15; i<304; i+=5)
{
myGLCD.drawLine(1, i, (i1.6)-10, 304);
}
myGLCD.setColor (255,0,0);
for (int i=304; i>15; i-=5)
{
myGLCD.drawLine(478, i, (i
1.6)-11, 15);
}
myGLCD.setColor (0,255,255);
for (int i=304; i>15; i-=5)
{
myGLCD.drawLine(1, i, 491-(i1.6), 15);
}
myGLCD.setColor (0,255,255);
for (int i=15; i<304; i+=5)
{
myGLCD.drawLine(478, i, 490-(i
1.6), 304);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some random circles
for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=32+random(416);
y=45+random(226);
r=random(30);
myGLCD.drawCircle(x, y, r);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some random rectangles
for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=2+random(476);
y=16+random(289);
x2=2+random(476);
y2=16+random(289);
myGLCD.drawRect(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

// Draw some random rounded rectangles
for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=2+random(476);
y=16+random(289);
x2=2+random(476);
y2=16+random(289);
myGLCD.drawRoundRect(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

for (int i=0; i<100; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
x=2+random(476);
y=16+random(289);
x2=2+random(476);
y2=16+random(289);
myGLCD.drawLine(x, y, x2, y2);
}

delay(2000);

myGLCD.setColor(0,0,0);
myGLCD.fillRect(1,15,478,304);

for (int i=0; i<10000; i++)
{
myGLCD.setColor(random(255), random(255), random(255));
myGLCD.drawPixel(2+random(476), 16+random(289));
}

delay(2000);

myGLCD.fillScr(0, 0, 255);
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect(160, 70, 319, 169);

myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print(“That’s it!”, CENTER, 93);
myGLCD.print(“Restarting in a”, CENTER, 119);
myGLCD.print(“few seconds…”, CENTER, 132);

myGLCD.setColor(0, 255, 0);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print(“Runtime: (msecs)”, CENTER, 290);
myGLCD.printNumI(millis(), CENTER, 305);

delay (10000);
}

I also tried the given example below. But still the display keeps on blinking white.

// Arduino SD image viewer
// Written by Stanley Huang stanleyhuangyc@gmail.com
//
// This program requires the UTFT library.
//

#include <UTFT.h>
#include <SD.h>

// Declare which fonts we will be using
extern uint8_t SmallFont;
extern uint8_t BigFont;

// for Arduino 2009/Uno
UTFT myGLCD(ITDB28,19,18,17,16); // Remember to change the model parameter to suit your display module!

// for Arduino Mega
//UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to change the model parameter to suit your display module!

#define SD_PIN 10

File root;

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240

void ShowMessage(const char* msg1, const char* msg2 = 0)
{
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect(50, 190, 270, 230);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print(msg1, CENTER, 196);
if (msg2) myGLCD.print(msg2, CENTER, 210);
}

void LoadImage(File& file)
{
for (int y = 0; y < SCREEN_HEIGHT && file.available(); y++) {
uint16_t buf[SCREEN_WIDTH];
for (int x = SCREEN_WIDTH - 1; x >= 0; x–) {
byte l = file.read();
byte h = file.read();
buf = ((uint16_t)h << 8) | l;
}
//myGLCD.drawPixelLine(0, y, SCREEN_WIDTH, buf);
myGLCD.drawBitmap(0,0,793,610,buf);
}
}

void WalkDirectory(File dir)
{
for (;:wink: {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
if (entry.isDirectory()) {
WalkDirectory(entry);
} else {
ShowMessage(“Loading image from SD card”, entry.name());
LoadImage(entry);
}
entry.close();
// delay for a while between each image
delay(2000);
}
}

void setup()
{
// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myGLCD.fillScr(0, 0, 255);

pinMode(SD_PIN, OUTPUT);
if (!SD.begin(SD_PIN)) {
ShowMessage(“SD not ready”);
return;
}

delay(1000);
root = SD.open("/root");
WalkDirectory(root);

ShowMessage(“That’s the end of the show”, “Press RESET to start over”);
}

void loop()
{
}

Several libraries should work e.g.
TFT_HX8357 from Bodmer. Edit User_Setup.h for ILI9486
UTFT from Henning Karlsen. Use ILI9486 as model in constructor
MCUFRIEND_kbv. Edit files for USE_SPECIAL, USE_MEGA_16BIT_SHIELD, tft.begin(0x486)

I would advise TFT_HX8357

David.