adafruit / Adafruit_CircuitPython_DisplayIO_SSD1306

DisplayIO driver for SSD1306 monochrome OLED displays
MIT License
57 stars 24 forks source link

function of the brightness (contrast) control is missing #25

Closed CrackXT closed 2 years ago

CrackXT commented 2 years ago

Please also integrate the command for "display.contrast ()" for brightness control in the library.

This is contained in the "Adafruit_CircuitPython_SSD1306", isn't it here?

tekktrik commented 2 years ago

It looks like this library uses the DisplayIO implementation of the hardware. If I'm understanding correctly, the equivalent command for contrast() in Adafruit_CircuitPython_SSD1306 here would be setting the object's brightness:

For Adafruit_CircuitPython_SSD1306:

display.contrast(51) # 0 - 255, so this is 20%

For Adafruit_CircuitPython_DisplayIO_SSD1306:

dislpay.brightness = 0.2 # 0.0 - 1.0, so this is also 20%

Not sure if one should be renamed to match the other, but that seems to be the same functionality.

tekktrik commented 2 years ago

Updated to correct example values

CrackXT commented 2 years ago

Thank you for your feedback, I already had this idea. However, brightness is not defined in the library and so the line is only processed as an error.

tekktrik commented 2 years ago

Oh weird, I wonder if that's a bug or that functionality needs to be added, I don't really know the displayio module that well... The register for brightness is in the code at least so it's weird it doesn't use it:

https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306/blob/fccc7d7d7a9281f73a454df672e2d3d442eb96ac/adafruit_displayio_ssd1306.py#L84

tekktrik commented 2 years ago

Out of curiosity, what's the error text you get, and with what code? I'd love to try and fix this.

anecdata commented 2 years ago

On Adafruit CircuitPython 7.0.0 on 2021-09-20; Adafruit Feather M4 Express with samd51j19 with OLED FeatherWing, it sort of works, but I only get 3 visually distinct levels of brightness:

import time
import board
import displayio
import adafruit_displayio_ssd1306

i2c = board.I2C()

displayio.release_displays()

display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)

splash = displayio.Group()

background_bitmap = displayio.Bitmap(display.width, display.height, 1)
background_palette = displayio.Palette(1)
background_palette[0] = 0xFFFFFF
background = displayio.TileGrid(background_bitmap, pixel_shader=background_palette)
splash.append(background)
display.show(splash)

while True:
    for contrast in (0, 1, 0.1):
        display.brightness = contrast
        time.sleep(1)

But I think implementing the proper contrast control to register 0x81 will give better performance. I don't get a CircuitPython exception.

anecdata commented 2 years ago

I didn't dive deeply enough into the core to see what it actually does. I'm surprised it works at all if it's not using the contrast register.

deshipu commented 2 years ago

It is using the 0x81 command. There is probably a problem with how the value is converted.

anecdata commented 2 years ago

I suppose it's a safe assumption for now that any I2C display will support that register. Transfer this issue to circuitpython?

tekktrik commented 2 years ago

I'll add this to the core then, thanks everyone!