kopia lustrzana https://github.com/peterhinch/micropython-samples
ssd1306_test.py now demos simple graphics. Now uses soft I2C and SPI.
rodzic
8a05088980
commit
74e786740b
|
@ -31,16 +31,20 @@ In addition several font files are provided as samples.
|
||||||
|
|
||||||
# Getting started
|
# Getting started
|
||||||
|
|
||||||
Edit ``ssd1306_test.py`` to match your hardware, namely whether it uses SPI or
|
The file ``ssd1306_test.py`` may need editing to match your hardware notably
|
||||||
I2C and the value of HEIGHT. The file contains details of how to wire the device
|
the values of WIDTH and HEIGHT which are set to 128x64 (w*h) pixels. Wiring
|
||||||
to a Pyboard. It is untested on other platforms, but I'd expect it to be
|
details are included in code comments but may be changed if required as soft
|
||||||
portable to any device supporting the official driver. If in doubt, install and
|
I2C and SPI interfaces are specified.
|
||||||
test this first.
|
|
||||||
|
Its principal testing was performed on Pyboards but I'd expect it to be
|
||||||
|
portable to any device supporting the official driver and the `machine` module.
|
||||||
|
|
||||||
Copy files 1-3 and ``freesans20.py`` to the target and issue
|
Copy files 1-3 and ``freesans20.py`` to the target and issue
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import ssd1306_test
|
import ssd1306_test
|
||||||
|
ssd1306_test.test() # If it uses an I2C connection
|
||||||
|
ssd1306_test.test(True) # If it uses SPI
|
||||||
```
|
```
|
||||||
|
|
||||||
# Principle of Operation
|
# Principle of Operation
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# ssd1306_test.py Demo pogram for rendering arbitrary fonts to an SSD1306 OLED display
|
# ssd1306_test.py Demo pogram for rendering arbitrary fonts to an SSD1306 OLED display.
|
||||||
|
|
||||||
# The MIT License (MIT)
|
# The MIT License (MIT)
|
||||||
#
|
#
|
||||||
|
@ -26,7 +26,9 @@
|
||||||
# https://learn.adafruit.com/monochrome-oled-breakouts/wiring-128x32-spi-oled-display
|
# https://learn.adafruit.com/monochrome-oled-breakouts/wiring-128x32-spi-oled-display
|
||||||
# https://www.proto-pic.co.uk/monochrome-128x32-oled-graphic-display.html
|
# https://www.proto-pic.co.uk/monochrome-128x32-oled-graphic-display.html
|
||||||
|
|
||||||
# V0.2 Dec 17th 2016 Now supports updated framebuf module.
|
# V0.22 Dec 23rd 2017 machine.SPI now only seems to work soft SPI and I2C
|
||||||
|
# implmentations
|
||||||
|
# Now provides demo of simple graphics
|
||||||
|
|
||||||
import machine
|
import machine
|
||||||
from ssd1306 import SSD1306_SPI, SSD1306_I2C
|
from ssd1306 import SSD1306_SPI, SSD1306_I2C
|
||||||
|
@ -38,40 +40,52 @@ import freesans20
|
||||||
#import inconsolata16
|
#import inconsolata16
|
||||||
|
|
||||||
WIDTH = const(128)
|
WIDTH = const(128)
|
||||||
SPI = False
|
HEIGHT = const(64)
|
||||||
|
|
||||||
if SPI:
|
def test(use_spi=False):
|
||||||
# Pyb SSD
|
if use_spi:
|
||||||
# 3v3 Vin
|
# Pyb SSD
|
||||||
# Gnd Gnd
|
# 3v3 Vin
|
||||||
# X1 DC
|
# Gnd Gnd
|
||||||
# X2 CS
|
# X1 DC
|
||||||
# X3 Rst
|
# X2 CS
|
||||||
# X6 CLK
|
# X3 Rst
|
||||||
# X8 DATA
|
# X6 CLK
|
||||||
HEIGHT = 32
|
# X8 DATA
|
||||||
pdc = machine.Pin('X1', machine.Pin.OUT_PP)
|
pdc = machine.Pin('X1', machine.Pin.OUT_PP)
|
||||||
pcs = machine.Pin('X2', machine.Pin.OUT_PP)
|
pcs = machine.Pin('X2', machine.Pin.OUT_PP)
|
||||||
prst = machine.Pin('X3', machine.Pin.OUT_PP)
|
prst = machine.Pin('X3', machine.Pin.OUT_PP)
|
||||||
spi = machine.SPI(1)
|
# spi = machine.SPI('Y')
|
||||||
ssd = SSD1306_SPI(WIDTH, HEIGHT, spi, pdc, prst, pcs)
|
spi = machine.SPI(sck=machine.Pin('X6'), mosi=machine.Pin('X8'), miso=machine.Pin('X7'))
|
||||||
else: # I2C
|
ssd = SSD1306_SPI(WIDTH, HEIGHT, spi, pdc, prst, pcs)
|
||||||
# Pyb SSD
|
else: # I2C
|
||||||
# 3v3 Vin
|
# Pyb SSD
|
||||||
# Gnd Gnd
|
# 3v3 Vin
|
||||||
# Y9 CLK
|
# Gnd Gnd
|
||||||
# Y10 DATA
|
# Y9 CLK
|
||||||
HEIGHT = 64
|
# Y10 DATA
|
||||||
pscl = machine.Pin('Y9', machine.Pin.OUT_PP)
|
pscl = machine.Pin('Y9', machine.Pin.OUT_PP)
|
||||||
psda = machine.Pin('Y10', machine.Pin.OUT_PP)
|
psda = machine.Pin('Y10', machine.Pin.OUT_PP)
|
||||||
i2c = machine.I2C(scl=pscl, sda=psda)
|
i2c = machine.I2C(scl=pscl, sda=psda)
|
||||||
ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)
|
# i2c = machine.I2C(2)
|
||||||
|
ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c, 0x3c)
|
||||||
|
|
||||||
#wri = Writer(ssd, freeserif19)
|
rhs = WIDTH -1
|
||||||
wri2 = Writer(ssd, freesans20, verbose=False)
|
ssd.line(rhs - 20, 0, rhs, 20, 1)
|
||||||
Writer.set_clip(True, True)
|
square_side = 10
|
||||||
#Writer.set_textpos(20, 20)
|
ssd.fill_rect(rhs - square_side, 0, square_side, square_side, 1)
|
||||||
wri2.printstring('Tuesday\n')
|
|
||||||
wri2.printstring('8 Nov 2016\n')
|
#wri = Writer(ssd, freeserif19)
|
||||||
wri2.printstring('10.30am')
|
wri2 = Writer(ssd, freesans20, verbose=False)
|
||||||
ssd.show()
|
Writer.set_clip(True, True)
|
||||||
|
Writer.set_textpos(0, 0)
|
||||||
|
wri2.printstring('Tuesday\n')
|
||||||
|
wri2.printstring('8 Nov 2016\n')
|
||||||
|
wri2.printstring('10.30am')
|
||||||
|
ssd.show()
|
||||||
|
|
||||||
|
print('Test assumes a 128*64 (w*h) display. Edit WIDTH and HEIGHT for others.')
|
||||||
|
print('Device pinouts are commented in the code.')
|
||||||
|
print('Issue:')
|
||||||
|
print('ssd1306_test.test() for an I2C connected device.')
|
||||||
|
print('ssd1306_test.test(True) for an SPI connected device.')
|
||||||
|
|
Ładowanie…
Reference in New Issue