I picked up a shield with a Nokia 3310 screen on it and have been playing around with it using the driver found at Arduino Playground - PCD8544. I've managed to convert the menu into a multi level menu to suit my needs but am getting frustrated with the LCD_3310_draw_bmp_pixel function. It's not critical to what I'm building but I'm so frustrated by it that I can't let it go. When I first started playing with it a few months back I found a site or a program that generated the char array for any bitmaps you imported and got some to work but I can no longer figure out how I did that. Right now I'm trying to generate the code through a C# app I wrote but I'm failing miserably.
The example app uses this char array to generate an AVR logo when passed into the LCD_3310_draw_bmp_pixel function:
unsigned char AVR_bmp[]= {
0x00,0x00,0x00,0x00,0x80,0xE0,0xFC,0xFF,0xFF,0xFF,0x7F,0xFF,0xFE,0xFC,0xF0,0xC1,
0x0F,0x7F,0xFF,0xFF,0xFE,0xF0,0xC0,0x00,0x00,0x00,0xC0,0xF8,0xFE,0xFF,0xFF,0x3F,
0x07,0xC1,0xF0,0xFE,0xFF,0xFF,0xFF,0x1F,0x07,0x8F,0xCF,0xFF,0xFF,0xFF,0xFE,0xFC,
0x00,0x80,0xF0,0xFC,0xFF,0xFF,0xFF,0x7F,0x7F,0x78,0x78,0x79,0x7F,0x7F,0xFF,0xFF,
0xFC,0xF0,0xC1,0x07,0x1F,0xFF,0xFF,0xFE,0xFC,0xFF,0xFF,0xFF,0x1F,0x07,0xC1,0xF0,
0xFE,0xFF,0xFF,0x3F,0x0F,0x0F,0x7F,0xFF,0xFF,0xFF,0xFF,0xE7,0x07,0x03,0x01,0x00,
0x02,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x03,0x03,0x03,0x03,0x00,0x00,0x03,0x1F,0x3F,0x1F,0x07,0x00,0x00,0x02,0x03,0x03,
0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00
};
As you can see its 48x24 pixels, yet the data in it is 16x9 bytes for a total of 144 bytes. I would suspect that if each byte simply mapped out to a pixel and set it on or off then you'd have 1152 bytes in that array, so that theory is out.
In my C# app I've tried converting the whole BMP to an array but it again is far too massive. I've also tried stripping the headers and getting just the individual pixel data and building a map of that even though I knew it wouldn't work. Here's my code for that:
public String convertToByteArray(String filePath)
{
Bitmap bmp2 = null;
// Make sure the bitmap is loaded into memory
if (bmp == null)
{
//bmp = new Bitmap(filePath);
bmp = new Bitmap(filePath); // Create 8bpp bitmap
bmp2 = CopyToBpp(bmp, 1); // Convert to a 1bpp bitmap (monochrome)
}
byteArrayLen = bmp.Height * bmp.Width;
String byteArrayString = "";
String byteTemp = "";
int i = 0;
if (byteArrayLen > 0)
{
// Start building the string
byteArrayString = byteArrayPrefix;
int x = 0;
int y = 0;
// Build the middle
for (i = 0; i < byteArrayLen - 1; i++)
{
// Calculate x and y positions
if ((i > 0) && (i % (byteArrayY - 1)== 0))
{
x++;
y = 0;
}
if (x == 84)
{
break;
}
// Add the current byte
try
{
byteTemp = bmp.GetPixel(x, y).ToString().Substring(16, 3);
if (byteTemp == "255")
{
byteArrayString += "0xFF";
}
else
{
byteArrayString += "0x00";
}
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
}
// Add separator
if (i < byteArrayLen - 1)
{
byteArrayString += byteArrayseparator;
if ((i + 1) % 16 == 0)
{
byteArrayString += "\r\n";
}
}
else
{
byteArrayString += "";
}
y++;
}
// Finish off string
byteArrayString += byteArraySuffix;
}
else
{
byteArrayString = null;
}
return byteArrayString;
} //convertToByteArray()
I've extracted all the relevant data out of the library to try and determine how it works but to me it looks like it's just the pixel map I already determined it isn't:
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0) row=Pix_y/8;
else
row=Pix_y/8+1;
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++;
}
}
void Nokia_3310_lcd::LCD_3310_write_byte(unsigned char dat, unsigned char dat_type){
LCD_write_byte(dat, dat_type);
}
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
So does anyone have any clue how I generate an array to map out a bitmap like the AVR logo in the example? I've been at this all day and feel like I'm just getting further from the correct way of doing it.
Thanks in advance