1- /*
2- SFE_MicroOLED Display Bitmap
3- Joel Bartlett @ SparkFun Electronics
4- Original Creation Date: January 20, 2015
1+ // Example-08_Bitmap.ino
2+ //
3+ // This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
4+ //
5+ // SparkFun sells these at its website: www.sparkfun.com
6+ //
7+ // Do you like this library? Help support SparkFun. Buy a board!
8+ //
9+ // Micro OLED https://www.sparkfun.com/products/14532
10+ // Transparent OLED https://www.sparkfun.com/products/15173
11+ // "Narrow" OLED https://www.sparkfun.com/products/17153
12+ //
13+ //
14+ // Written by
15+ // Joel Bartlett @ SparkFun Electronics
16+ // Original Creation Date: January 20, 2015
17+ //
18+ // This library configures and draws graphics to OLED boards that use the
19+ // SSD1306 display hardware. The library only supports I2C.
20+ //
21+ // Repository:
22+ // https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
23+ //
24+ // Documentation:
25+ // https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
26+ //
27+ //
28+ // SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
29+ //
30+ // SPDX-License-Identifier: MIT
31+ //
32+ // The MIT License (MIT)
33+ //
34+ // Copyright (c) 2022 SparkFun Electronics
35+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
36+ // associated documentation files (the "Software"), to deal in the Software without restriction,
37+ // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
38+ // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to
39+ // do so, subject to the following conditions:
40+ // The above copyright notice and this permission notice shall be included in all copies or substantial
41+ // portions of the Software.
42+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
43+ // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44+ // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
45+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46+ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
547
6- This sketch shows you how to draw a 64x48 pixel Bitmap image on the MicroOLED.
48+ // Example 08 for the SparkFun Qwiic OLED Arduino Library
49+ //
50+ // >> Overview <<
51+ //
52+ // Draws a simple bitmap on a OLED.
53+ //
54+ // ////////////////////////////////////////////////////////////////////////////////////////
55+ // >>> SELECT THE CONNECTED DEVICE FOR THIS EXAMPLE <<<
56+ //
57+ // The Library supports three different types of SparkFun boards. The demo uses the following
58+ // defines to determine which device is being used. Uncomment the device being used for this demo.
59+ //
60+ // The default is Micro OLED
761
8- Hardware Connections:
9- This example assumes you are using Qwiic. See the SPI examples for
10- a detailed breakdown of connection info.
62+ // #define MICRO
63+ // #define NARROW
64+ # define TRANSPARENT
1165
12- Note: The display on the MicroOLED is a 1.8V-3.3V device only.
13- Don't try to connect a 5V Arduino directly to it! Use level
14- shifters in between the data signals if you have to resort to
15- a 5V board.
66+ // ////////////////////////////////////////////////////////////////////////////////////////
1667
17- This code is beerware; if you see me (or any other SparkFun
18- employee) at the local, and you've found our code helpful,
19- please buy us a round!
68+ #include < stdint.h>
2069
21- Distributed as-is; no warranty is given.
22- */
70+ // Include the SparkFun qwiic OLED Library
71+ # include < SparkFun_Qwiic_OLED.h >
2372
24- #include < Wire.h>
25- #include < SFE_MicroOLED.h> // Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED
73+ // What device is being used in this demo
2674
75+ #if defined(TRANSPARENT)
76+ QwiicTransparentOLED myOLED;
77+ const char * deviceName = " Transparent OLED" ;
2778
28- #define kMicroOLEDAddress 0x3D
29- #define kNarrowOLEDAddress 0x3C
79+ #elif defined(NARROW)
80+ QwiicNarrowOLED myOLED;
81+ const char * deviceName = " Narrow OLED" ;
82+
83+ #else
84+ QwiicMicroOLED myOLED;
85+ const char * deviceName = " Micro OLED" ;
86+
87+ #endif
3088
31- #define DC_JUMPER 1
32- #define PIN_RESET 9 // Optional - Connect RST on display to pin 9 on Arduino
3389
34- MicroOLED oled (PIN_RESET, kNarrowOLEDAddress , 128 , 32 ); // I2C declaration
3590// ------------------------------------------------------------------------------
3691// File generated by LCD Assistant
3792// http://en.radzio.dxp.pl/bitmap_converter/
3893// ------------------------------------------------------------------------------
3994// This is the array that holds the Bitmap image. The easiest way to convert a bmp
4095// to an array is to use the LCD Assistant linked above.
96+
97+ #define BMP_WIDTH 64
98+ #define BMP_HEIGHT 48
99+
41100uint8_t bender[] = {
42101 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x7F , 0xBF , 0xDF , 0x5F , 0x5F , 0x5F , 0x5F ,
43102 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F , 0x5F ,
@@ -64,29 +123,33 @@ uint8_t bender[] = {
64123 0xFB , 0xFB , 0xFB , 0xF8 , 0xFB , 0xFD , 0xFD , 0xFC , 0xFE , 0xFE , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
65124 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
66125
67- // I2C is great, but will result in a much slower update rate. The
68- // slower framerate may be a worthwhile tradeoff, if you need more
69- // pins, though.
126+ // Very siomple
70127void setup ()
71128{
72- delay (100 ); // Give display time to power on
73- Wire.begin (); // Setup I2C bus
74-
75- // Before you can start using the OLED, call begin() to init
76- // all of the pins and configure the OLED.
77- oled.begin ();
78- // clear(ALL) will clear out the OLED's graphic memory.
79- // clear(PAGE) will clear the Arduino's display buffer.
80- oled.clear (ALL); // Clear the display's memory (gets rid of artifacts)
81- // To actually draw anything on the display, you must call the
82- // display() function.
83- oled.display ();
84- delay (1000 ); // pause for the splash screen
85- // Note: You can change the spalsh screen by editing the array founf in the library source code
86-
87- oled.clear (PAGE); // clear the screen before we draw our image
88- oled.drawBitmap (bender); // call the drawBitmap function and pass it the array from above
89- oled.display (); // display the imgae
129+
130+ delay (500 ); // Give display time to power on
131+
132+ // Serial on!
133+ Serial.begin (115200 );
134+
135+ Serial.println (" \n\r -----------------------------------" );
136+
137+ Serial.print (" Running Example 01 on: " );
138+ Serial.println (String (deviceName));
139+
140+ // Initalize the OLED device and related graphics system
141+ if (!myOLED.begin ()){
142+
143+ Serial.println (" - Device Begin Failed" );
144+ while (1 );
145+ }
146+
147+ Serial.println (" - Begin Success" );
148+
149+ // Draw the bitmap
150+ myOLED.bitmap (0 , 0 , BMP_WIDTH, BMP_HEIGHT, bender, BMP_WIDTH, BMP_HEIGHT);
151+ myOLED.display ();
152+
90153}
91154
92155void loop ()
0 commit comments