Bitmaps from SD card with SSD1963 parallel TFT display

Status
Not open for further replies.

SomeoneFromGermany

Well-known member
Hello,

I tried to display bitmaps from an SD card with an Teensy 3.6 on a SSD1963 16bit parallel TFT display using the UTFT library.
The drawBitmap method takes an array of integers to display a bitmap, but there is no method to display files.

So i tried a rather stupid but simple way where i saved the bitmap as an String in the PROGMEM and tried to decode it by splitting the values by an ",".

Code:
//Include the Librarys
#include <UTFT.h>
#include <SD.h>
#include "icon.h"

//Extern font
extern uint8_t SmallFont[];

//Some variables
String iconStr;
unsigned short intValues[0x444];

//Creating UTFT instance
UTFT myGLCD(SSD1963_480, 38, 39, 22, 23);

void setup() {
  //Initializing stuff
  Serial.begin(115200);
  delay(1000);
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  //  SD.begin(BUILTIN_SDCARD);

  //copying the bitmap char* to RAM, converting it to a String an replacing stuff
  iconStr = icon;
  iconStr.replace("\n", "").replace(" ", "");

  //Print it
  Serial.println(icon);
  Serial.println(iconStr);

  //Set white background
  myGLCD.fillScr(255, 255, 255);

  //check if copy was successful
  if (iconStr.length() > 0) {
    //message
    Serial.println("Converting...");
    
    //Inizialise more variables
    String decod = "";
    unsigned long pos = 0;

    //Loop through the String byte by byte
    for (unsigned long x = 0; x < iconStr.length(); x++) {
      //current Char
      char currChar = iconStr.charAt(x);
      Serial.print(currChar);

      //Look if a new value started if not add current char to String
      if (currChar != ',')
        decod += currChar;
      else {
        //convert whole value to int and append it to the integer array
        intValues[pos] = strtoint(decod);
        Serial.print(decod);
        Serial.print("::");
        Serial.println(intValues[pos]);

        //increment array position and reset String
        pos++;
        decod = "";
      }
    }

    Serial.println("Finished.");

    //Drawing bitmap
    myGLCD.drawBitmap (0, 0, 362, 272, intValues, 1);
  }
}


void loop() {

}

int strhextoint(char in) {
  //returning char - 48/55 to get 0-F Hex values
  return (((int)in >= 48 && (int)in <= 57) * (in - 48))
         +
         (((int)in >= 65 && (int)in <= 70) * (in - 55));
}

int strtoint(String str) {
  unsigned int ret = 0x0;

  //looping to the String
  for (int i = 0; i < str.length(); i++) {

    //current char
    char currChar = str.charAt(i);

    //look if char is 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E or F
    if (((int)currChar >= 65 && (int)currChar <= 70) || ((int)currChar >= 48 && (int)currChar <= 57)) {

      //check if hex value is initialized with "0x"
      String zeroEx = currChar;
      zeroEx += str.charAt(i + 1);

      //if value is valid shift last value 4 times left and do bitwise or with value 0x0-0xF
      if (!zeroEx.equals("0x"))
        ret = ret << 4 | strhextoint(currChar);

      //else jump over "0x"
      else i++;

    //return -1 if invalid value
    } else return -1;

  }
  //return hex-string converted to integer
  return ret;
}

//the bitmap was defined like this in an other File:

#include <Arduino.h>

PROGMEM const char* icon = R"rawliteral(
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
...
0xFFFF, 0xFFFF, 0xFFFF, 0xF7DE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
)rawliteral";

This worked for one small icon used in a demo, but when i tried to use a bigger image the teensy kept resetting and reprogramming itself (maybe a RAM-size problem?).

So i gave up on this idea, but I have no more ideas.

Is there a way to do this and if possible with a reasonable speed?
 
Last edited:
Status
Not open for further replies.
Back
Top