-->
Page 1 of 1

Loading image from SPIFFS to LCD (txt to uint8_t)

PostPosted: Wed Aug 03, 2016 2:47 pm
by kristsm
Hi!
One of my small project consists of transferring an image from PC to ESP8266 which is connected to LCD ( for testing purposes I am using SSD1306 OLED screen). Images are changing every minute and are displayed with Adafruit GFX library. The setup is as follows:

1. 64x64 pixel monochrome BMP image is converted to hex string, like : "0x00, 0x00, 0x00, 0x00, 0x00, 0x00 etc.". It is saved as hex.txt;
2. hex.txt is transferred to ESP-12E SPIFFS. It could also be transferred as any other format, too.
3. Adafruit GFX library function for showing the image is as follows:

// drawBitmap() variant for RAM-resident (not PROGMEM) bitmaps.
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color

, where "uint8_t *bitmap" is the source for that hex tring ("0x00, 0x00, 0x00, 0x00, 0x00, 0x00 etc.").

Sadly I have no programming background, therefore I have problems with loading and converting that hex.txt from SPIFFS to "uint8_t *bitmap" and still getting no errors on compiling the code.

What would be the right way to load the hex.txt and convert it to format which Adafruit GFX needs ( "uint8_t *bitmap" ) ?

P.S. I have no problems with loading the same image from PROGMEM.


Thanks!

Re: Loading image from SPIFFS to LCD (txt to uint8_t)

PostPosted: Fri Aug 05, 2016 2:03 am
by kristsm
Saddly, no answer :(

Anway, this script compiles without problems, but the image is messed up (as opposite to the same image displayed from PROGMEM)


File f;

f = SPIFFS.open("/data/image_hex.txt", "r");

if (f) {
int s = f.size();
Serial.printf("File Opened , Size=%d\r\n", s);


String data = f.readString();
uint8_t data1[data.length()];
data.getBytes(data1, data.length());


//Serial.println(data);


f.close();

display.drawBitmap(30, 0, data1, 64, 64, WHITE);
display.display();
delay(1000);



} else {
Serial.println("File Not Opened");
}

Re: Loading image from SPIFFS to LCD (txt to uint8_t)

PostPosted: Fri Aug 05, 2016 12:48 pm
by RichardS
Its a string of HEX chars "0x00" not a single "byte" like the display function probably requires.

"0x00" is 4 bytes, 5 if you count a possible trailing nul terminator of zero.

RichardS