rgb oled display dim through pwm?

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 1:01 am

rgb oled display dim through pwm?

Post by dere1 »

is there a way to dim the display through pwm? i know it's not backlit, but i think there should still be a way? one of the datasheets says it can be done through the iref pin on the logic driver, but i don't see iref in the pinout diagram that i found for the chip...

i tried attaching the power inputs on the chips to pwm control but that did not work

is there another way to do this?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: rgb oled display dim through pwm?

Post by adafruit_support_rick »

The driver chip sets an individual PWM value for each pixel on the display, depending on the pixel value.

If you want to dim simply change the image data to be dimmer. You can do that by applying a scaling factor to the color of objects you draw. If you are displaying a bitmap image, you can go through and scale each pixel before writing it to the display.

Offhand, I don't know if the library allows you to set the contrast of the display; if so, you may be able to use that to get a dimming effect.

EDIT:
the adafruit library provides two methods, void writeData(uint8_t d); and void writeCommand(uint8_t c); which can be used to write directly to the driver chip. I had a brief look at the datasheet, and you may be able to control the overall brightness of the display by using the PRECHARGE commands and or the CONTRAST commands. See page 26 of the datasheet for a discussion of the precharge sequence in setting the grayscale level of each pixel.

Also, note command ACh, which puts the device in "dim mode" There is a "dim mode" contrast setting, and the display can be turned ON, OFF or DIM via commands AFh, AEh, and ACh. See page 30 of datasheet

User avatar
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 1:01 am

Re: rgb oled display dim through pwm?

Post by dere1 »

thanks, i was able to do it by altering the bmp data, but this requires reloading the image each time to dim, which is not the effect i was hoping for.

sorry if this is a silly question, but i'm not very experienced with writing to libraries- i tried messing with the values for the contrast and it worked a little bit. the precharge didn't do very much though. i tried using writeCommand to write a function in the Arduino code but it gave me an error about the ports- do i need to write the functions in the library to alter the contrast levels?

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: rgb oled display dim through pwm?

Post by adafruit »

OLED displays arent really dimmable - they're supposed to be bright - and you have a risk of damaging the display by messing too much with the registers. We suggest scaling the bitmap rather than messing with the display

User avatar
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 1:01 am

Re: rgb oled display dim through pwm?

Post by dere1 »

so in this case i would have to reload the image data to the screen each time i wanted to change the brightness?

thanks for the heads up, definitely don't want to mess it up...

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: rgb oled display dim through pwm?

Post by adafruit »

yep, thats what we suggest!

User avatar
gsentlin
 
Posts: 5
Joined: Sun Aug 19, 2012 10:51 am

Re: rgb oled display dim through pwm?

Post by gsentlin »

Hello. I now have my OLED SSD1306 working with my Arduino Uno board. I see the SSD1306 datasheet boasts "256 step contrast brightness current control" but cannot find out how to change the individual dimness of each pixel. This thread suggests "scaling the bitmap" but I'm not sure how to do that. Can you provide some direction? Thanks.

BTW, I'm using this 128x64 OLED with the adafruit datalogger board and was having SRAM limit problems. I ended up using the 128x32 library and example code to reduce the SRAM buffer by 1/2. It misses every other line but still looks pretty good. It would be nice to not use so much SRAM for this display. Otherwise it's a great little display. Thanks.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: rgb oled display dim through pwm?

Post by adafruit_support_rick »

To scale a bitmap, you would apply some scaling function to each pixel. For example, if you divided the value of each pixel in half, your bitmap would be half as bright (OK, not "half", as human perception of brightness is not linear, and the display may not be exactly linear either. But you get the idea).

User avatar
gsentlin
 
Posts: 5
Joined: Sun Aug 19, 2012 10:51 am

Re: rgb oled display dim through pwm?

Post by gsentlin »

Thanks for the explanation. I opened up the output from LCD assistant for my bitmap, and see there are 16 hex bytes across and 32 rows. I understand the 16 bytes to be 128 bits, so each bit corresponds to a pixel, making them only on or off, correct? The settings the adafruit tutorial (http://learn.adafruit.com/monochrome-ol ... d-examples) suggest are 8 pixels/byte, so that checks out, I think. Perhaps I'm missing something.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: rgb oled display dim through pwm?

Post by adafruit_support_rick »

Ah, I see. This thread was for the RGB OLED display, which has multi-bit pixels. You can't scale 1-bit a monochrome bitmap.

But, I think you're in luck. The SSD1306 library has a function that allows you to send commands to the chip. To access the contrast setting, you would send the SSD1306_SETCONTRAST command, followed by an 8-bit contrast level. Contrast increases as the level increases. You could do something like this:

Code: Select all

void setBrightness(Adafruit_SSD1306 display, uint8_t brightness)
{
    display. ssd1306_command(SSD1306_SETCONTRAST);
    display. ssd1306_command(brightness);
}
Caveat: Note the warning from adafruit posted above. The driver chip supports the command, but I don't know whether or not there is a risk to doing this with the monochrome display.

gwilson5
 
Posts: 16
Joined: Sun Nov 25, 2012 5:03 pm

Re: rgb oled display dim through pwm?

Post by gwilson5 »

I am willing to take the risks on dimming the monochrome display. However, not quite sure how to send the commands you suggested. I am not sure of what the first parameter does or what input it is looking for.
referring to --> Adafruit_SSD1306 display from

Code: Select all

void setBrightness(Adafruit_SSD1306 display, uint8_t brightness)
Also, does the 8-bit level have to be sent in hex?

I have experimented with a few things, but don't think I am calling the routine properly as I don't get any difference.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: rgb oled display dim through pwm?

Post by adafruit_support_rick »

OK - I just tossed off that bit of code as a suggestion - I haven't actually tried it.

Looking at it now, I should have made the first parameter a pointer to the display object you declare in your sketch. And you're really not setting brightness, you're setting contrast, (which is going to amount to roughly the same thing on an OLED). So, let's change the same of the function accordingly:

Code: Select all

void setContrast(Adafruit_SSD1306 *display, uint8_t contrast)
{
    display->ssd1306_command(SSD1306_SETCONTRAST);
    display->ssd1306_command(contrast);
}
So, in your sketch, you've got something like this:

Code: Select all

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oledDisplay(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
This declares an object of type Adafruit_SSD1306 with the name oledDisplay.

To call the contrast function, you pass it a reference (i.e., pointer) to oledDisplay, and a value for the desired contrast setting. For example, to set the contrast level to 50%, you would do this:

Code: Select all

setContrast(&oledDisplay, 128);  //contrast is a number between 0 and 255. Use a lower number for lower contrast
I STILL haven't tested it :shock: . I'm just going on what I see in the library code and tin the datasheet.

gwilson5
 
Posts: 16
Joined: Sun Nov 25, 2012 5:03 pm

Re: rgb oled display dim through pwm?

Post by gwilson5 »

That makes sense. I would have never figured it out on my own.

It does work. However, it is only a minimal effect (maybe 15% light output decrease when set to 0).

Thanks again!

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”