OLED Displays SSD1306

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
User avatar
kfricke
Posts: 310
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: OLED Displays SSD1306

Postby kfricke » Tue Dec 16, 2014 2:36 pm

Following the initial trial and error with the source code provided in the Github repository above i did some tweaks to the code which i of course will commit back to a fork on Github.

What i would like to mention and ask before doing this is that i also did start to port more basic drawing operations to uPy for use on this device (lines, rectangles and the old-school 5x7 pixel font in different scales).
These drawing primitives are operating on a 1-bit frame-buffer (the only hint to the used monochrome display) which by itself is hardware independent. Based on this it possibly could receive some performance boost by "hand-optimizing" it or by using some code-emitter decorators.
The code works but has not been tested that extensively. Status is something about "alpha, but works as intended". Some open ends are still present. E.g. i would like it to respect the frame-buffer boundaries. It currently still draws characters, which "hang out off the display on side" over into the opposite side. In general there are still some quirks i would like to be hunted down, before considering it really usable.

I did base my implementation on the algorithms found in the Adafruit GFX library for Arduino, so i should at least check their licenses before we do commit this back to Github under the MIT license.

Should we pull such an module out of this context or is there no other need for this?

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: OLED Displays SSD1306

Postby mschulz » Mon Oct 19, 2015 3:57 pm

Hello,
I want to use the SSD1306 with I2C, too.

But it do not run.

I connectet SDA to Y10, and SCL to Y9, VIN to 5V and GND to GND. so far ok?

than I kopied the main and the ssd1306 file from GitHub, and uncommand the line for I2C in the main file. OK?

Code: Select all

import pyb
from ssd1306 import SSD1306

# SPI
#display = SSD1306(pinout={'dc': 'Y3',
#                          'res': 'Y4'},
#                  height=64,
#                  external_vcc=False)

# I2C connected to Y9, Y10 (I2C bus 2)
display = SSD1306(pinout={'sda': 'Y10',
                           'scl': 'Y9'},
                   height=64,
                   external_vcc=False)

led_red = pyb.LED(1)
led_red.off()
....


But now I get an error

Code: Select all

PYB: sync filesystems
PYB: soft reboot
Unexpected error: bytearray index out of range
Micro Python v1.3.9-59-g99bcaa2 on 2015-02-11; PYBv1.0 with STM32F405RG



Thank you for all ideas!

Online
User avatar
dhylands
Posts: 2256
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: OLED Displays SSD1306

Postby dhylands » Mon Oct 19, 2015 4:03 pm

Since you didn't get a traceback (which seems peculiar), I'd look for try/catch blocks.

I generally add print statements to the code to try and narrow down where the error is coming from.

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: OLED Displays SSD1306

Postby mschulz » Mon Oct 19, 2015 4:05 pm

Thank you, yes, this was the first problem, you are so fast :-)

mschulz
Posts: 35
Joined: Fri Apr 17, 2015 11:26 am
Location: Germany

Re: OLED Displays SSD1306

Postby mschulz » Tue Oct 20, 2015 9:01 am

Hello,

this runs now,
But how I can wirte a Text message to the display.

I tried

Code: Select all

display.write_command('123')


But this is unexpected indent

Can I get an example?

Thank you

User avatar
kfricke
Posts: 310
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: OLED Displays SSD1306

Postby kfricke » Tue Oct 20, 2015 3:03 pm

The display library from the Github repository does not support text display. But there is a fork with added text rendering.

The method you are calling is used for communicating on the SPI or I2C bus. Do not use it externally, it should be kept private to the module.
As for examples... i have none at hand. Simply check the code for the method called "draw_text(x, y, string, size=1, space=1)". You should also keep that font module (font.py) around!

Additionally this library might soon need an update for all MicroPython platforms. It does rely on the "pyb" module which is only available on the official pyboard!

domgiles
Posts: 10
Joined: Fri Aug 08, 2014 2:54 pm

Re: OLED Displays SSD1306

Postby domgiles » Sun Apr 03, 2016 8:00 pm

Coming back to the display...

I've tried to use the latest code... https://github.com/khenderick/micropython-drivers

I'm using a stock AdaFruit 64X128 display... https://www.adafruit.com/product/938

When I attempt to use the example, I get. I know the display works (tested it under with Arduino Uno)

Code: Select all

PYB: sync filesystems
PYB: soft reboot
Unexpected error: 116
Traceback (most recent call last):
  File "main.py", line 94, in <module>
  File "main.py", line 94, in <module>
  File "ssd1306.py", line 183, in poweroff
  File "ssd1306.py", line 116, in write_command
OSError: 116
MicroPython v1.5.1-158-g0a4eb4d on 2015-12-20; PYBv1.0 with STM32F405RG
Type "help()" for more information.


Any ideas where I can go next to try and find out the issue?

Thanks

Dom

User avatar
saulo
Posts: 12
Joined: Thu May 26, 2016 9:05 am
Location: Brasil

Re: OLED Displays SSD1306

Postby saulo » Mon Jul 18, 2016 12:15 am

domgiles wrote:Coming back to the display...

I've tried to use the latest code... https://github.com/khenderick/micropython-drivers

I'm using a stock AdaFruit 64X128 display... https://www.adafruit.com/product/938

When I attempt to use the example, I get. I know the display works (tested it under with Arduino Uno)

Code: Select all

PYB: sync filesystems
PYB: soft reboot
Unexpected error: 116
Traceback (most recent call last):
  File "main.py", line 94, in <module>
  File "main.py", line 94, in <module>
  File "ssd1306.py", line 183, in poweroff
  File "ssd1306.py", line 116, in write_command
OSError: 116
MicroPython v1.5.1-158-g0a4eb4d on 2015-12-20; PYBv1.0 with STM32F405RG
Type "help()" for more information.


Any ideas where I can go next to try and find out the issue?

Thanks

Dom


I have similar problem, the OSError: 116 seems to be related to ACK byte that some displays don't handle.. for arduino i had to use the U8G_I2C_OPT_NO_ACK) option on u8glib to work. Seems to be another controller than SSD1306, like the SH1106. I don't figure out how to solve it yet...

User avatar
kamikaze
Posts: 127
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: OLED Displays SSD1306

Postby kamikaze » Tue Dec 06, 2016 2:34 am

Code: Select all

self.spi.init(baudrate=self.rate, polarity=0, phase=0)


Why there is an init() call on each write_cmd() and write_data() call?

User avatar
deshipu
Posts: 928
Joined: Thu May 28, 2015 5:54 pm

Re: OLED Displays SSD1306

Postby deshipu » Tue Dec 06, 2016 11:35 am

Because you might have more than one device on the SPI bus, and those other devices might be using different mode/speed. So you never know if the mode/speed have been changed. So you have to set them to the correct values each time. That was the reasoning when I was asked to add it, anyways.


Return to “Hardware Projects”

Who is online

Users browsing this forum: No registered users and 1 guest