zashi
Posts: 7
Joined: Mon Nov 10, 2014 5:31 pm

Help writing an overlay (dts / device tree) for an ssd1307

Sat Apr 04, 2015 2:44 pm

I could use a little help / sanity check trying to get an overlay working.

I've got a ssd1306-based OLED screen wired up. It's uses i2c. i2cdetect -y 1 shows me the device on the i2c bus.

To use the in-kernel driver for the ssd1306 (which is ssd1307fb.ko), you have to add a device tree entry.

I wrote a dts by combining the rpi overlay example from here http://www.raspberrypi.org/documentatio ... ce-tree.md with the ssd1307fb example from here https://www.kernel.org/doc/Documentatio ... 1307fb.txt but it is no doubt wrong (see bottom of post).

I compiled the dts into a dtb via

Code: Select all

dtc [email protected] -I dts -O dtb -o oled-overlay.dtb oled-overlay.dts 
, stashed oled-overlay.dtb into /boot/overlays and then added these two lines to config.txt:

Code: Select all

device_tree=bcm2708-rpi-b-plus.dtb
dtoverlay=oled
I know I got device-tree loaded and working as /proc/device-tree exists and is populated, plus I've got the human readable form of the Machine showing: [ 0.000000] Machine model: Raspberry Pi Model B+

But I am not getting a second framebuffer device like I would expect, nor is ssd1307fb loading automatically. If I load the module manually nothing happens--no output in dmesg. /proc/device-tree does not contain any references to oled or solomon.

Can anyone help me figure out what I'm doing wrong or what changes I need to make to my overlay? Perhaps if we can get this working we can included it by default like the other overlays, as these OLED screens are quite cheap (mine was less than USD$10 with shipping).

My oled-overlay.dts:

Code: Select all

// Definitions for Rpi-Proto
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2708";

	[email protected] {
		target = <&i2c1>;
		__overlay__ {
			[email protected] {
					compatible = "solomon,ssd1306fb-i2c";
					reg = <0x3c>;
					
			};
		};
	};
};


notro
Posts: 693
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: Help writing an overlay (dts / device tree) for an ssd13

Sat Apr 04, 2015 8:18 pm

Does your device show up in /sys/bus/i2c/devices/ ?

Have you built your own kernel?
Because the module is not enabled in the official one:

Code: Select all

$ zgrep SSD1307 /proc/config.gz
# CONFIG_FB_SSD1307 is not set
You can enable the i2c bus in the oled overlay as well:

