HCuOLED library for SSD1307 & SH1106 based OLED displays

Useful guides, libraries, and example sketches to support our Arduino based products.
leg2027
Posts: 3
Joined: Wed Sep 28, 2022 5:46 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by leg2027 » Thu Sep 29, 2022 5:31 pm

Hello,

First of all, thank you for this library, it works really well. I tried many others for 0.66 wemos screen but they didn't work.

I didn't quite understand how to use the function

Code: Select all

HCuOLED.Bitmap(Cols, ByteRows, BitmapData[]);
The link to the converter no longer exists.

Can you help me display a bitmap on my screen?

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Sat Oct 01, 2022 10:04 am

Assuming you're using Windows you can use ‘The Dot Factory’ to convert your bitmap. This can be downloaded from here:

http://www.eran.io/the-dot-factory-an-l ... generator/
Disclaimer: Links to external websites and software are used at your own risk.

Open the program and in the left hand window pane click the image tab to import a bitmap.

Note that your graphic should be a two colour (BW) bitmap that is smaller than the resolution of the display.

In the right hand pane click the wrench icon which can be found in the top right hand corner of the pane.

In the settings window that opens up, for the Byte settings, make sure you have Bit Layout set to 'ColumnMajor' and Order set to 'MsbFirst'

Click the apply button to close the settings window and then click the generate button to generate the bitmap data. You can then cut and paste the array it generates into your sketch.

For the HCuOLED.Bitmap(pixelCols, byteRows, bitmapName) function, it takes 3 parameters:

pixelCols is the horizontal resolution of your bitmap in pixels. For the example pasted below it is 20 pixels wide.

byteRows is the vertical resolution of your bitmap divided by 8. For the example below the vertical resolution is 32 pixels / 8 = 4

bitmapName is the name of the array used to store the bitmap.



Here is an example:
  1. #include "HCuOLED.h"
  2. #include "SPI.h"
  3.  
  4. /* Example bitmap */
  5. const PROGMEM uint8_t bitmap[] =
  6. {
  7.   //        ######      
  8.   //      ##########    
  9.   //     ###      ##    
  10.   //     ###      ###    
  11.   //     ############    
  12.   //   ################  
  13.   //   ################  
  14.   //  ##              ##
  15.   //  ##              ##
  16.   // ###    ######    ###
  17.   // ###   ########   ###
  18.   // ###  ##########  ###
  19.   // ###  ######  ##  ###
  20.   // ###  ####   ###  ###
  21.   // ###  ###    ###  ###
  22.   // ###  ##    ####  ###
  23.   // ###  ##    ####  ###
  24.   // ###  ##     ###  ###
  25.   // ###  ###     ##  ###
  26.   // ###  ####    ##  ###
  27.   // ###  ####    ##  ###
  28.   // ###  ###    ###  ###
  29.   // ###  ###   ####  ###
  30.   // ###  ##  ######  ###
  31.   // ###  ##########  ###
  32.   // ###   ########   ###
  33.   // ###    ######    ###
  34.   //  ##              ##
  35.   //  ##              ##
  36.   //   ################  
  37.   //   ################  
  38.   //      ##########    
  39.  
  40.  
  41.   0x00, 0x80, 0xE0, 0x60, 0x7C, 0x7E, 0x7E, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x7E, 0x7E, 0x78, 0x60, 0xE0, 0x80, 0x00,
  42.   0xFE, 0xFF, 0xFF, 0x00, 0x00, 0xF8, 0xFC, 0x7E, 0x3E, 0x1E, 0x1E, 0x8E, 0xEE, 0xFC, 0xF8, 0x00, 0x00, 0xFF, 0xFF, 0xFE,
  43.   0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x7C, 0x18, 0x80, 0x80, 0xC1, 0xE3, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
  44.   0x07, 0x1F, 0x7F, 0x60, 0x60, 0xE1, 0xE3, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE3, 0xE1, 0x60, 0x60, 0x7F, 0x1F, 0x07,
  45. };
  46.  
  47. #define CS_DI 10
  48. #define DC_DI 9
  49. #define RST_DI 8
  50.  
  51.  
  52. /* Create an instance of the library (uncomment one of the lines below) */
  53. HCuOLED HCuOLED(SSD1307, CS_DI, DC_DI, RST_DI); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
  54. //HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI); // For SH1106 displays (HCMODU0058 & HCMODU0059)
  55.  
  56.  
  57. void setup()
  58. {
  59.   /* Reset the display */
  60.   HCuOLED.Reset();
  61.  
  62.   HCuOLED.Cursor(0,0);  
  63.   HCuOLED.Bitmap(20, 4, bitmap);
  64.  
  65.   HCuOLED.Refresh();
  66. }
  67.  
  68. void loop()
  69. {
  70. }

