How does one control the brightness of an OLED display (SSD1309) ?

Status
Not open for further replies.

spitwad

Member
I have really fallen in love with the cheap OLED displays that have now become available, but I have not found a definite way to control the charge pump for these guys.

I am using the teensy modified version of Oliver's Library (u8glib teensy add on : https://github.com/FriedCircuits/Ug8lib_Teensy )

I found some threads on the web suggesting the following code:

sendCommand(0x8d); // charge pump regulator
sendCommand(0x14); // send a value of 20 for max brightness ( I am thinking that 0 turns the display off and 10 would be 50%)

I tried to send these commands using the wire library, but perhaps that may be the incorrect way of doing this being that I am using <u8g_teensy.h>.

Does anyone here have any experience with this?
 
I got into the same OLED i would love to use it, therfore i would like to know if you did some progess on this matter.
Thanks.
 
Perhaps try:
uint8_t U8GLIB::setContrast(uint8_t contast)

contrast can be between 0 and 255

EDIT-
Poking around it seems that this exists:
Code:
uint8_t u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
{
  switch(msg)
  {
    case U8G_DEV_MSG_INIT:
      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
      u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_init_seq);
      break;
    case U8G_DEV_MSG_STOP:
      break;
    case U8G_DEV_MSG_PAGE_NEXT:
      {
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
        u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_data_start);    
        u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */
        u8g_SetAddress(u8g, dev, 1);           /* data mode */
        if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
          return 0;
        u8g_SetChipSelect(u8g, dev, 0);
      }
      break;
    case U8G_DEV_MSG_CONTRAST:
      u8g_SetChipSelect(u8g, dev, 1);
      u8g_SetAddress(u8g, dev, 0);          /* instruction mode */
      u8g_WriteByte(u8g, dev, 0x081);
      u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) ); /* 11 Jul 2015: fixed contrast calculation */
      u8g_SetChipSelect(u8g, dev, 0);      
      return 1; 
    case U8G_DEV_MSG_SLEEP_ON:
      u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on);    
      return 1;
    case U8G_DEV_MSG_SLEEP_OFF:
      u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off);    
      return 1;
  }
  return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}
This implys you should be able to do:
Code:
u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, U8G_DEV_MSG_CONTRAST, *contrastValue)

It is important you control the chip select while issuing commands
Code:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0);          /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, contrastValue );
u8g_SetChipSelect(u8g, dev, 0);
Should also work for you
 
Last edited:
I just wanted to update this as I spoke with Oliver the author of the wonderful U8GLIB library.

The brightness control was broken for the 1309 constructor.

This is the message that I received from Oliver with the fix. (Oliver is a very impressive individual by the way)

"Hi

Hmm.. yes, i guess this is still missing. It should work by using the u8g.setContrast and adding the MSG_CONTRAST to the low level driver. File u8g_dev_ssd1309_128x64.c could serve as an example for u8g_dev_ssd1306_128x64.c.
The code
case U8G_DEV_MSG_CONTRAST:
u8g_SetChipSelect(u8g, dev, 1);
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
u8g_WriteByte(u8g, dev, 0x081);
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) ); /* 11 Jul 2015: fixed contrast calculation */
u8g_SetChipSelect(u8g, dev, 0);
return 1;
should be placed into the device function for u8g_dev_ssd1306_128x64.c

I will create an issue for this.


Oliver"
 
...File u8g_dev_ssd1309_128x64.c could serve as an example for u8g_dev_ssd1306_128x64.c.
...should be placed into the device function for u8g_dev_ssd1306_128x64.c
He's referring to the 1306 constructor being broken not the 1309


Like I posted this function already exists for the 1309
 
Status
Not open for further replies.
Back
Top