I am using a Waveshare OLED Display 1.3 B and trying to run it with a Raspberry Pi Zero 2 W. Because I have several devices hanging on my Pi I cannot use the suggested PINs GPIO 25 for Data and GPIO 27 for Reset. I tried now to use GPIO 16 (Data) and GPIO 19 (Reset) instead. Therefore I have added the parameters gpio_DC = 16 and gpio_RST = 19 to my code in order to tell the device to use those GPIOs. All other GPIOs are used as stated in the LUMA Documentation. I'm using the luma.oled library. Unfortunately the Documentation states:
If you’re already using the listed GPIO pins for Data/Command and/or Reset, you can select other pins and pass gpio_DC and/or gpio_RST argument specifying the new GPIO pin numbers in your serial interface create call (this applies to PCD8544, ST7567 and ST7735)
My OLED Display has the SH1106 driver so that might not apply to my display?
Anyhow, the code runs as requested, but the display stays off.
Is there anything I can do to get the display running this way?
Here is my code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import time
import os
import pycurl, json
import argparse
from io import BytesIO
from PIL import ImageFont
from luma.core.interface.serial import spi
from luma.oled.device import sh1106
from luma.core.render import canvas
# Main program logic follows:
if __name__ == '__main__':
while True:
# catching command arguments
parser = argparse.ArgumentParser()
parser.add_argument('-1', '--width', help='Display width', required=True, type=int)
parser.add_argument('-2', '--height', help='Display height', required=True, type=int)
parser.add_argument('-3', '--data', help='Value for Data GPIO', required=True, type=int)
parser.add_argument('-4', '--reset', help='Value for Reset GPIO', required=True, type=int)
args = parser.parse_args()
if args.width:
oledWidth = args.width
if args.height:
oledHeight = args.height
if args.data:
oledData = args.data
if args.reset:
oledReset = args.reset
serial = spi(device=0,port=0)
device =sh1106(serial, gpio_DC=oledData, gpio_RST=oledReset)
device.width=oledWidth
device.height=oledHeight
# use custom font
font_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '/home/pi/blpi/luma.examples/examples/fonts/', 'helvetica400.ttf'))
font2 = ImageFont.truetype(font_path, 21)
try:
with open('<filename>','r') as f:
crdtls = f.readline()
f.close()
except:
print(datetime.now(tz=None) + "BLPI config file could not be opened.")
if 'error' in response:
logf.write(datetime.now(tz=None) + "Failed to load DHT11 data: {0}\n".format(response['error']['message']))
else:
try:
with canvas(device) as draw:
draw.text((35, 0), u"\u2191 ", font=font2, fill="white")
draw.text((0, 16), u"%s°C %srH%%" % ("Temperature 1", "Humidity 1"), font=font2, fill="white")
draw.text((35, 32), u"\u2193", font=font2, fill="white")
draw.text((0, 48), u"%s°C %srH%%" % ("Temperature 2", "Humidity 2"), font=font2, fill="white")
except:
print ("Canvas Draw command could not be executed.")
time.sleep(60)