parameter guidelines for display.drawBitmap

I'm kind of used to the IDE cheating for me and autofilling hints when typing in a function of a class...
I just received my 128x32 OLED display, and am trying to get some bmp to display on it, but am unclear on the parameters of the function display.drawBitmap()

Where do I find this information. /noob

What library are you using for the OLED?

HazardsMind:
What library are you using for the OLED?

it's the stock Adafruit_SSD1306 from github.
Specifically, I'm trying to figure out what each of these parameters are:
display.drawBitmap(a, b, imgmap, c, d, f);

The drawBitmap function is actually from another library called Adafruit_GFX, and the drawBitmap function confuses me too.

If you took a look at the Adafruit_GFX library in a text editor like notepad++, you will be able to see all the functions the library offers.

drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)

What confuses me in this case is the “color”, now normally when you draw a bitmap, the color is gotten from the image and just displayed at a certain spot on the display. However, with this function I dont know if the color you set is the background color or not. But I think I may have something you can use.

I made this bitmap function for another user, you can give it a try.

extern unsigned int conix_64x64[0x1000]; // "conix_[0x1000]" must match the name in the file.

void setup()
{
  /* add in the functions to get your LCD started */
  drawBitmap(0, 0, 64, 64, conix_64x64); // (0,0) where on the screen, (64,64) size of image, (conix_64x64) image name.
}

void loop()
{
}

void drawBitmap(int x, int y, int sx, int sy, unsigned int *data)
{
 int tc = 0;
 for(int Y = 0; Y < sy; Y++)
 {
  for(int X = 0; X < sx; X++)
  {
   display.drawPixel(X+x, Y+y, pgm_read_word(&data[tc]));
   if(tc < (sx*sy)) tc++;
  }
 }
}

To see the image on screen all you need to do is copy and paste the image file below into the same folder of the sketch you are using, it should appear as a new tab. Or copy the contents of the image file(the whole thing) into a new tab (small down arrow in the top right corner of the arduino software) save it then you can use it.

pCnsL64x64.c (37.2 KB)

Thanks!
That does help a bit, in terms of the clarification of the drawBitmap functionality.
Upon further forum searching, I think my problem might have more to do with LCD Assistant, than the actual arduino code.

I'm down to testing a single little block image bitmap of a 4x4 pixel square beside a 3x22 pixel rectangle, just to try to make sense of what that software is putting out.
In the example code from Adafruit, they're using binary instead of hex to code the little stars that they put on the OLED, and you can actually sort of trick your eyes into seeing the stars with the 1s being image and the 0s being blank:

static const 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 };

so, first thing I just discovered: I'm using fireworks to kick out the bitmap, and had made the mistake of having the bmp dithering at 100%. I needed to have the dithering set to 0% in order to get the full black blocks on the resultant bmp

so the resultant image is 16x22, and that first 4 horizontal pixels should give me B11110000... so, lets see what LCD assistant does with it.

ok, that doesn't seem right when set to 'vertical'

//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------

const unsigned char test [] = {
0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x3F, 0x00, 0x00, 
};

lets try 'horizontal'

//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------

const unsigned char test [] = {
0xF1, 0xC0, 0xF1, 0xC0, 0xF1, 0xC0, 0xF1, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0,
0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0,
0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xC0, 
};

That seems better! that first pair of hex is 11110001 1100000, which looks promising, as that would perfectly match the blacked out pixels on that first 16pixel horizontal line
load it up

  display.clearDisplay();
  //start the drawing 45 pixels in, 3 pixels down.  It's 16 pixels wide by 22 pixels high. try WHITE for no reason.
  display.drawBitmap(45, 3,  test, 16, 22, WHITE);
  display.display();

upload! and.....
nope.

that makes no sense.
when I properly format the code output from LCD Assistant, it looks perfect to the image:

 static const unsigned char test [] = {
0xF1, 0xC0, 
0xF1, 0xC0, 
0xF1, 0xC0, 
0xF1, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0,
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0,
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
0x01, 0xC0, 
};