Code: Select all

		target = <&i2c1>;
		__overlay__ {
			status = "okay";

zashi
Posts: 7
Joined: Mon Nov 10, 2014 5:31 pm

Re: Help writing an overlay (dts / device tree) for an ssd13

Sat Apr 04, 2015 10:40 pm

I'm not running a stock kernel, and yes I have ssd1307fb.ko built.

zashi
Posts: 7
Joined: Mon Nov 10, 2014 5:31 pm

Re: Help writing an overlay (dts / device tree) for an ssd13

Sun Apr 05, 2015 2:27 pm

I'm not running a stock kernel, but yes, I of course have the ssd1307fb module compiled.

No, I do not see anything on the i2c bus in /sys/bus/i2c. If you're wondering if i2c is loaded and working, it clearly is, as you can see the oled driver on the i2c bus via i2cdetect.

notro
Posts: 693
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: Help writing an overlay (dts / device tree) for an ssd13

Sun Apr 05, 2015 5:31 pm

The device must show up in /sys/bus/i2c/devices

This is an i2c driver I'm currently working on:

Device Tree

Code: Select all

$ ls -l /proc/device-tree/soc/i2c[email protected]/
total 0
-r--r--r-- 1 root root  4 Apr  5 17:04 #address-cells
-r--r--r-- 1 root root  4 Apr  5 17:04 clock-frequency
-r--r--r-- 1 root root  4 Apr  5 17:04 clocks
-r--r--r-- 1 root root 17 Apr  5 17:04 compatible
-r--r--r-- 1 root root  8 Apr  5 17:04 interrupts
-r--r--r-- 1 root root  4 Apr  5 17:04 linux,phandle
-r--r--r-- 1 root root  4 Apr  5 17:04 name
-r--r--r-- 1 root root  4 Apr  5 17:04 phandle
-r--r--r-- 1 root root  4 Apr  5 17:04 pinctrl-0
-r--r--r-- 1 root root  8 Apr  5 17:04 pinctrl-names
-r--r--r-- 1 root root  8 Apr  5 17:04 reg
-r--r--r-- 1 root root  4 Apr  5 17:04 #size-cells
drwxr-xr-x 2 root root  0 Apr  5 17:04 [email protected]
-r--r--r-- 1 root root  5 Apr  5 17:04 status

$ ls -l /proc/device-tree/soc/[email protected]/[email protected]/
total 0
-r--r--r-- 1 root root 19 Apr  5 17:07 compatible
-r--r--r-- 1 root root  4 Apr  5 17:07 linux,phandle
-r--r--r-- 1 root root  8 Apr  5 17:07 name
-r--r--r-- 1 root root  4 Apr  5 17:07 phandle
-r--r--r-- 1 root root  4 Apr  5 17:07 pinctrl-0
-r--r--r-- 1 root root  8 Apr  5 17:07 pinctrl-names
-r--r--r-- 1 root root  4 Apr  5 17:07 reg
-r--r--r-- 1 root root 12 Apr  5 17:07 reset-gpios

$ hexdump -C /proc/device-tree/soc/[email protected]/[email protected]/reg
00000000  00 00 00 3c                                       |...<|
00000004

i2c device

Code: Select all

$ ls -l /sys/bus/i2c/devices/1-003c/
total 0
lrwxrwxrwx 1 root root    0 Apr  5 17:03 driver -> ../../../../../bus/i2c/drivers/ada-ssd1306fb
drwxr-xr-x 4 root root    0 Apr  5 17:03 drm
-r--r--r-- 1 root root 4096 Apr  5 17:03 modalias
-r--r--r-- 1 root root 4096 Apr  5 17:03 name
lrwxrwxrwx 1 root root    0 Apr  5 17:03 subsystem -> ../../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Apr  5 17:03 uevent

Regex_Philbin
Posts: 2
Joined: Tue Jun 14, 2016 1:28 am

Re: Help writing an overlay (dts / device tree) for an ssd13

Tue Jun 14, 2016 1:32 am

I know this thread is old, but did anyone make progress on this? I feel really close, I have things showing up in /sys/bus/i2c/devices/...

zashi
Posts: 7
Joined: Mon Nov 10, 2014 5:31 pm

Re: Help writing an overlay (dts / device tree) for an ssd13

Tue Jun 14, 2016 11:55 am

Nope, but if you get it working please post. I never could.

Regex_Philbin
Posts: 2
Joined: Tue Jun 14, 2016 1:28 am

Re: Help writing an overlay (dts / device tree) for an ssd13

Wed Jun 15, 2016 12:02 am

Thanks, I will.. by the way, my display only has 4 pins, no reset pin, which I think could be a problem here but not sure.. also I'm using a Pi Zero but I don't think that matters..

fiveseven808
Posts: 10
Joined: Fri Mar 03, 2017 1:56 am

Re: Help writing an overlay (dts / device tree) for an ssd13

Sun Mar 26, 2017 11:08 am

Hey, I know this thread is almost a year old, but I was wondering if anyone in here figured this out?

I want to use this SSD1307 driver in 1306 mode (since it supports it) but I'm not sure where to start.

If I had to guess, the ssd1307fb module needs to be loaded in /etc/modules so it runs on boot (i guess?).

Really curious about using an I2C SSD1306 as a frame buffer! fbtft unfortunately only supports SPI (and it works damn well!)
Need to get a "headless" pi up and running with a hardware input/output and minimal effort? Check out the hueBerry project here!
https://github.com/fiveseven808/HueBerry_SmartSwitch

The (soon-to-be) extensible home automation controller platform!

ighea
Posts: 8
Joined: Thu Nov 17, 2016 9:45 pm

Re: Help writing an overlay (dts / device tree) for an ssd1307

Sun Feb 04, 2018 7:32 pm

I'm sorry for rising a dead thread, but I have some sad results.

I also bought one of these 4-pin OLED displays with ssd1306 driver and wanted to get it to work as framebuffer device. Becouse of that I also ended up on this thread.

As somebody mentioned here the problem with original ssd1307fb driver is that it expects the screen to have a reset pin set and configured on the device tree settings file. After coursing through the source file the reset didn't seem to be used for much and just dirty removal for testing proved some successful results. I got the fb device to appear and work somewhat.

Well, i2c is slow. Really slow. Also, the image seems to be mirrored and rotated so it would require some additional tweaking. I also couldn't get any usefull results out from playing 1-bit video (didn't play, some initializen problems that didn't really help to solve the proble, I assumed too small screen size or buffers) or displaying images with fbi program. Console worked after some tweaking and playing around, but is mostly useless for anything at this moment.

Overall it would be better to just use Adafruit's python library to display stuff on the small monochrome screen.

Becouse the effort this took I wanted to document it loosely here for future reference.

After collecting bits from here and there I ended up with following puzzle pieces:

device tree file: oled.dts:

Code: Select all

// Definitions for Rpi-Proto
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	[email protected] {
		target = <&i2c>;
		__overlay__ {
			status = "okay";
			#address-cells = <1>;
			#size-cells = <0>;			
			ssd1306: [email protected] {
				compatible = "solomon,ssd1306fb-i2c";
				reg = <0x3c>;
				solomon,width = <128>;
				solomon,height = <64>;
				solomon,page-offset = <0>;
			};
		};
	};
};
Compile dtbo and move it to overlays:

Code: Select all

dtc [email protected] -I dts -O dtb -o oled.dtbo oled.dts && mv oled.dtbo /boot/overlays/
Install kernel headers for stock kernel for compiling the modified driver:

Code: Select all

sudo apt install raspberrypi-kernel-headers
Fetch appropriate driver source from Raspberry Pi kernel tree for ssd1307fb:

Code: Select all

wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/drivers/video/fbdev/ssd1307fb.c
Remove or comment out all lines related to reset, or just try to use this as long as it exists: http://w.igh.fi/ssd1307fb.c

Create following Makefile to same directory with the source code file and run make as root (yes, for some funny reasons even sudo does not work):

Code: Select all

# Makefile 
obj-m+=ssd1307fb.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean

modules_install: all
	$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
	$(DEPMOD)   
If all goes well copy the new ssd1307fb.ko to overwrite current module:
cp ssd1307fb.ko /lib/modules/$(uname -r)/kernel/drivers/video/fbdev/ssd1307fb.ko

Enable the overlay with

Code: Select all

dtoverlay oled
This should load the new ssd1307fb driver and result the following in dmesg log:

Code: Select all

Feb  4 18:42:50 raspberrypi kernel: [   73.626023] ssd1307fb: loading out-of-tree module taints kernel.
Feb  4 18:42:50 raspberrypi kernel: [   73.635531] ssd1307fb 1-003c: fb1: Solomon SSD1307 framebuffer device registered, using 1024 bytes of video memory
And /dev/fb1 should appear on devices.

I might have missed something I did, but this should highlight the important bits.

Edit: Fixed a typo.
Last edited by ighea on Mon Mar 26, 2018 12:54 pm, edited 1 time in total.

fraz
Posts: 3
Joined: Mon Mar 26, 2018 11:53 am

Re: Help writing an overlay (dts / device tree) for an ssd1307

Mon Mar 26, 2018 12:16 pm

Thanks for posting your steps @ighea!
I have a SSD1306 128x64 monochrome OLED from ebay too.

I was getting s warning:
Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property
while doing
"dtc [email protected] -I dts -O dtb -o oled.dtbo oled.dts && mv oled.dtbo /boot/overlays/"

