rgb oled display dim through pwm?

by dere1 on Tue Jul 03, 2012 3:13 pm

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?
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 12:01 am

Re: rgb oled display dim through pwm?

by adafruit_support_rick on Tue Jul 03, 2012 3:53 pm

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
adafruit_support_rick
 
Posts: 8551
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: rgb oled display dim through pwm?

by dere1 on Thu Jul 05, 2012 5:14 pm

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?
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 12:01 am

Re: rgb oled display dim through pwm?

by adafruit on Thu Jul 05, 2012 5:24 pm

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
adafruit
 
Posts: 11507
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: rgb oled display dim through pwm?

by dere1 on Thu Jul 05, 2012 5:27 pm

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...
dere1
 
Posts: 12
Joined: Thu Sep 15, 2011 12:01 am

Re: rgb oled display dim through pwm?

by adafruit on Thu Jul 05, 2012 7:42 pm

yep, thats what we suggest!
User avatar
adafruit
 
Posts: 11507
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: rgb oled display dim through pwm?

by gsentlin on Tue Oct 16, 2012 11:55 am

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.
gsentlin
 
Posts: 3
Joined: Sun Aug 19, 2012 9:51 am

Re: rgb oled display dim through pwm?

by adafruit_support_rick on Tue Oct 16, 2012 12:16 pm

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
adafruit_support_rick
 
Posts: 8551
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: rgb oled display dim through pwm?

by gsentlin on Wed Oct 17, 2012 12:46 am

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.
gsentlin
 
Posts: 3
Joined: Sun Aug 19, 2012 9:51 am

Re: rgb oled display dim through pwm?

by adafruit_support_rick on Wed Oct 17, 2012 9:16 am

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.
User avatar
adafruit_support_rick
 
Posts: 8551
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: rgb oled display dim through pwm?

by gwilson5 on Sat Dec 01, 2012 7:09 pm

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.
gwilson5
 
Posts: 16
Joined: Sun Nov 25, 2012 4:03 pm

Re: rgb oled display dim through pwm?

by adafruit_support_rick on Sat Dec 01, 2012 8:01 pm

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.
User avatar
adafruit_support_rick
 
Posts: 8551
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: rgb oled display dim through pwm?

by gwilson5 on Sat Dec 01, 2012 8:46 pm

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!
gwilson5
 
Posts: 16
Joined: Sun Nov 25, 2012 4:03 pm