adafruit / Adafruit_CircuitPython_DisplayIO_SH1106

CircuitPython library for SH1106 OLED displays
MIT License
4 stars 4 forks source link

sleep() throws error #17

Closed EAGrahamJr closed 4 months ago

EAGrahamJr commented 8 months ago

Adding a display.sleep() call at the end of the example causes an error to be thrown. This the hacked-up code that reproduces the error:

import busio
import displayio
import board
import adafruit_displayio_sh1106

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)

WIDTH = 128
HEIGHT = 64
# create the display and put it to sleep
display = adafruit_displayio_sh1106.SH1106(display_bus, width=WIDTH, height=HEIGHT)
display.sleep()

This is the error (personal directories removed):

$ python brokesleep.py 
Traceback (most recent call last):
  File "brokesleep.py", line 14, in <module>
    display.sleep()
  File "venv/lib/python3.11/site-packages/adafruit_displayio_sh1106.py", line 111, in sleep
    self.bus.send(0xAE, b"")  # 0xAE = display off, sleep mode
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/displayio/_i2cdisplay.py", line 90, in send
    self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + data))
                                                             ~~~~~~~~~~^~~~~~
TypeError: can only concatenate list (not "bytes") to list
dargus commented 4 months ago

More info: The issue affects both .sleep() and .wake(). I was able to get it working by putting self.bus.send(0xAE, 0x00) into adafruit_displayio_sh1106.py

and I ALSO had to modify i2cdisplaybus/init.py from self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + data)) to self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + [data]))

I'm not a good enough python programmer to figure out where/how this needs to be fixed at large, but hopefully it helps someone else if this can't be fixed upstream or elsewhere.

dargus commented 4 months ago

https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1106/pull/18

Pull request submitted that should fix this.

FoamyGuy commented 4 months ago

resolved by #18