Hello everybody !
I’m quite new to Arduino, so apologize in advance if I say monstrous things about Arduino’s operating mode…
English isn’t my native language… I do my best to write without mistakes, apologize if it’s awful to read…
I’ve got to lead a very simple project : displaying images on a 2.4" 320x240 screen from a SD Card (even if I’m working on DUE, there is not enough RAM to handle 20+ bitmaps, that’s why I need them on SD card…)
I already consulted you (especially Dennis & Graham, so many thanks to them) for an SPI issue. Everything is working well now.
I consult you one more time, because I’m out of ideas and it’s been weeks that I’m stuck with this problem. Let me explain my trouble now :
Hardware and configuration:
- I’m working on a DUE with a TFT/LCD shield and a 2.4" TFT/LCD screen from Buydisplay.
Both shield and screen possess a SD Card slot, i’m using the one on the screen, its accessibility is the most convenient. - SD Card is a SanDisk, 4GB, Class 4, micro SDHC.
- Images are converted with Imageconverter565, a tool you find in UTFT library
- The image I want to display is the one Dennis gave me in the previous post linked above. You can find it joined to this post.
- I’m using software SPI, according to my shield :
[list][li]SCLK 2, MOSI 3, MISO 4[/li]
[li]TFT_CS 9, TFT_DC 7, TFT_RST 10[/li]
[li]Touch_CS 6, Touch_PEN 5[/li]
[li]SD_CS 8[/li][/list] [/li]
[/list]
[b]Trouble :[/b]
I use UTFT_SdRaw library to load my image on the screen.
I started with LANDSCAPE orientation. If I just use the command
[code]myFiles.load( 0, 0, 320, 240, "pic101.raw",1,0);[/code]in my function, it results in a white blank screen.
When I modify the command like this, the image is well displayed as a 240x180 image
[code] myFiles.load( 0, 0, 240, 180, "pic101.raw",180,0);[/code]As you can see, the bufmult is really HIGH ! I read many topics where Graham explained how this [color=teal]int load(int x, int y, int sx, int sy, char* filename, int bufmult, int iswap);[/color] function works and the highest bufmult I saw was 16 !!!!!
I tried every bufmult number from 1 to 180, and 180 is the only one displaying the picture entirely with no odd behavior (white lines, picture changing color before becoming white, starts to display well then stops, inverses colors, black and white moving lines appear before everything shades gently to white screen...)
I noticed I have no trouble displaying 240x180 images with the last command I wrote, they are well displayed without color inversion.
If I want to display a 320x240 picture, it's impossible. High bufmult numbers aren't handled by load function, it results a white screen or the screen drawn previously stays on... or odd behavior as I described above (and it's just a snippet...)
I thought it could be an orientation issue, so I update my screen set up from LANDSCAPE to PORTRAIT.
To display an image, I had to comment the part of the code in UTFT_SdRaw library which handles PORTRAIT displaying :
[code]int UTFT_SdRaw::load(int x, int y, int sx, int sy, char *filename, int bufmult, bool iswap)
{
char buf[2 * bufmult * sx];
int cx, cy, cp;
word result;
if (dataFile.open(filename))
{
cbi(_UTFT->P_CS, _UTFT->B_CS);
cx = 0;
cy = 0;
result = bufmult * sx;
/*if (_UTFT->orient == PORTRAIT) //Need to be commented to display
{ //
_UTFT->setXY(x, y, x + sx - 1, y + sy - 1); //
}*/ //
for (int n = 0; n < sy; n += bufmult)
{
result = dataFile.read(&buf, (2 * bufmult) * sx);
/*if (_UTFT->orient == PORTRAIT) //
{ //
for (int i = 0; i < result; i += 2) //
{ //
if (iswap == 1) //
{ //
_UTFT->LCD_Write_DATA(buf[i + 1], buf[i]); //
} //
else //
{ //
_UTFT->LCD_Write_DATA(buf[i], buf[i + 1]); //
} //
} //
} //
else //
{*/ //
cp = 0;
while (cp < result)
{
if (((result - cp) / 2) < (sx - cx))
{
_UTFT->setXY(x + cx, y + cy, x + cx + ((result - cp) / 2) - 1, y + cy);
for (int i = (result - cp) - 2; i >= 0; i -= 2)
{
if (iswap == 1)
{
_UTFT->LCD_Write_DATA(buf[cp + i + 1], buf[cp + i]);
}
else
{
_UTFT->LCD_Write_DATA(buf[cp + i], buf[cp + i + 1]);
}
}
cx += ((result - cp) / 2);
cp = result;
}
else
{
_UTFT->setXY(x + cx, y + cy, x + sx - 1, y + cy);
for (int i = sx - cx - 1; i >= 0; i--)
{
if (iswap)
{
_UTFT->LCD_Write_DATA(buf[cp + (i * 2) + 1], buf[cp + (i * 2)]);
}
else
{
_UTFT->LCD_Write_DATA(buf[cp + (i * 2)], buf[cp + (i * 2) + 1]);
}
}
cp += (sx - cx) * 2;
cx = 0;
cy++;
//} //
}
}
}
dataFile.close();
_UTFT->setXY(0, 0, _UTFT->getDisplayXSize() - 1, _UTFT->getDisplayYSize() - 1);
sbi(_UTFT->P_CS, _UTFT->B_CS);
return 0;
}
else
{
return 99;
}
}[/code]
And this was ONLY to display something on screen. If I uncomment those lines the screen stays on the one drawn previously and the sketch stops running. Nothing tries to display the picture on screen...
And it's the same command as LANDSCAPE orientation that allows to display the image, with a high number for bufmult...
[code]myFiles.load( 0, 0, 240, 180, "pic101.raw",180,0);[/code]
I'm not an expert, only a novice. It seems the bufmult number has to be [color=teal]int sy[/color]. It only works with 240x180 image. If I apply the same thing for 320x240 image (bufmult = 240) nothing appears on screen. If bufmult = 1, I only have a white screen... other numbers under 100 result in odd behavior...
I don't know why but the load function isn't used correctly here... I don't have enough knowledge to understand what is going on here... That's why I'm asking for your help with this strange case... It's really impossible to display correctly a 320x240 sized image even if the screen size is 320x240 (I really tried EVERY number for bufmult...)
My post is too big, you'll get my sketch as well as the spec of my shield & screen on the next post ... (to be continued...)
[pic101.zip|attachment](upload://iNnpYICJG85P4XGwSNA6byZXdvn.zip) (31.9 KB)