Skip to content

Reference: Compile OLED display drivers

Steven Noreyko edited this page Apr 9, 2019 · 1 revision

OLED displays

Compile OLED display drivers (SH1106, SSD1322) from source

references:
https://github.com/notro/fbtft/wiki/Development
https://wiki.zerophone.org/index.php/Framebuffer_driver_for_SH1106
https://www.reddit.com/r/raspberry_pi/comments/4cnc12/sending_console_to_spi_displays/
https://github.com/alidaf/raspberryPi/wiki/SSD1322(SPI)--fbtft-framebuffer-driver

it is likely you need to do this for ssd1322 display if not using monome/linux source

NOTE: Kernel versions are different for Stretch - note changes below

ALSO NOTE: rpi-update will probably kill these changes to the display modules

Install dependencies

Needed for make menuconfig

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get -y install libncurses5-dev
sudo apt-get install git bc raspberrypi-kernel-headers
git clone --depth=1 https://github.com/raspberrypi/linux
# or 
git clone --depth=1 https://github.com/monome/linux


cd ~/linux

sh1106

sh1106 Driver file appears to already be in linux sources - but the set_gamma looks like it needs to be patched for 4.9 raspbian

    sed 's/u32 \*curves/unsigned long *curves/' drivers/staging/fbtft/fb_sh1106.c

Preparing the kernel module compilation

check with linux kernel you have with (adjust version# path below if needed)
may also need to confirm this matches what headers are available in the linux distrib

    uname -r

check headers to see if they match

ls /usr/src/linux-headers*
ls /lib/modules/
cp /usr/src/linux-headers-$(uname -r)/Module.symvers .
cp /usr/src/linux-headers-$(uname -r)/.config .

Use either make modules_prepare or make menuconfig to prepare configs

    make modules_prepare
    #  select "m" for ssd1322

or try menuconfig

    make menuconfig
        Device Drivers  ---> Staging Drivers ---> Support for small TFT LCD display modules  --->
        <M>   SH1106 driver
        <M>   SSD1322 driver

Save, Exit and then Always run 'make prepare' after changing the kernel config

make prepare

make -C ~/linux SUBDIRS=drivers/staging/fbtft modules

move the drivers

sudo cp -v ~/linux/drivers/staging/fbtft/*.ko /lib/modules/$(uname -r)/kernel/drivers/staging/fbtft/

sudo depmod -a

Test

change the gpios below to what you have wired for your display

sudo modprobe fbtft_device custom name=fb_sh1106 debug=1 speed=2000000 gpios=reset:15,dc:14
sudo modprobe fbtft_device custom name=fb_ssd1322 debug=1 speed=16000000 gpios=reset:15,dc:14

check dmesg

dmesg

test with (will show login prompt)

con2fbmap 1 1

unload command if you need it for some reason

sudo modprobe -r fbtft_device
sudo modprobe -r fb_ssd1322

Some example Modprobe example commands:

sudo modprobe fbtft_device name=adafruit13m debug=1 speed=2000000 gpios=reset:25,dc:23

sudo modprobe fbtft_device custom name=fb_sh1106 gpios=reset:5,dc:6 speed=32000000

sudo modprobe fbtft_device custom name=fb_ssd1322 debug=1 speed=16000000 gpios=reset:15,dc:14

sudo modprobe fbtft_device custom name=fb_ssd1322 width=128 height=64 gpios=reset:15,dc:14

sudo modprobe fbtft_device custom name=fb_sh1106 debug=1 speed=2000000 gpios=reset:15,dc:14

sudo modprobe fbtft_device name=adafruit22 debug=1 speed=2000000 gpios=reset:15,dc:14

Set console not to use OLED display

  • Edit /boot/cmdline.txt
sudo nano /boot/cmdline.txt 
  • Add to the end of the line:
fbcon=map:00

this stuff is out of date - use display overlay instead

get oled to load at startup

  • add a file:
sudo nano /etc/modules-load.d/fbtft_device.conf
spi-bcm2835
fbtft_device
  • add aother file:
sudo nano /etc/modprobe.d/fbtft_device.conf

add whichever of the following you need

options fbtft_device custom name=fb_sh1106 debug=1 speed=2000000 gpios=reset:15,dc:14
options fbtft_device custom name=fb_ssd1322 width=128 height=64 speed=16000000 gpios=reset:15,dc:14
  • Reboot and check the modules have loaded:
lsmod