rm-hull / luma.oled

Python module to drive a SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106 OLED
https://luma-oled.readthedocs.io
MIT License
807 stars 161 forks source link

NanoPi M4v2 + OPi.GPIO + Luma.OLED + SSD1351 Error #331

Closed TCB13 closed 3 years ago

TCB13 commented 3 years ago

Hello,

I've posted about this here but I'm not sure if this isn't a luma.oled issue.

Device Info

SBC: NanoPi M4v2 System: Armbian 5.10.35-rockchip64 #21.05.1 SMP PREEMPT Fri May 7 13:53:11 UTC 2021 aarch64 GNU/Linux Display: https://www.ebay.com/itm/203101646517 Datasheet: https://www.waveshare.com/w/upload/5/5b/1.5inch_RGB_OLED_Module_User_Manual_EN.pdf

Expected behaviour

Working SSD1351 SPI LCD with the provided luma.oled examples on the NanoPi M4v2 board.

Actual behaviour

  1. Install Luma.OLED:
    apt-get update
    apt-get install python3 python3-pip python3-pil libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libopenjp2-7 libtiff5 -y
    pip3 install luma.oled
  2. Install OPi.GPIO:
    pip3 install --upgrade OPi.GPIO
  3. Wire my LCD as:
    
    MOSI > GPIO1_A7 > SPI1_RXD > M4 Pin 21   > LCD DIN Pin (blue)
    SCK > GPIO1_B1 > SPI1_CLK > M4 Pin 23     > LCD CLK Pin (yellow)
    CS > GPIO1_B2  > SPI1_CSn0 > M4 Pin 24    > LCD CS Pin (orange)

RST > GPIO1_A1(3V) > M4 Pin 11 > LCD RST Pin (white) DC > GPIO1_A3(3V) > M4 Pin 13 > LCD DC Pin (green)

4. Find the spidev and run a Luma.OLED example as:

ls /dev/spi* /dev/spidev1.0

python3 luma.examples/examples/3d_box.py --display=ssd1351 --interface=spi --width=128 --height=128 --spi-bus-speed=16000000 --bgr --spi-device=1 --spi-port=0 --gpio-reset=35 --gpio-data-command=33 --gpio=OPi.GPIO --gpio-mode=nanopi.m4.BOARD


From what I understand of https://github.com/rm-hull/OPi.GPIO/blob/master/nanopi/m4.py my physical pin 11 maps to GPIO 33 and physical pin 13 to GPIO 35. Is this even correct?

Now it fails with the following output:

Traceback (most recent call last): File "luma.examples/examples/3d_box.py", line 129, in device = get_device() File "/root/luma.examples/examples/demo_opts.py", line 61, in get_device device = cmdline.create_device(args) File "/usr/local/lib/python3.7/dist-packages/luma/core/cmdline.py", line 246, in create_device device = Device(serial_interface=interface(), **params) File "/usr/local/lib/python3.7/dist-packages/luma/core/cmdline.py", line 161, in spi gpio=self.gpio or GPIO) File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 299, in init bitbang.init(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST) File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 187, in init self._DC = self._configure(kwargs.get("DC")) File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 200, in _configure self._gpio.setup(pin, self._gpio.OUT) File "/usr/local/lib/python3.7/dist-packages/OPi/GPIO.py", line 470, in setup pin = get_gpio_pin(_mode, channel) File "/usr/local/lib/python3.7/dist-packages/OPi/pin_mappings.py", line 80, in get_gpio_pin return _pin_map[mode][channel] KeyError: 33



Thank you.
TCB13 commented 3 years ago

Yet another example, simple code:

#!/usr/bin/env python3
from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.oled.device import ssd1351
from time import sleep
import nanopi.m4
import OPi.GPIO as GPIO

GPIO.setmode(nanopi.m4.BOARD)
interface = spi(gpio=GPIO ,device=1, port=0, bus_speed_hz=16000000, gpio_DC=33, gpio_RST=35)

device = ssd1351(interface, rotate=1)

with canvas(device) as draw:
    draw.rectangle(device.bounding_box, outline="white", fill="black")
    draw.text((10, 40), "Hello World", fill="white")
sleep(10)

Now if I run it:

# ./test.py
Traceback (most recent call last):
  File "./test.py", line 11, in <module>
    interface = spi(gpio=GPIO ,device=1, port=0, bus_speed_hz=16000000, gpio_DC=33, gpio_RST=35)
  File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 299, in __init__
    bitbang.__init__(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST)
  File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 187, in __init__
    self._DC = self._configure(kwargs.get("DC"))
  File "/usr/local/lib/python3.7/dist-packages/luma/core/interface/serial.py", line 200, in _configure
    self._gpio.setup(pin, self._gpio.OUT)
  File "/usr/local/lib/python3.7/dist-packages/OPi/GPIO.py", line 470, in setup
    pin = get_gpio_pin(_mode, channel)
  File "/usr/local/lib/python3.7/dist-packages/OPi/pin_mappings.py", line 80, in get_gpio_pin
    return _pin_map[mode][channel]
KeyError: 33
TCB13 commented 3 years ago

Apparently it seems like I've to specify the physical pins:

python3 luma.examples/examples/3d_box.py --display=ssd1351 --interface=spi --width=128 --height=128 --spi-bus-speed=16000000 --spi-device=0 --spi-port=1 --gpio-reset=11 --gpio-data-command=13 --gpio OPi.GPIO --gpio-mode nanopi.m4.BOARD
Version: luma.oled 3.8.1 (luma.core 2.3.1)
Display: ssd1351
Interface: spi
Dimensions: 128 x 128
------------------------------------------------------------

No errors now, but unfortunately I still don't get an image on the LCD.

TCB13 commented 3 years ago

My pin assignment was also wrong. I was connecting the LCD DIN to the SBC RXD pin. Switched to TXD and it works just fine!

The final wiring is:

MISO > GPIO1_B0 > SPI1_TXD > 19     > DIN | Azul 
SCK > GPIO1_B1 > SPI1_CLK > 23     > CLK | Amarelo
CS > GPIO1_B2  > SPI1_CSn0 > 24    > CS | Laranja

RST > GPIO1_A1(3V) > M4 Pin 11    >   LCD RST Pin (white)
DC > GPIO1_A3(3V)  > M4 Pin 13        >   LCD DC Pin (green)

Now running:

python3 luma.examples/examplebounce.py \
--display=ssd1351 \
--interface=spi --width=128 --height=128 \
--spi-bus-speed=50000000 \
--spi-device=0 \
--spi-port=1 \
--gpio-reset=11 \
--gpio-data-command=13 \
--gpio OPi.GPIO \
--gpio-mode nanopi.m4.BOARD

Produces the expected output:

photo_2021-09-18_22-20-04-horz

It even runs over 40fps!

Thank you all for the time invested in this library and for being my rubber duck debugging ears :)