1#!/usr/bin/env python
2#-----------------------------------------------------------------------------
3# ex2_hello_world.py
4#
5# "Hello World" Example for the Qwiic 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 2 - Simple example to display "hello world" on the Qwiic OLED Display board.
40#
41
42from __future__ import print_function
43import qwiic_oled_display
44import sys
45
46def runExample():
47
48 # These three lines of code are all you need to initialize the
49 # OLED and print the splash screen.
50
51 # Before you can start using the OLED, call begin() to init
52 # all of the pins and configure the OLED.
53
54
55 print("\nSparkFun OLED Display - Hello World Example\n")
56
57 # Create instance with parameters for Qwiic OLED Display
58 myOLED = qwiic_oled_display.QwiicOledDisplay(0x3C, 128, 32)
59
60 if not myOLED.connected:
61 print("The Qwiic OLED Display isn't connected to the system. Please check your connection", \
62 file=sys.stderr)
63 return
64
65 myOLED.begin()
66
67 # clear(ALL) will clear out the OLED's graphic memory.
68 myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
69
70 # To actually draw anything on the display, you must call the display() function.
71 myOLED.display() # Display buffer contents
72 time.sleep(3)
73
74 # clear(PAGE) will clear the Arduino's display buffer.
75 myOLED.clear(myOLED.PAGE) # Clear the display's buffer
76
77 # Display buffer contents
78 myOLED.display()
79 time.sleep(3)
80
81 # Print "Hello World"
82 # ---------------------------------------------------------------------------
83 # Add text
84 myOLED.print("Hello World")
85
86 # Display buffer contents
87 myOLED.display()
88
89if __name__ == '__main__':
90 try:
91 runExample()
92 except (KeyboardInterrupt, SystemExit) as exErr:
93 print("\nEnding OLED Hello Example")
94 sys.exit(0)