HCuOLED library for SSD1307 & SH1106 based OLED displays

Useful guides, libraries, and example sketches to support our Arduino based products.
andrew
Site Admin
Posts: 1190
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Mon Jan 10, 2022 3:32 pm

I was hoping to invert a character but I can't get the DrawMode function to invert. It's not a mission critical requirement, just a nice to have, so if the functionality is broken, don't spend time fixing it on my behalf.
I don't have access to a display right now to check it but I think it does work but in a different way to what you're expecting. When printing text Invert mode only affects the foreground parts of the text, not the background. So for instance if you were to draw a filled rectangle, and then print some text on top of it in invert mode, the text will be drawn in the background colour - if that makes sense!

How difficult would it be to scroll a line of text? Looking at the library it looks tricky, but do able.

You could actually use the invert mode to do that in the same way as the Things example sketch does it. I'll grab a display when I'm in the office tomorrow and have a closer look.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

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

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Tue Jan 11, 2022 3:42 pm

Just to follow upon my previous post here is a example of printing text in invert mode...

  1. #include "HCuOLED.h"
  2. #include "SPI.h"
  3.  
  4. #define CS_DI 10
  5. #define DC_DI 9
  6. #define RST_DI 8
  7.  
  8. //HCuOLED HCuOLED(SSD1307, CS_DI, DC_DI, RST_DI); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
  9. //HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI); // For SH1106 displays (HCMODU0058 & HCMODU0059)
  10.  
  11. void setup()
  12. {
  13.   HCuOLED.Reset();
  14.  
  15.   HCuOLED.Rect(43,27,88,36, SOLID);
  16.  
  17.   HCuOLED.DrawMode(INVERT);
  18.  
  19.   HCuOLED.Cursor(44,28);
  20.   HCuOLED.Print("HELLO");
  21.  
  22.   HCuOLED.Refresh();
  23. }
  24.  
  25. void loop()
  26. {
  27. }


...and here is a similar sketch but this time it makes use of the invert mode to scroll text across the screen. Note that I had to update the library to 0.9 to allow text to be partially printed off the screen:


  1. #include "HCuOLED.h"
  2. #include "SPI.h"
  3.  
  4. #define CS_DI 10
  5. #define DC_DI 9
  6. #define RST_DI 8
  7.  
  8. //HCuOLED HCuOLED(SSD1307, CS_DI, DC_DI, RST_DI); // For SSD1307 displays (HCMODU0050 & HCMODU0052)
  9. //HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI); // For SH1106 displays (HCMODU0058 & HCMODU0059)
  10.  
  11. void setup()
  12. {
  13.   HCuOLED.Reset();
  14.  
  15.   HCuOLED.Rect(43,27,88,36, SOLID);
  16.  
  17.   HCuOLED.DrawMode(INVERT);
  18. }
  19.  
  20. void loop()
  21. {
  22.   for(int x = 128; x > -40; x--)
  23.   {
  24.     // Print the text at the current cursor position
  25.     HCuOLED.Cursor(x,28);
  26.     HCuOLED.Print("HELLO");
  27.     HCuOLED.Refresh();
  28.  
  29.     // Print the text in the same position whilst in invert mode to remove it
  30.     HCuOLED.Cursor(x,28);
  31.     HCuOLED.Print("HELLO");
  32.     delay(10);
  33.   }
  34. }
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 21
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Tue Jan 11, 2022 4:33 pm

I've got the inverting working, thank you for the clarification on how to do that.

I found a way of scrolling text by hacking around with MoveBitmap from the Things example. But that would require me to convert the text into a bitmap, which isn't ideal.

I'll check out your latest update.

Many thanks.

ChrisSharp
Posts: 21
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Tue Jan 11, 2022 6:48 pm

Your changes have made scrolling text super easy.

For the umpteenth time, thank you. The support you provide is very much appreciated.

I'm on Model Railway Arduino Zoom meeting this evening. I'll mention what I've been up to and give Hobby Components a plug.

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

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Wed Jan 12, 2022 9:27 am

No problem and thanks for the plug, it's much appreciated.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 21
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Thu Jan 13, 2022 8:08 pm

Is there a technique to getting HCuOLED2.Flip_V(); to work. I'd like to be able to mount my displays upside down.

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

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Fri Jan 14, 2022 3:07 pm

It's a bug. I've add a fix so if you update to V1.0 it should work now. Also, I think to correctly flip the screen you'll probably need to use the HCuOLED2.Flip_H() function too.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 21
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Fri Jan 14, 2022 3:09 pm

Thanks. I give it a try.

ChrisSharp
Posts: 21
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Fri Jan 14, 2022 3:21 pm

It works! Thank you.

Yes it does require flipping both horizontal and vertical.

replacing a ~ with a ! I hope that didn't take you too long to spot!

While I'm here. Yesterday I discovered that these displays work without a 5V or GND connection. They appear to be able to be powered by just the data lines. Is this kind of thing common?

Gave you a good plug at my meeting, banged on about how good your after sales service is.

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

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Sun Jan 16, 2022 9:03 am

replacing a ~ with a ! I hope that didn't take you too long to spot!
It didn’t take long actually. I first checked the flip functions were writing the correct value to the correct registers which meant it had to be something to do with the part of the code that stores the flip state. Bypassing that bit of code and forcing a flipped state caused it to work at which point I spotted the bug.

A bitwise NOT is definitely wrong but it must have originally worked so my guess is that an update to the compiler (the library is nearly 7 years old now!) at some point caused it to stop working.

While I'm here. Yesterday I discovered that these displays work without a 5V or GND connection. They appear to be able to be powered by just the data lines. Is this kind of thing common?
Yeah it's because being OLED displays they are so low power that leakage current from the data lines is enough to power the module. I doubt it's a good idea to run them like that though.

Gave you a good plug at my meeting, banged on about how good your after sales service is.
Thanks! Word of mouth recommendations are always greatly appreciated.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Arduino”