although it's still garbled on the OLED.

I also just went through the conversion to binary, thinking maybe the Arduino didn't like the hex.

 static const unsigned char test [] = {
B11110001, B11000000, 
B11110001, B11000000, 
B11110001, B11000000, 
B11110001, B11000000, 
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000001, B11000000
};

  // Clear the buffer.
  display.clearDisplay();
  display.drawBitmap(45,3,test,16,22,WHITE);
  display.display();

It still comes out all garbled, which totally doesn't make sense, as it LOOKS perfect.

SOLVED! ]:slight_smile:

it's the PROGMEM initializer in the setting up of the byte array I was missing. :~
I was doing this:

static const unsigned char test [] = {
B11110001, B11000000, .....

and it needed to be this:

static const unsigned char PROGMEM test [] = {
B11110001, B11000000, ......

tada:

So, hopefully this will help somebody in the future.

Nice.

Yeah, got caught up with just cutting and pasting the output from the LCD Assistant software, you neeeed to add the PROGMEM identifier.
and by the way, the hex values are fine. No need to convert to binary.

Members

I know its an old post but Id like to know where this number '[0x1000]' is found?

Thanks

fnb111:
Members

I know its an old post but Id like to know where this number '[0x1000]' is found?

Thanks

'[0x1000]' is NOT a number.

You will HAVE to provide a LOT more context for your off-the-wall question.

PaulS:
'[0x1000]' is NOT a number.

You will HAVE to provide a LOT more context for your off-the-wall question.

I think he's referencing code from reply #3. "conix_64x64" is the name of the external bitmap file, and [0x1000] is the number of bits in the file, since it's 64x64.

Thanks Chris.

[quote author=corvidael link=msg=1863198 date=1409500449]

 static const unsigned char test [] = {
B11110001, B11000000, 
B11110001, B11000000,

[/quote]

How to convert like this, instead of Hex value (0X00). any tool is available ?

Just break it down 4 bits at a time, goes quick with a little practice

B00000000 = 0b00000000 = 0x00

so:
0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F

B11110001, B11000000, -> B1111 / 0001, B1100 / 0000, ->0xF1, 0xC0

After a while you'll start thinking in hex numbers. A lot of times binary makes it easier to visualize what is going on hardware-wise.

CrossRoads:
Just break it down 4 bits at a time, goes quick with a little practice

B00000000 = 0b00000000 = 0x00

B11110001, B11000000, -> B1111 / 0001, B1100 / 0000, ->0xF1, 0xC0

Thank you for your replay.But i have a huge amount of Hex value like ;

0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,
0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,
0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,
0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,
0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,
0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,
0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,
0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,
0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,
0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,
0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,
0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,
0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,
0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,
0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,
0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,
0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,
0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,
0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,
0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,
0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,
0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,
0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,
0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,
0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,
0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,
0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X49,0XC1,0X23,0XEE,
0X18,0X71,0X23,0XE3,0X8D,0XB4,0X3C,0X81,0XBE,0X37,0XC4,0XF0,0X90,0X36,0XC0,0X00,..............

I tried in some online converter but it returns like this
11111100111111111100111111
11110001111100111110001111
This is not accepted by the Arduino.So Is that any tool is available to convert huge hex value into binary value ?

Please explain a little more what it is you are trying to do.

Where is the data coming from, and what is the Arduino to do with it?
You appear to have 16 bytes per line, 30+ lines.

CrossRoads:
Please explain a little more what it is you are trying to do.

I am trying to display the barcode image in 2.4Inch LCD (without using SD card) which is connected with ARDUINO UNO R3. For that i am trying to convert image into hex value.but it returns kind of blur image.

And Is it possible to send a image from PHP Page?

Ok, the LCD display can accept a hex digit per location. 0xXX is hex data. If you're receiving it from a PHP page, I can't help you there.
There are libraries for writing data to LCD displays.

CrossRoads:
accept a hex digit per location.

Per location means?
And i tried it accepts but displays broken blur image