Skip to content

Converting a bitmap for the OLED

December 31, 2017

IMG_0552
I don’t know why this seemed so hard but it did. Converting a .bmp file to display on the OLED was as simple as loading it into the LCD Assistant program and saving it as a header file with vertical orientation. Presumably the horizontal orientation would give you something suitable for the pixie-type display.
Below is the original image(in jpg form) and the display of LCD Assistant before saving it. The code is the same adaptation of the nokia lcd code. I tried the animation sequence but, not surprisingly, the control instructions would have to change.

/*  oledmain.c
    Display an image on an OLED display using hardware SPI shift register
    Dec 14 2017 - adapting for OLED display/SSD1306 controller
    Dec 16 2017 - recovered from olduino post(!)
    Dec 31 Displaying 128X64 Santa with Merry Christmas text(whew)
*/
#include <olduino.h>
#include <nstdlib.h>
#include <cpu1802spd4port7.h>
#include <hspi2.h>
#include <hspi2Lcd.h>
//from lcd assistant conversion of santa3-128X64.bmp in vertical mode
unsigned char spibytes[]={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x00, 0x00, 0x80, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0xF0, 0x90, 0x88, 0x80, 0x50, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xC0, 0x40, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB8, 0xF8, 0xF8, 0xFF, 0x0C, 0x04, 0x82, 0x83, 0x81, 0xC0,
0xC0, 0xC0, 0xC0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xE3, 0xFB, 0xFF, 0xFF, 0xFF, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xF8, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xCC, 0xEC, 0xFE, 0xFC, 0xFC,
0x87, 0x84, 0x80, 0x82, 0x83, 0x83, 0x81, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xF0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0x40, 0x60, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x7F,
0x7F, 0x3F, 0xFF, 0xAC, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0C, 0xE4, 0x36, 0x17,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x7F, 0x6B, 0x0F, 0x08,
0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x88, 0xC8, 0x2C, 0x3E, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0xFF, 0xDF, 0xFF, 0xB1, 0x00, 0x08, 0x18, 0x10, 0x10, 0x10, 0x18,
0x08, 0x08, 0x04, 0x04, 0x02, 0x33, 0x19, 0xF9, 0xF9, 0xF1, 0xE3, 0xE7, 0xFE, 0xFC, 0xFC, 0xFC,
0xEC, 0xE6, 0xE6, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xF7, 0xFF, 0xF9, 0xF9,
0xF9, 0xFB, 0xFB, 0xFF, 0x07, 0x03, 0x03, 0x07, 0x0F, 0x0F, 0x0C, 0x0C, 0x1C, 0x1C, 0x1C, 0x00,
0x07, 0x03, 0x00, 0x00, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x38, 0x60, 0xE0, 0xCF, 0xCF, 0xDF, 0xFF, 0xFF, 0x3F, 0x7F, 0x7F, 0x7F, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x03,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x06, 0x06, 0x0C,
0x0C, 0x0D, 0x19, 0x1F, 0x3F, 0x33, 0x33, 0x63, 0x63, 0xC1, 0xC1, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xF0, 0xF0, 0xF0, 0xC0, 0x00, 0xC0, 0xF0, 0xF0, 0xF0, 0x00, 0x80, 0xC0, 0x40, 0x40, 0xC0,
0x80, 0x00, 0xC0, 0xC0, 0x40, 0x40, 0x00, 0xC0, 0xC0, 0x40, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x00,
0xC0, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0x30, 0x10, 0x10, 0x30, 0x20, 0x00, 0xF0, 0xF0, 0x80,
0x40, 0xC0, 0x80, 0x00, 0xC0, 0xC0, 0x40, 0x40, 0x00, 0xD0, 0xD0, 0x00, 0x80, 0xC0, 0x40, 0x40,
0xC0, 0x80, 0x40, 0xE0, 0xF0, 0x40, 0x00, 0xC0, 0xC0, 0x80, 0x40, 0xC0, 0xC0, 0x80, 0x40, 0xC0,
0x80, 0x00, 0x80, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x80, 0xC0, 0x40, 0x40, 0xC0, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0x1F, 0x00, 0x0F, 0x1C, 0x0F, 0x00, 0x1F, 0x1F, 0x00, 0x0F, 0x1F, 0x12, 0x12, 0x1B,
0x0B, 0x00, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x00, 0x00, 0x40, 0x47, 0x7F, 0x38, 0x1F,
0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0F, 0x18, 0x10, 0x10, 0x18, 0x08, 0x00, 0x1F, 0x1F, 0x00,
0x00, 0x1F, 0x1F, 0x00, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x00, 0x09, 0x1B, 0x13, 0x16,
0x1E, 0x0C, 0x00, 0x0F, 0x1F, 0x10, 0x00, 0x1F, 0x1F, 0x00, 0x00, 0x1F, 0x1F, 0x00, 0x00, 0x1F,
0x1F, 0x00, 0x0C, 0x1E, 0x13, 0x11, 0x1F, 0x1F, 0x00, 0x09, 0x1B, 0x13, 0x16, 0x1E, 0x0C, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void animate(){
	unsigned int offset;
	for (offset=0;offset<128;offset++){
		gotoXY(0,1); //position to 1st line with ship in it
		digitalWrite(lcdcmd,LCD_D); //get out of command mode
		LcdWriteN(spibytes+128+offset,128-offset);
		if (offset>0){
			LcdWriteN(spibytes+128,offset);
		}
		gotoXY(0,2); //position to 2nd line with ship in it
		digitalWrite(lcdcmd,LCD_D); //get out of command mode
		LcdWriteN(spibytes+256+offset,128-offset);
		if (offset>0){
			LcdWriteN(spibytes+256,offset);
		}
		gotoXY(0,3); //position to 2nd line with ship in it
		digitalWrite(lcdcmd,LCD_D); //get out of command mode
		LcdWriteN(spibytes+384+offset,128-offset);
		if (offset>0){
			LcdWriteN(spibytes+384,offset);
		}
		delay(100);
	}
}

#define LcdSS 4
void oledInitialise(void)
{
    unsigned char initbytes[32]={ //cribbed from adafruit library
        0xAE,0xD5,0x80,0xA8,0x3F,0xD3,0x00,0x40,
        0x8D,0x14,0x20,0x00,0xA1,0xC8,0xDA,0x12,
        0x81,0xCF,0xD9,0xF1,0xDB,0x40,0xA4,0xA6,
        0x2E,0xAF,0x21,0x00,0x7F,0x22,0x00,0x07};
    unsigned int i;

    digitalWrite(lcdreset,LOW); //reset the LCD
    digitalWrite(lcdreset,HIGH); //release the reset
    digitalWrite(LcdSS,LOW);    //select the LCD
    for (i=0;i<32;i++){
        LcdWrite(LCD_C, initbytes[i]); //send initialization
    }

}
void oledSet(unsigned char what) //set the whole LCD to a bit pattern
{
  unsigned int index;
  for (index = 0; index <1024; index++)
  {
    LcdWrite(LCD_D, what);
  }
}
void main()
{
    printf("oledmain.c here\n");
    PIN4=0;
    digitalWrite(LcdSS,HIGH);
    setqon();
    digitalWrite(LcdSS,LOW);
    oledInitialise();
    setqoff();
    //oledSet(0xf0);
    digitalWrite(lcdcmd,LCD_D); //set data
    spiSendN(spibytes,128*8);
}
#include <hspi2.c>
#include <hspi2Lcd.c>
#include <olduino.c>
#include <nstdlib.c>

As an aside, as i was fumbling around trying to get something to work i tried another conversion program at https://sourceforge.net/projects/bmp2glcd/files/bmp2glcd/bmp2glcd_ver_1.02/bmp2glcd_v1-02-src.tar.gz/download

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: