OLED display with VIM3 (via SPI and luma.oled)

Dear all,

I’m having some OLED Display lying around here, which I want to connect to my VIM3. One is driven by SSD1309, the other by SSD1351, both can be connected via SPI having the same pin-outs:

GND	Ground
CS1/CS	ChipSelection

I already did some searching here, which lead me to this pin-out for VIM2 (Oled Display connection to VIM GPIO - #9 by Gouwa). For VIM3 it seems to be a little bit different. What I did so far, I enabled the spidev first editing the dtb to enable spicc1, disabling pwm_ef. That seemed to be successsful (/dev/spidev0.0 is there). That lead me to the GPIO Header/schematics (as referenced in VIM3L GPIO capability - #3 by quatro) the VIM3 seem to has the following pin out for SPI:


So I tried to conclude with VIM3 GPIO Pinout | Khadas Documentation but failed:

1.GND (power ground) ------------------- VIM3 PIN 28
2.VCC (power supply positive) ---------- VIM3 PIN 27
3.SCL (clock line) --------------------- VIM3 PIN 25? or 16?
4.SDA (data line) ---------------------- VIM3 PIN 26? or 15?
5.RES (reset line) --------------------- VIM3 PIN ???
6.DC (data / command) ------------------ VIM3 PIN 37?
7.CS (chip select) --------------------- VIM3 PIN 35? 15?

It’s really confusing me. Any help would be appreciated here.

Up to the next problem. I wanted to use luma.oled to drive the OLED display (GitHub - rm-hull/luma.oled: Python module to drive a SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106 OLED). It’s originally designed for RaspberryPi and depends on RPi.GPIO. I know that there is a RPi.GPIO implementation for VIM3 (How To Use RPi.GPIO | Khadas Documentation), but I’m unsure if this will work, because:

1.) RPI.Gpio example - #3 by Frank (last post) says “The RPi.GPIO in VIM3 can’t control SPI
2.) looking at the sources from RPi.GPIO for Khadas (RPi.GPIO-Khadas/khadas.h at master · frank180/RPi.GPIO-Khadas · GitHub) the physical pinouts for phyToGpio_rev_vim3 are totally different from the ones from for example wiringPi (WiringPi/khadas_vim3.c at master · khadas/WiringPi · GitHub). 3xx vs. 5xx

So it’s hard to say, if luma.oled will work with the Khadas made implementation of RPi.GPIO. Did someone already manage to get luma.oled to work on VIM3?

Another approach seems to be GitHub - rm-hull/OPi.GPIO: RPi.GPIO drop-in replacement library for Orange Pi Zero and other SBCs then (It originally is a replacement library for RPi.GPIO made for orange-pi, but one could easily write an device mapping file to work with VIM3. Look at for example at the on for M4 (OPi.GPIO/m4.py at master · rm-hull/OPi.GPIO · GitHub):

# The Rockchip RK3399 GPIO has 5 banks, GPIO0 to GPIO4, each with 32 pins.
# Each bank is then divided into 4 parts with 8 pins each, labeled A through D (A=0, B=1, C=2, D=3)
# So, GPIO4_D5 is 4*32 + 3*8 + 5 = 157

# NanoPi M4 physical board pin to GPIO pin
    7:    32,    # GPIO1_A0
    8:    145,   # GPIO4_C1/I2C3_SCL
    10:   144,   # GPIO4_C0/I2C3_SDA
    11:   33,    # GPIO1_A1
    12:   50,    # GPIO1_C2
    13:   35,    # GPIO1_A3
    15:   36,    # GPIO1_A4
    16:   54,    # GPIO1_C6
    18:   55,    # GPIO1_C7
    19:   40,    # GPIO1_B0/SPI1_TXD/UART4_TX
    21:   39,    # GPIO1_A7/SPI1_RXD/UART4_RX
    22:   56,    # GPIO1_D0
    23:   41,    # GPIO1_B1/SPI1_CLK
    24:   42,    # GPIO1_B2/SPI1_CSn0
    26:   149    # GPIO4_C5/SPDIF_TX

Couldn’t be to hard to write this definition file for VIM3 with getting the physical pin details out of WiringPi/khadas_vim3.c at master · khadas/WiringPi · GitHub, right?

Really looking forward if someone can help me with all this stuff.

Best regards

Ok, maybe i figured out the correct pins to use:

1.GND (power ground) ------------------- VIM3 PIN 28
2.VCC (power supply positive) ---------- VIM3 PIN 27
3.SCL (clock line) --------------------- VIM3 PIN 16		SPIB_SCLK
4.SDA (data line) ---------------------- VIM3 PIN 35/37		SPIB_MISO/SPIB_MOSI (which one to use?)
5.RES (reset line) --------------------- VIM3 PIN 26		defined in OPi.GPIO as RST GPIO / phy pin 499 / GPIOAO_3 (26)
6.DC (data / command) ------------------ VIM3 PIN 25		defined in OPi.GPIO as DC GPIO / phy pin 498 / GPIOAO_2 (25)
7.CS (chip select) --------------------- VIM3 PIN 15		SPIB_SS (is this one for chip select?)

What do the experts say? should this work out? pins correctly assigned?

1 Like

Really no one ever tried this? I’m not getting this to work. Can please one double check the pins mentioned from me?!

Hello, A search on OLED brings up several posts like this one, maybe something will help. Sorry, I cannot help directly.

Thanks, yes I already found that (see my first post). But this is for VIM1 and VIM2 and the pinouts have changed for VIM3 (also mentioned in the schematics). So this sadly is not helping me. But thanks anyway

Perhaps @Gouwa may have some advice.

Ok, getting this to work is a complete mess. Leaving the GPIO Pin for D/C “up in the air” I see some scrambled / mixed up / unreadable picture on the OLED. In general this leads to some problem somehow need to pull-up or pull-down this one with a transistor? But in general this shouldn’t be needed for SPI driven displays.

But all of this doesn’t make sense to me. It testet my both displays SSD1351 and SSD1309 on a Banana PI (same setup with LUMA + OBi.GPIO mapping the correct pins for DC/RST) and this works without any problem.

I really have no further clue to get this to work with VIM3.

Okay, everything is getting clear now. I couldn’t find any single GPIO which is working/switchable

The problem is, that PIN 15,16,35,37 are occupied by the SPI

How can I use for example PIN 25 and 26? Or 29 to 32 (30 and 32 seem to be problematic an beloging to MMC)?

I mean, what I can do is the following:

PIN 25

echo 498 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio498/direction
echo 0/1 > /sys/class/gpio/gpio498/value


PIN 26

echo 499 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio499/direction
echo 0/1 > /sys/class/gpio/gpio499/value

But the output doesn’t switch (tested with LED). Furthermore these pins seem to be pulled up by default. Tested also with PIN 29 and 31 (pulled down default), but same thing here. I even can’t get the LED to light up.

So what to do? How to get these GPIO pins running?!

Ok, I finally got it to work and know what? I was able to switch the GPIOs with the following commands:

(for example PIN 22)
gpio -g mode $PHY out
gpio -g write $PHY 0
gpio -g write $PHY 1

but not with
echo 475 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio475/direction
echo 0/1 > /sys/class/gpio/gpio475/value

isn’t that strange?! Can someone explain this?!

Anyway, I just needed to change processing of the GPIO pins in OPi.GPIO using the gpio-command instead of the sysfs calls and now the OLED display works.

Regarding the GPIO pins, I was able to use the following ones:

#### PIN 22 (I2C_M3_SCL) PHY=475
#### PIN 23 (I2C_M3_SDA) PHY=474
#### PIN 29 (I2SB_SCLK) PHY=461
#### PIN 30 (I2S_MCLK0) PHY=460
#### PIN 31 (I2SB_SDO) PHY=463
#### PIN 32 (I2SB_LRCK) PHY=462
#### PIN 33 (I2SB_SDI) PHY=464

I will write a total sumup within the next days. So far, so good…