I can not provide a full solution, but maybe some hits.
Adafruit lib contains the ssd1306_command function. This is a little bit more complicated in u8g2 (because u8g2 also supports many other displays) so the second loop will probably look like this (not tested):
olikraus:
I can not provide a full solution, but maybe some hits.
Adafruit lib contains the ssd1306_command function. This is a little bit more complicated in u8g2 (because u8g2 also supports many other displays) so the second loop will probably look like this (not tested):
For the first loop you can use the set contrast command from u8g2.
Oliver
Thank you Oliver for the suggestion. What is the purpose of GetU8c8() function? U8G2 is a brilliant library to work with. I also need to know what does setPrecharge do? I saw the suggested video by the OP and the implied limitations with I2C diaplays as their minimum contrast exhibit some constraints. I tried the following code with an I2C OLED module, and it seems like setContrast(0) hits the hardware limitation of the module as it was still quiet bright, not like the LED fade effect from absolute 0 to 255.
for (int dim=0; dim<=255; dim+=10) {
u8g2.SetContrast(dim);
}
delay(50);
U8g2 is a C library with a C++/Arduino wrapper. getU8x8() converts the C++/Arduino class into a pointer to the u8x8 C structure, which is required to call the low level functions.
I also need to know what does setPrecharge do?
There is no such function in u8g2. I do not know from where this got quoted. It is not from the original library.
like setContrast(0) hits the hardware limitation of the module as it was still quiet bright
Yes, this is true for some (all?) OLEDs. OP has used a trick here: The SSD1306 specific precharge register is used to do further brightness reduction. U8g2 and Adafruit libs do not provide access to this register because it is not portable and it may only work with some SSD1306 OLEDs.The trick was to do a fade down of the precharge values (there actualy two precharge periods and OP has reduced them both in parallel). This is from the initial code:
Actually i can not tell you whether this will work or why this works. This is something you need to figure out from the SSD1306 data sheet. I can only tell you how to send the same commands+argumements to u8g2. I mean ssd1306_command is a Adafruit library command, so I just translated the same loop to U8g2 commands.
Can I implement the code as it is? Since the compiler shows the following error:
'class U8G2_SSD1306_128X64_NONAME_F_HW_I2C' has no member named 'GetU8x8'.
I tried the same with U8X8 library and display constructor, the error persists. Can you please guide me to what I'm missing here?
Antrix:
Can I implement the code as it is? Since the compiler shows the following error:
'class U8G2_SSD1306_128X64_NONAME_F_HW_I2C' has no member named 'GetU8x8'.
I tried the same with U8X8 library and display constructor, the error persists. Can you please guide me to what I'm missing here?
My mistake, it is not "GetU8x8", but instead "getU8x8" (Arduino naming convention).
I´ve been struggeling to get my ssd1306 to dimm beyond what setConrast would allow. Now I´ve stumbled accross this piece of code, but son´t really know how to implement it.
You´ve stated that you uploaded the code. Please elaborate on where you put it.
I have tried in the main loop and get a nice pulsing brightness. At least it seems to go lower than what setContrast would allow.
I would like to know what dim1 and 2 are and what are their respective max/min values to be used.
MK1888:
See the commands in the datasheet. Both are single bytes, but precharge has two phases combined into the byte.
Not able to read that datasheet unfortunately.
Datasheet says this:
For 0xD9, page 40 just says "This command is used to set the duration of the pre-charge period. The interval is counted in number of DCLK, where RESET equals 2 DCLKs." and doesn't give a range
There is no range and no value, how am I supposed to set a value if I don't have a range?