Skip to content

Commit 5bdf2a0

Browse files
committed
Optimise for MPY v1.14
1 parent 015ac0e commit 5bdf2a0

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ For example, the [Grove - OLED Display 1.12"](http://wiki.seeed.cc/Grove-OLED_Di
1010

1111
Copy the file to your device, using ampy, webrepl or compiling and deploying. eg.
1212

13-
```
13+
```bash
1414
$ ampy put ssd1327.py
1515
```
1616

1717
**Hello World**
1818

1919
```python
2020
import ssd1327
21-
from machine import I2C, Pin
21+
from machine import SoftI2C, Pin
22+
23+
i2c = SoftI2C(sda=Pin(21), scl=Pin(22)) # TinyPICO
24+
# i2c = SoftI2C(sda=Pin(0), scl=Pin(1)) # Raspberry Pi Pico
25+
# i2c = SoftI2C(sda=Pin(4), scl=Pin(5)) # WeMos D1 Mini
2226

23-
i2c = I2C(sda=Pin(4), scl=Pin(5))
24-
# display = ssd1327.SSD1327_I2C(96, 96, i2c, 60)
2527
display = ssd1327.SEEED_OLED_96X96(i2c)
28+
# display = ssd1327.SSD1327_I2C(128, 128, i2c) # WaveShare, Zio Qwiic
29+
30+
display.text('Hello World', 0, 0, 255)
31+
display.show()
2632

33+
display.fill(0)
2734
for y in range(0,12):
2835
display.text('Hello World', 0, y * 8, 15 - y)
2936
display.show()
@@ -33,12 +40,29 @@ See [ssd1327_examples.py](ssd1327_examples.py) for more.
3340

3441
## Parts
3542

36-
* [WeMos D1 Mini](https://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html) $4.00 USD
37-
* [Grove OLED Display 1.12"](https://www.seeedstudio.com/Grove-OLED-Display-1.12%22-p-824.html) $14.90 USD
38-
* [Grove Male Jumper Cable](https://www.seeedstudio.com/Grove-4-pin-Male-Jumper-to-Grove-4-pin-Conversion-Cable-%285-PCs-per-Pack%29-p-1565.html) $2.90 USD
43+
* [Grove OLED Display 1.12"](https://www.seeedstudio.com/Grove-OLED-Display-1-12.html) $14.90 USD
44+
* [Zio Qwiic OLED Display (1.5inch, 128x128)](https://www.sparkfun.com/products/15890) $19.95 USD
45+
* [TinyPICO](https://www.tinypico.com/) $20.00 USD
46+
* [Raspberry Pi Pico](https://core-electronics.com.au/raspberry-pi-pico.html) $5.75 AUD
47+
* [WeMos D1 Mini](https://www.aliexpress.com/item/32529101036.html) $3.50 USD
48+
* [Grove Male Jumper Cable](https://www.seeedstudio.com/Grove-4-pin-Male-Jumper-to-Grove-4-pin-Conversion-Cable-5-PCs-per-Pack.html) $2.90 USD
3949

4050
## Connections
4151

52+
TinyPICO ESP32 | Grove OLED
53+
-------------- | ----------
54+
GPIO22 (SCL) | SCL
55+
GPIO21 (SDA) | SDA
56+
3V3 | VCC
57+
GND | GND
58+
59+
Raspberry Pi Pico | Grove OLED
60+
----------------- | ----------
61+
GPIO1 (I2C0_SCL) | SCL
62+
GPIO0 (I2C0_SDA) | SDA
63+
3V3 | VCC
64+
GND | GND
65+
4266
WeMos D1 Mini | Grove OLED
4367
------------- | ----------
4468
D1 (GPIO5) | SCL
@@ -48,8 +72,10 @@ G | GND
4872

4973
## Links
5074

51-
* [WeMos D1 Mini](https://wiki.wemos.cc/products:d1:d1_mini)
75+
* [TinyPICO Getting Started](https://www.tinypico.com/gettingstarted)
76+
* [WeMos D1 Mini](https://www.wemos.cc/en/latest/d1/d1_mini.html)
5277
* [micropython.org](http://micropython.org)
78+
* [micropython docs](http://docs.micropython.org/en/latest/)
5379
* [Adafruit Ampy](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy)
5480

5581
## License

docs/demo.jpg

68.7 KB
Loading

ssd1327.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
from micropython import const
2828
import time
2929
import framebuf
30-
from uos import uname
31-
3230

3331
# commands
3432
SET_COL_ADDR = const(0x15)
@@ -153,25 +151,17 @@ class SSD1327_I2C(SSD1327):
153151
def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):
154152
self.i2c = i2c
155153
self.addr = addr
156-
self.temp = bytearray(2)
154+
self.cmd_arr = bytearray([REG_CMD, 0]) # Co=1, D/C#=0
155+
self.data_list = [bytes((REG_DATA,)), None]
157156
super().__init__(width, height, external_vcc)
158157

159158
def write_cmd(self, cmd):
160-
self.temp[0] = REG_CMD # Co=1, D/C#=0
161-
self.temp[1] = cmd
162-
self.i2c.writeto(self.addr, self.temp)
159+
self.cmd_arr[1] = cmd
160+
self.i2c.writeto(self.addr, self.cmd_arr)
163161

164162
def write_data(self, buf):
165-
self.temp[0] = self.addr << 1
166-
self.temp[1] = REG_DATA # Co=0, D/C#=1
167-
# check if board is Pi Pico as it doesn't support start, write and stop operations.
168-
if uname()[0] == 'rp2':
169-
self.i2c.writeto(self.addr, b'\x40' + buf)
170-
else:
171-
self.i2c.start()
172-
self.i2c.write(self.temp)
173-
self.i2c.write(buf)
174-
self.i2c.stop()
163+
self.data_list[1] = buf
164+
self.i2c.writevto(self.addr, self.data_list)
175165

176166

177167
class SEEED_OLED_96X96(SSD1327_I2C):

ssd1327_examples.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
display.text('grey using',0,50,5)
4242
display.text('GS4_HMSB',0,60,15)
4343
display.text('MicroPython',0,70,5)
44-
display.text('v1.9 ESP8266',0,80,15)
44+
display.text('v1.14',0,80,15)
4545
display.show()
4646

4747

4848
# rotate 180 degrees
4949
display.rotate(True)
50+
display.show()
5051

5152
# rotate 0 degrees
5253
display.write_cmd(0xA2)
@@ -78,13 +79,14 @@
7879

7980
# rotate 0 degrees
8081
display.rotate(False)
81-
82+
display.show()
8283

8384
# scroll the framebuf down 16px
8485
display.fill(0)
8586
display.text('Hello World', 0, 0, 15)
8687
display.show()
8788
display.scroll(0,16)
89+
display.show()
8890

8991

9092
# corner pixels
@@ -97,6 +99,7 @@
9799

98100

99101
# random pixels (slow)
102+
# note: urandom not available on rpi pico
100103
import uos
101104
for i in range(0,256):
102105
x = uos.urandom(1)[0] // 2

0 commit comments

Comments
 (0)