Note you’ll change how the software declares the array from this:

const uint_8 bitmap =

to this:

const PROGMEM uint8_t bitmap[] =


This will make sure the bitmap is stored in flash memory and not SRAM.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

leg2027
Posts: 3
Joined: Wed Sep 28, 2022 5:46 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by leg2027 » Sat Oct 01, 2022 4:02 pm

Thanks a lot !

I tried everything you said and it works perfectly.
I managed to display the bitmaps that I wanted.

Just in case, can we rotate a bitmap?

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Mon Oct 03, 2022 7:46 am

Glad I could help...
Just in case, can we rotate a bitmap?
The library doesn't support rotating of bitmaps. So if you want to rotate bitmaps you'll need to pre-generate the bitmaps in each rotated position.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

leg2027
Posts: 3
Joined: Wed Sep 28, 2022 5:46 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by leg2027 » Mon Oct 03, 2022 7:25 pm

I expected that. It's not that serious.

Now that I understand, arrays for bitmaps are quite simple actually. So for the little bitmaps, like the arrows, I made a sort of binary grid on paper, then I converted the columns to hexadecimal and typed them into the PROGMEM array.
It's more convenient to draw what you want and even faster.


Here is a small picture of my project:
I may use more complex bitmaps in the future.
20221003_211208.jpg
You do not have the required permissions to view the files attached to this post.

Gingerbloke
Posts: 4
Joined: Fri Aug 07, 2015 9:33 am

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by Gingerbloke » Wed Apr 19, 2023 5:49 pm

I found the following initialisation commands were needed when I connected the display to an STM32F0 microcontroller.
Sorry I don't have a description of these, but I found them in section 4.4 of the datasheet.
Google: "ER-OLED0.91-1 Series datasheet".

Hopefully these commands might save someone a few hours of debugging. Great little display!

STM32 code I used was adapted from Alexander Lutsai and Tilen Majerle. I2C address was 0x78
  1.     SSD1306_WRITECOMMAND(0xAE); //display off
  2.     SSD1306_WRITECOMMAND(0xD5);            
  3.     SSD1306_WRITECOMMAND(0x80);            
  4.     SSD1306_WRITECOMMAND(0xA8);            
  5.     SSD1306_WRITECOMMAND(0x1F);
  6.     SSD1306_WRITECOMMAND(0xD3);
  7.     SSD1306_WRITECOMMAND(0x00);
  8.     SSD1306_WRITECOMMAND(0x40);
  9.     SSD1306_WRITECOMMAND(0x8d);
  10.     SSD1306_WRITECOMMAND(0x10);
  11.     SSD1306_WRITECOMMAND(0xA1);
  12.     SSD1306_WRITECOMMAND(0xC8);
  13.     SSD1306_WRITECOMMAND(0xDA);          
  14.     SSD1306_WRITECOMMAND(0x02);
  15.     SSD1306_WRITECOMMAND(0x81);
  16.     SSD1306_WRITECOMMAND(0xCF);
  17.     SSD1306_WRITECOMMAND(0xD9);
  18.     SSD1306_WRITECOMMAND(0x22);
  19.     SSD1306_WRITECOMMAND(0xDB);
  20.     SSD1306_WRITECOMMAND(0x40);
  21.     SSD1306_WRITECOMMAND(0xA4);
  22.     SSD1306_WRITECOMMAND(0xA6);
  23.     SSD1306_WRITECOMMAND(0x12);
  24.     SSD1306_WRITECOMMAND(0xDB);
  25.     SSD1306_WRITECOMMAND(0x20);
  26.     SSD1306_WRITECOMMAND(0x8D);
  27.     SSD1306_WRITECOMMAND(0x14);
  28.     SSD1306_WRITECOMMAND(0xAF); //--turn on SSD1306 panel

Post Reply

Return to “Arduino”