Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ssd1306 improvements #3411

Open
wants to merge 3 commits into
base: master
from

Conversation

@zgyarmati
Copy link

zgyarmati commented Nov 3, 2017

This patchset improves the support for the SSD1306 displays: the previous version used I2C ops available only on ESP8266, and as some of the I2C display modules have reset pin (but apparently not all of them), we also add optional support for it here. Finally now there is a test/demo script with some comments about wiring to show example about the usage of the driver.

Copy link
Contributor

SpotlightKid left a comment

self.width = width
self.height = height
self.external_vcc = external_vcc
self.res = res
if(res):

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Parentheses are not necessary here and there should be a space between if and res.
This also breaks if a (theoretically valid) pin number 0 (zero) is passed. Better:

if res is not None:
@@ -49,6 +53,14 @@ def __init__(self, width, height, external_vcc):
self.init_display()

def init_display(self):
if(self.res):

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Same applies as above. Better:

if self.res is not None:
time.sleep_ms(1)
self.res(0)
time.sleep_ms(10)
self.res(1)

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

It might be worth putting this block into its own method, e.g. named pulse_reset.

if self.res is not None:
    self.pulse_reset()
@@ -49,6 +53,14 @@ def __init__(self, width, height, external_vcc):
self.init_display()

def init_display(self):
if(self.res):
# not all of the modules have reset pin broke out

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Better:

# Some SDD1306 modules do not provide a reset on their pin header

This comment has been minimized.

Copy link
@mcauser

mcauser Jan 19, 2018

Contributor

"Some SDD1306 SSD1306..."

@@ -105,11 +117,11 @@ def show(self):


class SSD1306_I2C(SSD1306):
def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):
def __init__(self, width, height, i2c, addr=0x3c, res=None, external_vcc=False):

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Inconsistent order of arguments between here and base class. res=None should be at the end of the parameter list.

if rtc:
dt = rtc.datetime()
d = '%4d-%02d-%02d' % (dt[0], dt[1], dt[2])
t = '%2d:%02d:%02d.%01d' % (dt[4], dt[5], dt[6], dt[7] // 100000)

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Maybe use the new-style string formatting?

d = '{:4d}-{:02d}-{:02d}'.format(*dt)
t = '{:2d}:{:02d}:{:02d}.{:01d}'.format(dt[4], dt[5], dt[6], dt[7] // 100000)

Not sure, which one I prefer...

d = '%4d-%02d-%02d' % (dt[0], dt[1], dt[2])
t = '%2d:%02d:%02d.%01d' % (dt[4], dt[5], dt[6], dt[7] // 100000)
display.text(d,20,32)
display.text(t,20,40)

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Put space after comma.

from ssd1306 import SSD1306_I2C
res = machine.Pin('PB4')
bus = machine.I2C(1)
d = SSD1306_I2C(width,height,bus,0x3C,res)

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Put space after comma.

D1 --> PA7 SPI MOSI
GND --> GND
VCC --> 5V
"""

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Shouldn't we better give the wiring for the Pyboard V1.1 here?

Also, some formatting improvements:

def test_spi():
    """Test SSD1306 module attached via SPI.

    Wiring for Pyboard, SPI bus #1:

    | SDD1306 | Pyboard | Function     |
    | ------- | ------- | ------------ |
    | DC      | ??      | data/command | 
    ....
D1 --> PB7 (I2C SDA)
GND --> GND
VCC --> 5V
"""

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Nov 29, 2017

Contributor

Same as above.

@zgyarmati

This comment has been minimized.

Copy link
Author

zgyarmati commented Dec 3, 2017

Thx for the detailed review! Fixes will follow.
Unfortunately i don't own a Pyboard, so i would need someone to hook it up and confirming the setup before adding the Pyboard wiring.

@SpotlightKid

This comment has been minimized.

Copy link
Contributor

SpotlightKid commented Dec 3, 2017

I'll try to do that later tonight.

@SpotlightKid

This comment has been minimized.

Copy link
Contributor

SpotlightKid commented Dec 4, 2017

I'll try to do that later tonight.

I'm sorry, but it seems that my only ssd1306 module with an SPI interface is broken, so I can't test the test_ssd1306.py module properly. I tested it successfully with an ssd1306 module with an I2c only interface (4 pins), though.

Since the mapping of Pyboard pin names to MCU pin names is well-known, we can specify the wiring for the Pyboard with confidence nevertheless. I propose these docstrings for the test_spi and test_i2c functions. I've put the table rows in the order of the pins as they appear on the module header, from left to right, looking at the front of the module. Feel free to adapt the pins used for Reset, DC and CS:

(ReST table formatting done with https://ozh.github.io/ascii-tables/)

def test_spi():
    """Test SDD1306 display attached via SPI.

    Wiring for STM32F4DISCOVERY, SPI bus #1 (MCU pin names in parentheses):

     ========= ========== ======================
      SDD1306   Pyboard            Note
     ========= ========== ======================
      GND       GND
      VCC       3V3        5V can be used too
      D0        X6 (PA5)   SPI SCK
      D1        X8 (PA7)   SPI MOSI
      RES       X3 (PA2)   Reset
      DC        X4 (PA3)   Data / Command
      CS        X5 (PA4)   SPI SS / Chip select
     ========= ========== ======================

    """
def test_i2c():
    """Test SDD1306 display attached via I2C.

    Wiring for Pyboard V1.1, I2C bus #1 (MCU pin names in parentheses):

     ========= =========== =========================================
      SSD1306    Pyboard                     Note
     ========= =========== =========================================
      GND       GND
      VCC       3V3         5V can be used too
      D0        X9 (PB6)    I2C SCL (note 1)
      D1        X10 (PB7)   I2C SDA (note 1)
      RES       X11 (PB8)   Reset (optional)
      DC        GND         addr: 0x3C, if set to VCC, addr is 0x3D
      CS        GND         Unused on most displays
     ========= =========== =========================================

    For SSD1306 modules with I2C interface only:

     ========= =========== ====================
      SSD1306    Pyboard           Note
     ========= =========== ====================
      GND       GND
      VDD       3V3         5V can be used too
      SCK       X9 (PB6)    I2C SCL (note 1)
      SDA       X10 (PB7)   I2C SDA (note 1)
     ========= =========== ====================

    note 1) Add a 4.7k - 10k pull-up resistor between pin and VCC.

    """"
display.vline(14, 13, 2, 0)
display.text('MicroPython',20,0)

display.hline(0,18,128,1)

This comment has been minimized.

Copy link
@SpotlightKid

SpotlightKid Dec 4, 2017

Contributor

There seems to be an off-by-one error here. I think the coordinates are inclusive, i.e. it should be display.hline(0, 18, 127, 1) or display.hline(0,18, width - 1,1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.