Skip to content

Commit fec22a4

Browse files
Refactor such that all sfe OLED python libs can be maintained in this single repo
1 parent 7ec6d51 commit fec22a4

18 files changed

+575
-417
lines changed

examples/ex1_splash_screen.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python
2+
#-----------------------------------------------------------------------------
3+
# ex1_splash_screen.py
4+
#
5+
# Simple Example for an OLED Display
6+
#------------------------------------------------------------------------
7+
#
8+
# Written by SparkFun Electronics, May 2021
9+
#
10+
# This python library supports the SparkFun Electroncis qwiic
11+
# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
12+
# board computers.
13+
#
14+
# More information on qwiic is at https:# www.sparkfun.com/qwiic
15+
#
16+
# Do you like this library? Help support SparkFun. Buy a board!
17+
#
18+
#==================================================================================
19+
# Copyright (c) 2021 SparkFun Electronics
20+
#
21+
# Permission is hereby granted, free of charge, to any person obtaining a copy
22+
# of this software and associated documentation files (the "Software"), to deal
23+
# in the Software without restriction, including without limitation the rights
24+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
# copies of the Software, and to permit persons to whom the Software is
26+
# furnished to do so, subject to the following conditions:
27+
#
28+
# The above copyright notice and this permission notice shall be included in all
29+
# copies or substantial portions of the Software.
30+
#
31+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37+
# SOFTWARE.
38+
#==================================================================================
39+
# Example 1 - Simple example to display the splash screen bitmap
40+
#
41+
42+
import qwiic_oled
43+
import time
44+
import sys
45+
46+
# --------- SET YOUR OLED DISPLAY TYPE HERE ----------------
47+
# The library supports three different types of SparkFun boards. The demo uses the following
48+
# variables to determine which device is being used. Uncomment the device being used for this demo.
49+
50+
userOLED = qwiic_oled.QwiicMicroOled() # Micro OLED https://www.sparkfun.com/products/14532
51+
# userOLED = qwiic_oled.QwiicOledDisplay() # "Narrow" OLED https://www.sparkfun.com/products/24606
52+
# userOLED = qwiic_oled.QwiicLargeOled() # Qwiic OLED 1.3in https://www.sparkfun.com/products/23453
53+
54+
def runExample():
55+
# Before you can start using the OLED, call begin() to init
56+
# all of the pins and configure the OLED.
57+
58+
print("\nOLED Display - Splash screen example\n")
59+
myOLED = userOLED
60+
61+
if not myOLED.connected:
62+
print("The OLED Display isn't connected to the system. Please check your connection", \
63+
file=sys.stderr)
64+
return
65+
66+
myOLED.begin()
67+
68+
# clear(ALL) will clear out the OLED's graphic memory.
69+
myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
70+
71+
# To actually draw anything on the display, you must call the display() function.
72+
myOLED.display() # Display buffer contents
73+
time.sleep(3)
74+
75+
# clear(PAGE) will clear the Arduino's display buffer.
76+
myOLED.clear(myOLED.PAGE) # Clear the display's buffer
77+
78+
# Display buffer contents
79+
myOLED.display()
80+
time.sleep(3)
81+
82+
qwiic_oled.oled_logos.add_logo(myOLED._screenbuffer)
83+
84+
myOLED.display()
85+
86+
if __name__ == '__main__':
87+
try:
88+
runExample()
89+
except (KeyboardInterrupt, SystemExit) as exErr:
90+
print("\nEnding OLED bitmap Example")
91+
sys.exit(0)

examples/ex2_qwiic_oled_display.py renamed to examples/ex2_hello_world.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python
22
#-----------------------------------------------------------------------------
3-
# ex2_qwiic_oled_display.py
3+
# ex2_hello_world.py
44
#
5-
# Simple Example for the Qwiic OLED Display
5+
# "Hello World" Example for an OLED Display
66
#------------------------------------------------------------------------
77
#
88
# Written by SparkFun Electronics, May 2021
@@ -36,39 +36,42 @@
3636
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3737
# SOFTWARE.
3838
#==================================================================================
39-
# Example 2 - Simple example to display "hello world" on the Qwiic OLED Display board.
39+
# Example 2 - Simple example to display "hello world"
4040
#
4141

42-
import qwiic_oled_base
43-
import time
42+
import qwiic_oled
4443
import sys
44+
import time
4545

46-
def runExample():
46+
# --------- SET YOUR OLED DISPLAY TYPE HERE ----------------
47+
# The library supports three different types of SparkFun boards. The demo uses the following
48+
# variables to determine which device is being used. Uncomment the device being used for this demo.
4749

48-
# These three lines of code are all you need to initialize the
49-
# OLED and print the splash screen.
50+
userOLED = qwiic_oled.QwiicMicroOled() # Micro OLED https://www.sparkfun.com/products/14532
51+
# userOLED = qwiic_oled.QwiicOledDisplay() # "Narrow" OLED https://www.sparkfun.com/products/24606
52+
# userOLED = qwiic_oled.QwiicLargeOled() # Qwiic OLED 1.3in https://www.sparkfun.com/products/23453
5053

