Pages: [1]   Go Down
Author Topic: Converting bitmaps to byte arrays  (Read 4121 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,
I've been working with a little nokia lcd recently (http://www.sparkfun.com/tutorials/300) Sparkfun's code is majorly out of date, the adafruit library they suggest seems to have been updated, but Sparkfun hasn't bothered to update their tutorial code. After some research and trial and error I have a grasp on the updated library. Only issue is now I want to display bitmaps, Sparkfun suggests using this converter (http://en.radzio.dxp.pl/bitmap_converter/) It works great for spitting out HEX arrays, but I think the updated library likes binary arrays. this is the function they use to call bitmaps:

Code:
display.drawBitmap(x, y,  array name, sizex, sizey, color(black/white));

So basically does anyone know of a bitmap image converter that will spit out a binary array and not a HEX array? It should look like this:

Code:
static unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

And NOT like this:

Code:
static unsigned char PROGMEM SFE[] = {
0x00, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x30, 0x10, 0x18, 0x08, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x0C, 0x08, 0x18, 0x10, 0x30, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3E, 0x07, 0x7D, 0x43, 0x41, 0x41, 0x4F, 0x4F, 0x4E, 0x78, 0x00, 0x00, 0x00, 0x00,
0x78, 0x46, 0x43, 0x41, 0x41, 0x47, 0x4F, 0x4E, 0x7C, 0x00, 0x00, 0x01, 0x07, 0x7E, 0xF0, 0x00,
0x00, 0x00, 0x7C, 0xE0, 0x80, 0x06, 0x3E, 0xE6, 0x86, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x86,
0x86, 0x86, 0x86, 0x86, 0x06, 0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x80, 0xE0, 0x7E, 0x0F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x0C, 0x08, 0x19, 0x13, 0x36, 0x24, 0x6C, 0x6E, 0x6F, 0x6F,
0x6F, 0x6F, 0x6F, 0x6F, 0x27, 0x33, 0x13, 0x19, 0x0C, 0x0C, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00
};

I get total gibberish on my screen when I use HEX, but a nice little adafruit logo when I use binary. Any suggestions?
Thank you!
« Last Edit: November 03, 2012, 04:52:45 pm by Paranemertes » Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

France
Offline Offline
God Member
*****
Karma: 34
Posts: 987
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is no difference between hex and binary, they are the same numbers, only presented differently, for example B11111110 = 0xFE = 254, the error is somewhere else :/
Logged

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmmmmmmm, that makes sense, now I feel extra stupid smiley-neutral Any ideas where that error might be??
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

France
Offline Offline
God Member
*****
Karma: 34
Posts: 987
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you show your code, maybe I can spot an error smiley

Also did you use the correct settings? :
Quote
3) With this image we simply use handy program called LCD Assistant that will take bitmap images and spit out the necessary data array.
Settings to use: Vertical byte orientation and Little endianness
« Last Edit: November 03, 2012, 07:07:43 pm by guix » Logged

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep, using all the settings suggested by Sparkfun, here is my little test program:

Code:
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 3, 4);
#define vcc 1 
#define gnd 2

static unsigned char PROGMEM SFE[] = //a sparkfun logo
{
0x00, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x30, 0x10, 0x18, 0x08, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x0C, 0x08, 0x18, 0x10, 0x30, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3E, 0x07, 0x7D, 0x43, 0x41, 0x41, 0x4F, 0x4F, 0x4E, 0x78, 0x00, 0x00, 0x00, 0x00,
0x78, 0x46, 0x43, 0x41, 0x41, 0x47, 0x4F, 0x4E, 0x7C, 0x00, 0x00, 0x01, 0x07, 0x7E, 0xF0, 0x00,
0x00, 0x00, 0x7C, 0xE0, 0x80, 0x06, 0x3E, 0xE6, 0x86, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x86,
0x86, 0x86, 0x86, 0x86, 0x06, 0x06, 0x06, 0xC6, 0x7C, 0x00, 0x00, 0x80, 0xE0, 0x7E, 0x0F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x0C, 0x08, 0x19, 0x13, 0x36, 0x24, 0x6C, 0x6E, 0x6F, 0x6F,
0x6F, 0x6F, 0x6F, 0x6F, 0x27, 0x33, 0x13, 0x19, 0x0C, 0x0C, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00
};
const int SFEx=32;
const int SFEy=32;