It seems this is harmless according to viewtopic.php?t=140835:
The warning is just an annoying feature of the latest version of dtc. The usual rule for DTs is that nodes with @<n> at the end of their name also include a matching "reg = <n>" property within the node. Fragments of overlays don't obey this rule. [ There is an ongoing behind-the-scenes debate about making support for overlays part of the official dtc source tree, rather than a set of patches maintained by others. I hope the resolution of that will see and end to such niggles. ]
Also, a minor typo:
The command to enable overlays is

Code: Select all

dtoverlay oled
and to test it: "dd if=/dev/urandom of=/dev/fb1" prints snow on the oled. Hooray!

Now to see it is faster than the adafruit python library.... I'm trying to display animated radar images without using 50-90% CPU like the python library does.

fraz
Posts: 3
Joined: Mon Mar 26, 2018 11:53 am

Re: Help writing an overlay (dts / device tree) for an ssd1307

Mon Mar 26, 2018 1:26 pm

And I can confirm this is woeful.

I get about 1 frame per second using mplayer:

Code: Select all

mplayer -vo fbdev2:/dev/fb1 -x 128 -y 64 -bpp 1 -fs -zoom ../radar.gif

Using mp4, or GIF. Even using 1 bit 128x64 source material (the radar images I've processed to display:
https://imgur.com/KH5Y2G8 - radar MP4
https://imgur.com/E8LQ1OM - radar GIF

Plus the display is kind of sliced up in vertical bands that are out of place. I used your supplied file with the reset lines removed. I suspect it needs some work to fix the display corruption, but I think it's too slow for me to get anywhere with.

And here's here's a tiny video to show you how the output looks:
https://imgur.com/QZnF1p1

back to python libraries I think!

fraz
Posts: 3
Joined: Mon Mar 26, 2018 11:53 am

Re: Help writing an overlay (dts / device tree) for an ssd1307

Mon Mar 26, 2018 11:24 pm

One more post in case it helps the next person. The vertical garbled bands might be a clock issue?

https://www.freetronics.com.au/pages/ol ... spberry-pi
Troubleshooting

If the OLED128 display is appearing garbled or not reliably updating, you may need to lower the SPI clock speed (that controls the rate that data is sent to the display.) This can particularly be the case if you are using long (>10cm) cables from the Pi to the OLED128.

You can do this by passing an additional argument "speed" to the fbtft_device module. Instead of:

fbtft_device name=freetronicsoled128

Try:

fbtft_device name=freetronicsoled128 speed=16000000

The default speed is 20MHz (20000000), try values lower than this and see if the screen starts updating reliably.

To make this change permanent, you can add the equivalent arguments to the line in the /etc/modules file on the Pi:

fbtft_device name=freetronicsoled128 speed=16000000
Maybe one day I'll look at the ssd1307fb code and see if I can pass options for the clock speed.

BeauSlim
Posts: 3
Joined: Mon Jul 31, 2017 10:02 am

Re: Help writing an overlay (dts / device tree) for an ssd1307

Wed Jul 18, 2018 2:43 am

I tried this a while back with my Adafruit OLED Bonnet but I think the "reset" issue got in the way. ighea, thank you so much for sorting this all out! It works quite well now, at least for text consoles.

The latest kernel code removes the reset requirement, so there's no need to comment stuff out and worry about problems.

For the Adafruit OLED Bonnet, I needed to add solomon,com-invdir; to the dts because the screen was backwards.

Other than that, the instructions above worked like a charm.

I then simply added fbcon=map:1 to /boot/cmdline.txt for a text console on the OLED. A really tiny console font like that tom-thumb one can get you a 10x32 terminal. Enough to edit /etc/fstab or install packages with apt.

I don't think there's anything to change the data rate to the screen other than the dtparam=i2c_baudrate=1000000 parameter in /boot/config.txt. Maybe try 4000000 on a Pi3. Most of the information out there is for SPI, and I don't think it applies here.

Return to “Advanced users”

Who is online

Users browsing this forum: ejolson and 17 guests