need help: UTFT drawBitmap with char array

Hello,

im trying to "convert" a char array to a short array which is then supposed to be draw on my LCD-display using the UTFT library and its drawBitmap function.

The problem is, it doesnt.

Why do I do that? Well not a single SD-Card I tried (4 different) worked with any Library I tried (SD.h, SDFat.h, tinyFat) and after searching for MANY hours without finding any solution I came to the idea to use the Mega's 252kB flash memory, but that will only work if I get this working because I want to fit 20 images in there, with each being 13kB when stored as short I will run out of it pretty quick.

To the SD-Cards:
No, my wiring is not wrong and yes, I used the SD Card Formatter tool everyone tells you to use.

To explain the code a bit:
every value stored in the char array is shifted left a total of 8 times(from 0 to 7) and after every shift compared to 0x1, if it returns true then 0xFFFF is written a dummy array, else 0x0000.

To keep the RAM from exploding the drawBitmap function is run after the dummy array is filled with 136 (W*2) values and then overwrite them in the next call of my converter function.

Tried to check the contents of my dummy array using Serial.print but as expected it does not return anything...

PLEASE help me.

Greetings,
Tsarga

#include <avr/pgmspace.h>
#include <UTFT.h>

#define LED_A  45

#define H 96 // Height of the image
#define W 68 // Width of the image
#define DoubleRow       W*2
#define DoubleRow_Bit   DoubleRow/8

UTFT myGLCD(SSD1963_480, 44, 43, 42, 41);

int dummy[DoubleRow];

// this is the array i want to convert to a short
const unsigned char Airflow2[]PROGMEM = {
  0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0,
  15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0,
  0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
  0, 0, 0, 0, 15, 0, 0, 0, 1, 216, 0, 0, 0, 15, 0, 224,
  96, 3, 216, 0, 0, 0, 15, 0, 224, 96, 3, 24, 0, 0, 0, 15,
  1, 176, 0, 3, 24, 0, 0, 0, 15, 1, 176, 99, 103, 216, 60, 97,
  134, 15, 1, 176, 99, 231, 216, 126, 97, 134, 15, 3, 24, 99, 131, 24,
  231, 51, 204, 15, 3, 24, 99, 3, 24, 195, 51, 204, 15, 7, 252, 99,
  3, 24, 195, 50, 76, 15, 7, 252, 99, 3, 24, 195, 30, 120, 15, 6,
  12, 99, 3, 24, 231, 30, 120, 15, 12, 6, 99, 3, 24, 126, 12, 48,
  15, 12, 6, 99, 3, 24, 60, 12, 48, 15, 0, 0, 0, 0, 0, 0,
  0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
  0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0,
  0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15,
  0, 0, 0, 0, 7, 240, 0, 0, 15, 0, 0, 0, 127, 248, 31, 128,
  0, 15, 0, 0, 1, 128, 0, 0, 112, 0, 15, 0, 0, 6, 0, 0,
  0, 12, 0, 15, 0, 0, 4, 0, 0, 0, 6, 0, 15, 0, 0, 8,
  0, 0, 0, 1, 0, 15, 0, 0, 8, 0, 0, 0, 1, 128, 15, 0,
  0, 8, 0, 0, 0, 1, 128, 15, 0, 0, 16, 0, 0, 0, 7, 0,
  15, 0, 96, 16, 0, 0, 0, 24, 0, 15, 0, 240, 16, 0, 0, 0,
  112, 0, 15, 1, 16, 16, 0, 0, 1, 128, 0, 15, 3, 16, 16, 0,
  0, 7, 0, 0, 15, 2, 8, 16, 0, 0, 8, 0, 0, 15, 4, 12,
  16, 0, 0, 112, 0, 0, 15, 4, 4, 16, 0, 0, 64, 0, 0, 15,
  4, 4, 16, 0, 1, 129, 255, 192, 15, 8, 2, 16, 0, 1, 3, 0,
  56, 15, 8, 3, 24, 0, 3, 4, 0, 6, 15, 8, 1, 8, 0, 4,
  8, 0, 2, 15, 8, 1, 4, 0, 4, 16, 0, 1, 15, 8, 0, 130,
  0, 4, 16, 0, 1, 15, 24, 0, 129, 128, 4, 32, 0, 0, 143, 16,
  0, 192, 96, 8, 32, 0, 0, 143, 16, 0, 32, 28, 8, 64, 0, 0,
  143, 16, 0, 56, 3, 8, 64, 0, 0, 143, 16, 0, 8, 1, 248, 64,
  0, 0, 143, 16, 0, 4, 1, 4, 128, 0, 0, 143, 16, 0, 3, 195,
  3, 128, 0, 0, 143, 8, 0, 0, 60, 1, 0, 0, 0, 143, 8, 0,
  0, 4, 1, 0, 0, 0, 143, 8, 0, 0, 4, 1, 0, 0, 0, 143,
  8, 0, 0, 4, 1, 0, 0, 0, 143, 8, 0, 0, 4, 1, 224, 0,
  0, 143, 8, 0, 0, 14, 6, 30, 0, 0, 79, 8, 0, 0, 9, 4,
  1, 0, 0, 79, 8, 0, 0, 16, 252, 0, 128, 0, 79, 8, 0, 0,
  16, 134, 0, 224, 0, 79, 8, 0, 0, 16, 129, 192, 32, 0, 79, 8,
  0, 0, 32, 128, 48, 24, 0, 79, 8, 0, 0, 33, 0, 12, 8, 0,
  207, 4, 0, 0, 65, 0, 2, 8, 0, 143, 4, 0, 0, 65, 0, 1,
  4, 0, 143, 2, 0, 0, 129, 0, 0, 132, 0, 143, 3, 0, 1, 6,
  0, 0, 198, 0, 143, 0, 224, 6, 4, 0, 0, 66, 0, 143, 0, 31,
  252, 12, 0, 0, 65, 1, 15, 0, 0, 0, 16, 0, 0, 65, 1, 15,
  0, 0, 0, 112, 0, 0, 65, 129, 15, 0, 0, 0, 128, 0, 0, 64,
  130, 15, 0, 0, 7, 0, 0, 0, 64, 70, 15, 0, 0, 12, 0, 0,
  0, 64, 68, 15, 0, 0, 112, 0, 0, 0, 64, 120, 15, 0, 0, 192,
  0, 0, 0, 64, 48, 15, 0, 7, 0, 0, 0, 0, 64, 0, 15, 0,
  12, 0, 0, 0, 0, 128, 0, 15, 0, 12, 0, 0, 0, 0, 128, 0,
  15, 0, 4, 0, 0, 0, 0, 128, 0, 15, 0, 3, 0, 0, 0, 1,
  0, 0, 15, 0, 1, 128, 0, 0, 3, 0, 0, 15, 0, 0, 112, 0,
  0, 12, 0, 0, 15, 0, 0, 15, 192, 255, 240, 0, 0, 15, 0, 0,
  0, 127, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15,
  0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0,
};


