BPI-R2/R3 and SSD1306 oled screen

I would like to share my experiences with SSD1306 oled screen attached to BPI-R2. I ordered from ebay :


Since I2C_SDA0 and I2C SCL0 are used for RTC shield I decided using I2C_SDA1 and I2C_SCL1. They are on PIN 27 and 28 :


After hooked up VCC with 5V, GND, SCL and SDA, started BPI-R2 and added device : echo ssd1306 0x3C > /sys/class/i2c-adapter/i2c-2/new_device

You might need kernel i2c-dev module(modprobe i2c-dev)!

With pip3 installed following python libraries :


Library Pillow is a basis for displaying something, but I was unable to download it via pip3. Therefore got it from git, and installed it :

python3.7 setup.py install

I got another part from git, this was Adafruit_Python_SSD1306.

I’ve found in the examples directory a script called stats.py and modified it for my taste. What is important, and has to be changed for i2c-2 bus is following :

disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_bus=2)

Now it displays time, uptime, cpu temp and load, memory usage, disk space. It’s not perfect, and would like to develop.


Can you display text and how much (can you show screen)? How do you access the display from cli? Is there any larger display (0.96inch is not big) which can be used in similar way?

From cli you can not access directly to the screen, leastways I don’t know how! (I’m not a python expert) As I wrote I’ve modified stats.py script, and took to rc-local script. You should open stats.py and will see how simple is it! With embedded bash commands it’s easy to show important infos. All i2c capable screen should work, maybe you need another python libraries. ( this one works with 128x32 or 128x64 resolutions )

can you point to git-repo where you get the stats.py? maybe it’s possible to show interface-status with ip (wan)

Here :

From line 110 you can modify as you wish! My suggestion is pick one “cmd =…” line, swap to your bash command, and pass corresponding “draw.text…” line!

But as I wrote before, I’ve been using 128x64 resolution, and i2c-2 bus! With 128x32 it can display less!

1 Like

Useful information! Thanks!

Some additional information (like installing necessary libs): https://www.raspberrypi-spy.co.uk/2018/04/i2c-oled-display-module-with-raspberry-pi/

I am trying the same thing and am having trouble figuring out where pin 1 is (sheepish grin)…

pin 1 is marked with an arrow (down left on looking on board with rj45 on bottom)

basicly my gpio - shematic (where pin 1 is top-left) is rotated 90 degrees right.

top-row begins with 5v (2),5v (4),gnd (6) (left to right)

Can’t find an arrow… Is pin 1 closest to the reset button? My vision sucks… Damn this small print… :frowning:

some basic ascii-art

  pwr rst               2 4...
   |     |             [:::::::::::...]
                       /1\ 3...


arrow is where the 1 stands here :slight_smile:

Thanks for helping a blind person! :stuck_out_tongue:

EDIT: Got it working for me, too! Thanks!

Great! Which ic2 bus are you using? What infos displays your screen?

VCC is on pin 1, GCC is on pin 9, SDA on pin 27 and SCL on pin 28. I’m customizing my display to show the statuses in stats.py using pure Python (no shell calls), plus icons on whether certain services are up…

I wrote the script, then the router rebooted during a file write and lost it. In the progress of rewriting the script… Can publish on GitHub when ready… Image

UPDATE: My code is available at my GitHub repository. Hope this helps somebody…

UPDATE 2: Updated code and picture used. No real documentation yet…


I’ve just downloaded! Great job, thanks for sharing!

UPDATE: I’ve added a README to the repo, primarily to add install directions to the repo. After all, what good is a repo if nobody knows how to install it? :sweat_smile: Also gonna see about making a Docker container for this repo, as adding compilation tools into an image probably isn’t the brightest of ideas…

Thanks some little notes:

  • typo in debian
  • why install libwebp-dev tcl8.6-dev tk8.6-dev python-tk ? Last3 imho are gui-libs,first is a -dev usally used for compiling own apps

Source: Pillow Installation Instructions

I just posted why I was told was needed to build the Python Pillow package. I’ll see if I can trim the package “requirements” down a bit later today…

does it need building (then i guess gcc/cpp ais also needed)? is there no binary package? building-tools on router is a huge security hole

Maybe this is the right way:

Most major Linux distributions, including Fedora, Debian/Ubuntu and ArchLinux also include Pillow in packages that previously contained PIL e.g. python-imaging


For python3 this needs to be installed. https://packages.debian.org/buster/python3-pil

Tested with basic-script from https://zetcode.com/python/pillow/

I guess Adafruit_GPIO is also not needed as it is only imported for spi as far as i see

in your call to getIP-Address you use “wan” instead of the variable wan_interface. so in case wan_interface is set to anything else, either an exception is thrown (if interface does not exist like on my laptop) or the wrong ip is printed (if there is any)


i change the script locally a bit, to generate text (for printing it out) instead of printing to display…so i can catch the data, print it to cli for external debugging…if display is enabled the image is generated (not finished yet)

forked your repo and change these 2 little things: https://github.com/frank-w/bpi-r2-ssd1306-display

have also uploaded reworked version, works without display…still waiting for my display to arrive

Wow… These changes are quite interesting! Care to create a Pull request?