54+
def runExample():
5155
# Before you can start using the OLED, call begin() to init
5256
# all of the pins and configure the OLED.
5357

54-
55-
print("\nSparkFun OLED Display - Hello Example\n")
58+
print("\nOLED Display - Hello World Example\n")
5659

5760
# Create instance with parameters for Qwiic OLED Display
58-
myOLED = qwiic_oled_base.QwiicOledBase(0x3C, 128, 32)
61+
myOLED = userOLED
5962

6063
if not myOLED.connected:
61-
print("The Qwiic OLED Display isn't connected to the system. Please check your connection", \
64+
print("The OLED Display isn't connected to the system. Please check your connection", \
6265
file=sys.stderr)
6366
return
6467

6568
myOLED.begin()
6669

6770
# clear(ALL) will clear out the OLED's graphic memory.
6871
myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
69-
70-
# Display buffer contents
71-
myOLED.display()
72+
73+
# To actually draw anything on the display, you must call the display() function.
74+
myOLED.display() # Display buffer contents
7275
time.sleep(3)
7376

7477
# clear(PAGE) will clear the Arduino's display buffer.
@@ -83,7 +86,7 @@ def runExample():
8386
# Add text
8487
myOLED.print("Hello World")
8588

86-
# To actually draw anything on the display, you must call the display() function.
89+
# Display buffer contents
8790
myOLED.display()
8891

8992
if __name__ == '__main__':

examples/ex3_qwiic_micro_oled_demo.py renamed to examples/ex3_demo.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python
22
#-----------------------------------------------------------------------------
3-
# ex3_qwiic_micro_oled_demo.py
3+
# ex3_demo.py
44
#
5-
# Simple Example for the Qwiic Micro OLED Device
5+
# Demo Example for an OLED Display
66
#------------------------------------------------------------------------
77
#
88
# Written by SparkFun Electronics, May 2021
@@ -36,16 +36,23 @@
3636
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3737
# SOFTWARE.
3838
#==================================================================================
39-
# Example 3 - An example showing various features of the display driver on the Qwiic Micro OLED board.
39+
# Example 3 - An example showing various features of the display driver
4040
#
4141

42-
from __future__ import print_function, division
43-
import qwiic_oled_base
42+
import qwiic_oled
4443
import time
4544
import sys
4645
import math
4746
from random import randint
4847

48+
# --------- SET YOUR OLED DISPLAY TYPE HERE ----------------
49+
# The library supports three different types of SparkFun boards. The demo uses the following
50+
# variables to determine which device is being used. Uncomment the device being used for this demo.
51+
52+
userOLED = qwiic_oled.QwiicMicroOled() # Micro OLED https://www.sparkfun.com/products/14532
53+
# userOLED = qwiic_oled.QwiicOledDisplay() # "Narrow" OLED https://www.sparkfun.com/products/24606
54+
# userOLED = qwiic_oled.QwiicLargeOled() # Qwiic OLED 1.3in https://www.sparkfun.com/products/23453
55+
4956
#-------------------------------------------------------------------
5057
def pixelExample(myOLED):
5158

@@ -325,19 +332,14 @@ def textExamples(myOLED):
325332
#-------------------------------------------------------------------
326333

327334
def runExample():
328-
329-
# These three lines of code are all you need to initialize the
330-
# OLED and print the splash screen.
331-
332335
# Before you can start using the OLED, call begin() to init
333336
# all of the pins and configure the OLED.
334337

335-
336-
print("\nSparkFun Micro OLED Everything Example\n")
337-
myOLED = qwiic_oled_base.QwiicOledBase()
338+
print("\nOLED Display - Everything Example\n")
339+
myOLED = userOLED
338340

339341
if not myOLED.connected:
340-
print("The Qwiic Micro OLED device isn't connected to the system. Please check your connection", \
342+
print("The OLED Display isn't connected to the system. Please check your connection", \
341343
file=sys.stderr)
342344
return
343345

examples/ex4_cube.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/usr/bin/env python
2+
#-----------------------------------------------------------------------------
3+
# ex4_cube.py
4+
#
5+
# Cube Example for a Qwiic OLED Device
6+
#------------------------------------------------------------------------
7+
#
8+
# Written by SparkFun Electronics, May 2019
9+
#
10+
# This python library supports the SparkFun Electroncis qwiic
11+
# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
12+
# board computers.
13+
#
14+
# More information on qwiic is at https:# www.sparkfun.com/qwiic
15+
#
16+
# Do you like this library? Help support SparkFun. Buy a board!
17+
#==================================================================================
18+
# Copyright (c) 2019 SparkFun Electronics
19+
#
20+
# Permission is hereby granted, free of charge, to any person obtaining a copy
21+
# of this software and associated documentation files (the "Software"), to deal
22+
# in the Software without restriction, including without limitation the rights
23+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24+
# copies of the Software, and to permit persons to whom the Software is
25+
# furnished to do so, subject to the following conditions:
26+
#
27+
# The above copyright notice and this permission notice shall be included in all
28+
# copies or substantial portions of the Software.
29+
#
30+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
# SOFTWARE.
37+
#==================================================================================
38+
# Example - simple command to draw a cube the OLED.
39+
#
40+
41+
42+
import qwiic_oled
43+
import sys
44+
import time
45+
import math
46+
47+
# --------- SET YOUR OLED DISPLAY TYPE HERE ----------------
48+
# The library supports three different types of SparkFun boards. The demo uses the following
49+
# variables to determine which device is being used. Uncomment the device being used for this demo.
50+
51+
userOLED = qwiic_oled.QwiicMicroOled() # Micro OLED https://www.sparkfun.com/products/14532
52+
# userOLED = qwiic_oled.QwiicOledDisplay() # "Narrow" OLED https://www.sparkfun.com/products/24606
53+
# userOLED = qwiic_oled.QwiicLargeOled() # Qwiic OLED 1.3in https://www.sparkfun.com/products/23453
54+
55+
56+
d = 3
57+
px = [-d, d, d, -d, -d, d, d, -d ]
58+
py = [-d, -d, d, d, -d, -d, d, d ]
59+
pz = [-d, -d, -d, -d, d, d, d, d ]
60+
61+
p2x = [0,0,0,0,0,0,0,0]
62+
p2y = [0,0,0,0,0,0,0,0]
63+
64+
r = [0,0,0]
65+
66+
SHAPE_SIZE=600
67+
def drawCube(oled):
68+
69+
global p2x, p2y, r
70+
71+
72+
r[0]=r[0] + math.pi/180.0 # Add a degree
73+
r[1]=r[1] + math.pi/180.0 # Add a degree
74+
r[2]=r[2] + math.pi/180.0 # Add a degree
75+
if r[0] >= 360.0*math.pi/180.0:
76+
r[0] = 0
77+
if r[1] >= 360.0*math.pi/180.0:
78+
r[1] = 0
79+
if r[2] >= 360.0*math.pi/180.0:
80+
r[2] = 0
81+
82+
scrWidth = oled.get_lcd_width()
83+
scrHeight = oled.get_lcd_height()
84+
85+
for i in range(8):
86+
87+
px2 = px[i]
88+
py2 = math.cos(r[0])*py[i] - math.sin(r[0])*pz[i]
89+
pz2 = math.sin(r[0])*py[i] + math.cos(r[0])*pz[i]
90+
91+
px3 = math.cos(r[1])*px2 + math.sin(r[1])*pz2
92+
py3 = py2
93+
pz3 = -math.sin(r[1])*px2 + math.cos(r[1])*pz2
94+
95+
ax = math.cos(r[2])*px3 - math.sin(r[2])*py3
96+
ay = math.sin(r[2])*px3 + math.cos(r[2])*py3
97+
az = pz3-150
98+
99+
p2x[i] = scrWidth/2+ax*SHAPE_SIZE/az
100+
p2y[i] = scrHeight/2+ay*SHAPE_SIZE/az
101+
102+
oled.clear(oled.PAGE)
103+
104+
for i in range(3):
105+
106+
oled.line(p2x[i],p2y[i],p2x[i+1],p2y[i+1])
107+
oled.line(p2x[i+4],p2y[i+4],p2x[i+5],p2y[i+5])
108+
oled.line(p2x[i],p2y[i],p2x[i+4],p2y[i+4])
109+
110+
oled.line(p2x[3],p2y[3],p2x[0],p2y[0])
111+
oled.line(p2x[7],p2y[7],p2x[4],p2y[4])
112+
oled.line(p2x[3],p2y[3],p2x[7],p2y[7])
113+
oled.display()
114+
115+
def runExample():
116+
# Before you can start using the OLED, call begin() to init
117+
# all of the pins and configure the OLED.
118+
119+
print("\nSparkFun OLED Cube Example\n")
120+
myOLED = userOLED
121+
122+
if not myOLED.connected:
123+
print("The Qwiic OLED device isn't connected to the system. Please check your connection", \
124+
file=sys.stderr)
125+
return
126+
127+
myOLED.begin()
128+
# clear(ALL) will clear out the OLED's graphic memory.
129+
# clear(PAGE) will clear the Arduino's display buffer.
130+
myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
131+
# To actually draw anything on the display, you must call the
132+
# display() function.
133+
myOLED.display()
134+
135+
136+
while True:
137+
138+
drawCube(myOLED)
139+
time.sleep(.01)
140+
141+
142+
143+
if __name__ == '__main__':
144+
try:
145+
runExample()
146+
except (KeyboardInterrupt, SystemExit) as exErr:
147+
print("\nEnding OLED Cube Example")
148+
sys.exit(0)

0 commit comments

Comments
 (0)