static unsigned char PROGMEM hand[] = //here is a hand picture
{
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x48,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x18, 0x0C, 0x30, 0x98, 0x30, 0x28, 0x28, 0x90,
0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x50, 0x50, 0x10, 0xC0, 0xB0, 0x28, 0xC8, 0x04,
0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x10, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x04, 0x00, 0x90,
0x00, 0x00, 0x00, 0x10, 0x04, 0x40, 0x90, 0x04, 0x40, 0x80, 0xA0, 0x80, 0x80, 0xC0, 0xA8, 0x88,
0x70, 0x80, 0x39, 0x40, 0x48, 0xA8, 0xD0, 0x64, 0x90, 0x24, 0xF8, 0x4E, 0xD2, 0xD6, 0xA5, 0x5F,
0x92, 0x89, 0xAE, 0x14, 0x0C, 0x1A, 0x06, 0x42, 0x00, 0xA0, 0x50, 0xE0, 0x50, 0x98, 0xC8, 0xB4,
0x80, 0x4E, 0xF3, 0xDD, 0x53, 0x9A, 0x55, 0x42, 0xA0, 0x60, 0xD8, 0x2B, 0x0A, 0x99, 0x03, 0x86,
0x05, 0x0F, 0xAE, 0x00, 0x94, 0x10, 0x16, 0x58, 0x80, 0x00, 0x04, 0x00, 0xC0, 0x4D, 0x20, 0x80,
0x29, 0x14, 0x01, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x06, 0xD1, 0x22, 0x8F, 0xB0, 0x45,
0xC9, 0xB4, 0x4A, 0x67, 0x98, 0xB7, 0x76, 0xA9, 0x52, 0x17, 0xC9, 0x45, 0x02, 0x51, 0x87, 0xA8,
0x5A, 0x05, 0x2A, 0xA2, 0x17, 0x49, 0x46, 0x25, 0xCC, 0x21, 0x42, 0x0A, 0x20, 0x18, 0xA0, 0x14,
0xAA, 0x10, 0x00, 0x54, 0x21, 0x11, 0x84, 0xD2, 0x00, 0x00, 0x23, 0x10, 0x85, 0x49, 0x12, 0x44,
0x8A, 0x44, 0x21, 0x40, 0x04, 0x02, 0x40, 0x2C, 0x82, 0x28, 0x50, 0x81, 0x82, 0x25, 0x58, 0xD0,
0x20, 0x20, 0x11, 0x40, 0x50, 0xA0, 0xF0, 0x4A, 0xE8, 0x98, 0x42, 0x50, 0x69, 0xC4, 0x94, 0x53,
0x6A, 0xDE, 0xA5, 0x5F, 0xE9, 0x54, 0x26, 0xD5, 0x48, 0xAA, 0xC1, 0x46, 0xA9, 0xC0, 0x44, 0xA0,
0x60, 0x45, 0xF0, 0xA0, 0x60, 0xB4, 0x4D, 0x6A, 0xA0, 0xC0, 0x52, 0x8D, 0x00, 0x5A, 0xA5, 0x40,
0xA4, 0xAA, 0x48, 0x95, 0xCA, 0x75, 0x2C, 0xD0, 0x3D, 0x42, 0xA5, 0x02, 0x5A, 0x44, 0x95, 0x52,
0xA8, 0x29, 0xD2, 0xA9, 0x46, 0x9D, 0xD0, 0x2A, 0x25, 0x02, 0xA4, 0x55, 0x90, 0xCA, 0x44, 0x09,
0x54, 0xBE, 0x6A, 0xEB, 0xB4, 0x03, 0x00, 0x00, 0x02, 0x82, 0x81, 0x02, 0x05, 0x03, 0x0D, 0x3A,
0x52, 0xAD, 0x02, 0x01, 0x01, 0x02, 0xF5, 0x95, 0x06, 0x02, 0x03, 0x00, 0xE1, 0x60, 0x83, 0xA0,
0x61, 0xC3, 0x42, 0x60, 0x03, 0x02, 0x03, 0x06, 0xE4, 0xAD, 0x02, 0x02, 0x01, 0x02, 0x60, 0x10,
0x0B, 0x0E, 0x04, 0x82, 0x42, 0xA2, 0x52, 0x89, 0xEA, 0xBB, 0x00, 0x00, 0x03, 0x03, 0xA4, 0xE4,
0x85, 0x75, 0x1A, 0x04, 0x02, 0x01, 0xA0, 0x60, 0x83, 0x02, 0x01, 0x18, 0x64, 0xD9, 0x4C, 0xA2,
0x4D, 0xD2, 0x4B, 0xF5, 0x9A, 0x57, 0x83, 0xBD, 0x75, 0x40, 0xA0, 0xC0, 0x20, 0xD1, 0x1A, 0x6C,
0xB2, 0xAC, 0x38, 0x40, 0x40, 0xA0, 0xE0, 0xA0, 0xE0, 0xA0, 0x4D, 0xB7, 0xA0, 0x40, 0xA0, 0xA0,
0x21, 0xC2, 0x23, 0x82, 0xA1, 0x42, 0xE3, 0xA0, 0x60, 0x20, 0xC0, 0x60, 0xD6, 0x5B, 0xA0, 0x60,
0x40, 0x40, 0xAA, 0xAC, 0xF4, 0x58, 0xA0, 0x60, 0x00, 0xE1, 0xE7, 0xA8, 0x4B, 0xFE, 0x40, 0xA0,
0x60, 0x80, 0xA4, 0x43, 0xC1, 0x40, 0xE0, 0x88, 0xB0, 0x50, 0x90, 0x68, 0x50, 0x88, 0x78, 0x40,
0xC0, 0xA1, 0x42, 0xAF, 0x1B, 0xE6, 0xBF, 0x29,
};