// this is my function to convert my char array to a short array
void converter(unsigned short out[DoubleRow], char in[DoubleRow_Bit], int row) {
  for (int x = DoubleRow_Bit * row; x < DoubleRow_Bit * (row + 1); x ++) {
    ////////////////////////////////////////////
    if (( (in[x] >> 7) & 0x1) == 1) {
      out[x * 8] = 0xFFFF;
    }
    else {
      out[x * 8] = 0x0000;
    }
    //////////////////////////////////////////
    if (( (in[x] >> 6) & 0x1) == 1) {
      out[(x * 8) + 1] = 0xFFFF;
    }
    else {
      out[(x * 8) + 1] = 0x0000;
    }
    ////////////////////////////////////////////
    if (( (in[x] >> 5) & 0x1) == 1) {
      out[(x * 8) + 2] = 0xFFFF;
    }
    else {
      out[(x * 8) + 2] = 0x0000;
    }
    ////////////////////////////////////////////
    if (( (in[x] >> 4) & 0x1) == 1) {
      out[(x * 8) + 3] = 0xFFFF;
    }
    else {
      out[(x * 8) + 3] = 0x0000;
    }
    ////////////////////////////////////////////
    if (( (in[x] >> 3) & 0x1) == 1) {
      out[(x * 8) + 4] = 0xFFFF;
    }
    else {
      out[(x * 8) + 4] = 0x0000;
    }
    ////////////////////////////////////////////
    if (( (in[x] >> 2) & 0x1) == 1) {
      out[(x * 8) + 5] = 0xFFFF;
    }
    else {
      out[(x * 8) + 5] = 0x0000;
    }
    ////////////////////////////////////////////
    if (( (in[x] >> 1) & 0x1) == 1) {
      out[(x * 8) + 6] = 0xFFFF;
    }
    else {
      out[(x * 8) + 6] = 0x0000;
    }
    ////////////////////////////////////////////
    if (( (in[x] >> 0) & 0x1) == 1) {
      out[(x * 8) + 7] = 0xFFFF;
    }
    else {
      out[(x * 8) + 7] = 0x0000;
    }

    Serial.print(out[(x * 8) + 0]);
    Serial.print(", ");
    Serial.print(out[(x * 8) + 1]);
    Serial.print(", ");
    Serial.print(out[(x * 8) + 2]);
    Serial.print(", ");
    Serial.print(out[(x * 8) + 3]);
    Serial.print(", ");
    Serial.print(out[(x * 8) + 4]);
    Serial.print(", ");
    Serial.print(out[(x * 8) + 5]);
    Serial.print(", ");
    Serial.print(out[(x * 8) + 6]);
    Serial.print(", ");
    Serial.println(out[(x * 8) + 7]);
    //////////////////////////////////////////
  }
}

void setup(void)
{
  Serial.begin(115200);
  pinMode(LED_A, OUTPUT);
  digitalWrite(LED_A, HIGH);

  // Setup the LCD
  myGLCD.InitLCD();
  myGLCD.clrScr();
}

void loop() {
//this loop will call the converter function and draw its results on my display, 2 lines each call
//in theory atleast....
  for (int i = 0; i <= H / 2; i++) {
    converter(dummy[DoubleRow], Airflow2[DoubleRow_Bit], i);
    myGLCD.drawBitmap(0, 2 * i, W, 2, dummy);
  }
  delay(10000);
}

To the SD-Cards:
No, my wiring is not wrong and yes, I used the SD Card Formatter tool everyone tells you to use.

So why isn't it working ? there must be a reason.. can't just give up :wink:

Deva_Rishi:
So why isn't it working ? there must be a reason.. can't just give up :wink:

well the best I got was SDFats's quickstart example, I got 3 different errorcodes:
errorCode: 0x30, errorData: 0x2
errorCode: 0x50, errorData: 0xc9
errorCode: 0x50, errorData: 0x0

and as far as I understand those are all read error codes....

Hmm i've been using SD.h (Arduino, Sparkfun v1.05) it's built-in. And i have never actually had any issue with it. i have 1 unit which is just a reader and i have a few TFT-touchscreen units (MCUfriend) which contain a micro-SD reader as well. I had some Micro-SD cards which already had been formatted and had stuff on them and i just used the 'listfile' example and it all just worked as i expected it would. When you put the sd-card into you computer do you have normal access to it ?

Deva_Rishi:
Hmm i've been using SD.h (Arduino, Sparkfun v1.05) it's built-in. And i have never actually had any issue with it. i have 1 unit which is just a reader and i have a few TFT-touchscreen units (MCUfriend) which contain a micro-SD reader as well. I had some Micro-SD cards which already had been formatted and had stuff on them and i just used the 'listfile' example and it all just worked as i expected it would. When you put the sd-card into you computer do you have normal access to it ?

I use the sd-card reader build into my SSD1963 display
and all of them work fine with my computer

OK so just to confirm, you are using the Mega and the SPI pins of the SD-card are connected to pins 50, 51 & 52 ? and you are using a CS pin (53 ?) then what is the result when you run this

#include <SPI.h>
#include <SD.h>

#define CS_PIN 53

File root;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.print("Initializing SD card...");

  if (!SD.begin(CS_PIN)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  root = SD.open("/");

  printDirectory(root, 0);

  Serial.println("done!");
}

void loop()
{
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs) {
   while(true) {
     
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

Listfiles example ?

Deva_Rishi:
OK so just to confirm, you are using the Mega and the SPI pins of the SD-card are connected to pins 50, 51 & 52 ? and you are using a CS pin (53 ?) then what is the result when you run this

#include <SPI.h>

#include <SD.h>

#define CS_PIN 53

File root;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.print("Initializing SD card...");

if (!SD.begin(CS_PIN)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

root = SD.open("/");

printDirectory(root, 0);

Serial.println("done!");
}

void loop()
{
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs) {
  while(true) {
   
    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i=0; i<numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs+1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}


Listfiles example ?

I use pin 8 as my SS and here are the result of 3 SD-Cards, changed the CS_PIN define to 8

Initializing SD card...initialization failed!
for all 3 of them

even when I route my chipselect to pin 53 and define it that way nothing changes

SPI pins of the SD-card are connected to pins 50, 51 & 52 ?

If so then your card reader must be broken or the reader only supports FAT16 (you could try formatting it that way). Either way i would consider just ordering a single card-reader (without the whole TFT screen attached)and see if you can get that to work because i think the avenue of putting your bitmap images in progmem is not the way to go. Actually i'd say to get yourself an ESP unit of some kind and use FFS is already more flexible.