int handx = 84;
int handy = 48;

static unsigned char PROGMEM logo16_glcd_bmp[] =  //this is the code provided by adafruit
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };
 
void setup(){
  Serial.begin(9600);

  pinMode(vcc, OUTPUT);
  pinMode(gnd, OUTPUT);
  digitalWrite(vcc, HIGH);
  digitalWrite(gnd, LOW);
 
  display.begin();
  // init done

  // you can change the contrast around to adapt the display
  // for the best viewing!
  display.setContrast(100);
  display.clearDisplay();

  //display.drawBitmap(20, 0, SFE, SFEx, SFEy, BLACK);   //gibberish
  //display.drawBitmap(0, 0, hand, handx, handy, 1);      //more gibberish
  //display.drawBitmap(0, 0,  logo16_glcd_bmp, 16, 16, BLACK); //nice little adafruit logo
  display.display();
}

void loop(){
}

I hope you can spot somethin! smiley
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

France
Offline Offline
God Member
*****
Karma: 34
Posts: 987
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well no, I can't see a problem... Try to use The Dot Factory, it's a program to convert fonts and images to byte arrays, you can choose to output in hex or binary, and many other options (that you shouldn't modify) by clicking the tool wrench near the generate button.

Try this array that I generated for you smiley :
Code:
static unsigned char PROGMEM SFE[] =
{
B00000000, B00000000, B00000000, B00000000, B11100000, B00000000, //                                 ###     
B00000000, B00000000, B00000000, B00000001, B11110000, B00000000, //                                #####    
B00000000, B00000000, B00000000, B00000011, B11100000, B00000000, //                               #####      
B00000000, B00000000, B00000000, B00000011, B11000000, B00000000, //                               ####      
B00000000, B00000000, B00000000, B00000011, B11000000, B00000000, //                               ####      
B00000000, B00000000, B00000000, B00000011, B11100010, B00000000, //                               #####   #  
B00000000, B00000000, B00000000, B00000011, B11111011, B00000000, //                               ####### ##
B00000000, B00000000, B00000000, B00000001, B11111111, B00000000, //                                #########
B00000000, B00000000, B00000000, B00111000, B11111111, B10000000, //                           ###   #########
B00000000, B00000000, B00000000, B00110000, B11111111, B10000000, //                           ##    #########
B00000000, B00000000, B00000000, B11110000, B11111111, B10000000, //                         ####    #########
B00000000, B00000001, B11111111, B11110000, B11111111, B10000000, //                #############    #########
B00000000, B00011111, B11111111, B11111111, B11111111, B10000000, //            ##############################
B00000000, B00111111, B11111111, B11111111, B11111111, B10000000, //           ###############################
B00000000, B11111111, B11111111, B11111111, B11111111, B00000000, //         ################################
B00000011, B11111111, B00001111, B11111111, B11111111, B00000000, //       ##########    ####################
B00000111, B11111000, B00000000, B11111111, B11111110, B00000000, //      ########           ###############  
B00000111, B11100000, B00000000, B01111111, B11111100, B00000000, //      ######              #############  
B00011111, B10000000, B00000000, B00011111, B11110000, B00000000, //    ######                  #########    
B00011111, B00000000, B00000000, B00001111, B11100000, B00000000, //    #####                    #######      
B00111110, B00000000, B00000000, B00000111, B11100000, B00000000, //   #####                      ######      
B00111110, B00000000, B00000000, B00000011, B11100000, B00000000, //   #####                       #####      
B01111100, B00000000, B00000000, B00000011, B11100000, B00000000, //  #####                        #####      
B01111000, B00000000, B00000000, B00000001, B11100000, B00000000, //  ####                          ####      
B01111001, B11111001, B11111001, B11111001, B11110000, B00000000, //  ####  ######  ######  ######  #####    
B01111001, B10111001, B11111001, B11110000, B11110000, B00000000, //  ####  ## ###  ######  #####    ####    
B11110001, B10011001, B10000001, B00000000, B11110000, B00000000, // ####   ##  ##  ##      #        ####    
B11110001, B10000001, B10000001, B00000000, B11110000, B00000000, // ####   ##      ##      #        ####    
B11110001, B11100001, B11111001, B11110000, B11110000, B00000000, // ####   ####    ######  #####    ####    
B11110000, B11100001, B11111001, B11110000, B11110000, B00000000, // ####    ###    ######  #####    ####    
B11110000, B00111001, B10000001, B00000000, B11110000, B00000000, // ####      ###  ##      #        ####    
B11110001, B10011001, B10000001, B00000000, B11110000, B00000000, // ####   ##  ##  ##      #        ####    
B11110001, B10011001, B10000001, B00000000, B11110000, B00000000, // ####   ##  ##  ##      #        ####    
B11111001, B10011001, B10000001, B11110000, B11110000, B00000000, // #####  ##  ##  ##      #####    ####    
B01111001, B11111001, B10000001, B11111001, B11110000, B00000000, //  ####  ######  ##      ######  #####    
B01111000, B00000000, B00000000, B00000001, B11100000, B00000000, //  ####                          ####      
B01111100, B00000000, B00000000, B00000011, B11100000, B00000000, //  #####                        #####      
B00111100, B00000000, B00000000, B00000011, B11100000, B00000000, //   ####                        #####      
B00111110, B00000000, B00000000, B00000011, B11000000, B00000000, //   #####                       ####      
B00011111, B00000000, B00000000, B00001111, B11000000, B00000000, //    #####                    ######      
B00011111, B10000000, B00000000, B00011111, B10000000, B00000000, //    ######                  ######        
B00001111, B11000000, B00000000, B00111111, B00000000, B00000000, //     ######                ######        
B00000111, B11110000, B00000000, B11111110, B00000000, B00000000, //      #######            #######          
B00000011, B11111110, B00000111, B11111100, B00000000, B00000000, //       #########      #########          
B00000001, B11111111, B11111111, B11110000, B00000000, B00000000, //        #####################            
B00000000, B01111111, B11111111, B11110000, B00000000, B00000000, //          ###################            
B00000000, B00011111, B11111111, B11000000, B00000000, B00000000, //            ###############              
B00000000, B00000011, B11111100, B00000000, B00000000, B00000000, //               ########                  
};

const int SFEx=42;
const int SFEy=48;

It should work...


* SFE Flame5.bmp (3.12 KB, 42x48 - viewed 1601 times.)
« Last Edit: November 03, 2012, 10:12:41 pm by guix » Logged

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

YES. Nice one guix! The Dot Factory came through. That is a really nice program. I think it was the LCD Assistant Sparkfun recommended that I was using, but this one works great! Thanks so much for the help, I really appreciate it.
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

France
Offline Offline
God Member
*****
Karma: 34
Posts: 987
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No problem smiley-wink
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice tool indeed !
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: