Skip to content

Commit 8cb3b04

Browse files
authored
Merge pull request #34 from sparkfun/release_candidate
v1.3.2
2 parents 1775ff1 + 5beb1c1 commit 8cb3b04

10 files changed

+196
-46
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
SFE_MicroOLED Library Demo
3+
Paul Clark @ SparkFun Electronics
4+
Original Creation Date: April 3rd, 2021
5+
6+
This sketch demonstrates how to use the Large Letter 31x48 font.
7+
This font is disabled by default. To enable it, you need to edit
8+
SFE_MicroOLED.cpp and change line 85 (or thereabouts) from:
9+
#define INCLUDE_FONT_LARGELETTER 0
10+
to:
11+
#define INCLUDE_FONT_LARGELETTER 1
12+
13+
Hardware Connections:
14+
This example assumes you are using Qwiic. See the SPI examples for
15+
a detailed breakdown of connection info.
16+
17+
Want to support open source hardware? Buy a board from SparkFun!
18+
https://www.sparkfun.com/products/13003
19+
https://www.sparkfun.com/products/14532
20+
21+
This code is beerware; if you see me (or any other SparkFun employee) at the
22+
local, and you've found our code helpful, please buy us a round!
23+
24+
Distributed as-is; no warranty is given.
25+
*/
26+
27+
#include <Wire.h>
28+
#include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED
29+
30+
#define PIN_RESET 9
31+
32+
// From version v1.3, we can instantiate oled like this (but only for I2C)
33+
MicroOLED oled(PIN_RESET);
34+
35+
void setup()
36+
{
37+
Serial.begin(115200); // Begin the Serial port
38+
Serial.println(F("SparkFun MicroOLED Example"));
39+
40+
delay(100);
41+
Wire.begin();
42+
43+
// This is the new way of initializing the OLED.
44+
// We can pass a different I2C address and TwoWire port
45+
// If 0x3D does not work, try 0x3C
46+
oled.begin(0x3D, Wire); // Initialize the OLED
47+
48+
// Print the total number of fonts loaded into memory
49+
Serial.print(F("There are "));
50+
Serial.print(oled.getTotalFonts());
51+
Serial.println(F(" fonts available"));
52+
53+
oled.clear(ALL); // Clear the display's internal memory
54+
oled.display(); // Display what's in the buffer (splashscreen)
55+
56+
delay(1000); // Delay 1000 ms
57+
58+
oled.clear(PAGE); // Clear the buffer.
59+
60+
if (oled.setFontType(4) == 0) // Set font to type 4 (fontlargeletter31x48)
61+
{
62+
Serial.println(F("Could not enable font 4 (fontlargeletter31x48)!"));
63+
Serial.println(F("Have you changed the #define INCLUDE_FONT_LARGELETTER to 1 in SFE_MicroOLED.cpp?"));
64+
Serial.println(F("Freezing..."));
65+
while (1)
66+
; // Do nothing more
67+
}
68+
}
69+
70+
void loop()
71+
{
72+
// Demonstrate font 4
73+
// There are 58 possible characters in the font 4 type: A - z
74+
// Lets run through all of them and print them out!
75+
for (int i = 'A'; i <= 'z'; i += 2)
76+
{
77+
oled.clear(PAGE); // Clear the screen
78+
79+
oled.setCursor(0, 0); // Set cursor to top-left
80+
81+
oled.write(i); // Write a byte out as a character
82+
oled.write(i+1); // Write the next byte out as a character
83+
oled.display(); // Draw on the screen
84+
85+
delay(500); // Delay 500 ms
86+
}
87+
}

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SparkFun Micro OLED Breakout",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"keywords": "display oled",
55
"description": "Library for the SparkFun Micro OLED Breakout",
66
"repository":

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Micro OLED Breakout
2-
version=1.3.1
2+
version=1.3.2
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the <a href="https://www.sparkfun.com/products/13003">SparkFun Micro OLED Breakout</a>.

src/SFE_MicroOLED.cpp

+70-26
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,85 @@ You should have received a copy of the GNU General Public License
3434
along with this program. If not, see <http://www.gnu.org/licenses/>.
3535
******************************************************************************/
3636
#include <Arduino.h>
37-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
38-
#include <avr/pgmspace.h>
37+
#if defined(ARDUINO_ARCH_MBED)
38+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
39+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
40+
#include <avr/pgmspace.h>
3941
#else
40-
#include <pgmspace.h>
42+
#include <pgmspace.h>
4143
#endif
4244
#include <SFE_MicroOLED.h>
4345

4446
#ifndef _BV
4547
#define _BV(x) (1 << x)
4648
#endif
4749

48-
// The 31x48 font is handy, but uses a big chunk of flash memory - about 7k.
49-
// If you want to use font 4 in your sketch, uncomment out the line below:
50-
//#define INCLUDE_LARGE_LETTER_FONT
51-
5250
// This fixed ugly GCC warning "only initialized variables can be placed into program memory area"
5351
#if defined(__AVR__)
5452
#undef PROGMEM
5553
#define PROGMEM __attribute__((section(".progmem.data")))
5654
#endif
5755

58-
// Add header of the fonts here. Remove as many as possible to conserve FLASH memory.
59-
#include "util/font5x7.h"
60-
#include "util/font8x16.h"
61-
#include "util/fontlargenumber.h"
62-
#include "util/7segment.h"
63-
#include "util/fontlargeletter31x48.h"
64-
65-
// Change the total fonts included
66-
#ifdef INCLUDE_LARGE_LETTER_FONT
67-
#define TOTALFONTS 5
68-
#else
69-
#define TOTALFONTS 4
56+
// Add header of the fonts here.
57+
// Fonts that aren't included the section below are excluded by the compiler.
58+
#include "util/font5x7.h" // Font 0
59+
#include "util/font8x16.h" // Font 1
60+
#include "util/7segment.h" // Font 2
61+
#include "util/fontlargenumber.h" // Font 3
62+
#include "util/fontlargeletter31x48.h" // Font 4 (excluded by default - see below)
63+
64+
#define MAXFONTS 5 // Do not change this line - except when _adding_ new fonts
65+
66+
// To save flash memory, change these to zeros for the fonts you want to exclude.
67+
// In particular, the 31x48 font is handy, but uses a big
68+
// chunk of flash memory - about 7k. It is excluded by default.
69+
//
70+
// If you are compiling the code using your own makefile, you can use compiler flags to include
71+
// or exclude individual fonts. E.g.: -DINCLUDE_FONT_LARGELETTER=1 or -DINCLUDE_FONT_LARGENUMBER=0
72+
#ifndef INCLUDE_FONT_5x7
73+
#define INCLUDE_FONT_5x7 1 // Change this to 0 to exclude the 5x7 font
74+
#endif
75+
#ifndef INCLUDE_FONT_8x16
76+
#define INCLUDE_FONT_8x16 1 // Change this to 0 to exclude the 8x16 font
77+
#endif
78+
#ifndef INCLUDE_FONT_7SEG
79+
#define INCLUDE_FONT_7SEG 1 // Change this to 0 to exclude the seven segment font
7080
#endif
81+
#ifndef INCLUDE_FONT_LARGENUMBER
82+
#define INCLUDE_FONT_LARGENUMBER 1 // Change this to 0 to exclude the large number font
83+
#endif
84+
#ifndef INCLUDE_FONT_LARGELETTER
85+
#define INCLUDE_FONT_LARGELETTER 0 // Change this to 1 to include the large letter font
86+
#endif
87+
7188

72-
// Add the font name as declared in the header file. Remove as many as possible to conserve FLASH memory.
89+
// Add the font name as declared in the header file.
90+
// Exclude as many as possible to conserve FLASH memory.
7391
const unsigned char *MicroOLED::fontsPointer[] = {
74-
font5x7, font8x16, sevensegment, fontlargenumber
75-
#ifdef INCLUDE_LARGE_LETTER_FONT
76-
,
92+
#if INCLUDE_FONT_5x7
93+
font5x7,
94+
#else
95+
NULL,
96+
#endif
97+
#if INCLUDE_FONT_8x16
98+
font8x16,
99+
#else
100+
NULL,
101+
#endif
102+
#if INCLUDE_FONT_7SEG
103+
sevensegment,
104+
#else
105+
NULL,
106+
#endif
107+
#if INCLUDE_FONT_LARGENUMBER
108+
fontlargenumber,
109+
#else
110+
NULL,
111+
#endif
112+
#if INCLUDE_FONT_LARGELETTER
77113
fontlargeletter31x48
114+
#else
115+
NULL
78116
#endif
79117
};
80118

@@ -997,7 +1035,13 @@ uint8_t MicroOLED::getFontTotalChar(void)
9971035
*/
9981036
uint8_t MicroOLED::getTotalFonts(void)
9991037
{
1000-
return TOTALFONTS;
1038+
uint8_t totalFonts = 0;
1039+
for (uint8_t thisFont = 0; thisFont < MAXFONTS; thisFont++)
1040+
{
1041+
if (fontsPointer[thisFont] != NULL)
1042+
totalFonts++;
1043+
}
1044+
return (totalFonts);
10011045
}
10021046

10031047
/** \brief Get font type.
@@ -1015,8 +1059,8 @@ uint8_t MicroOLED::getFontType(void)
10151059
*/
10161060
uint8_t MicroOLED::setFontType(uint8_t type)
10171061
{
1018-
if ((type >= TOTALFONTS) || (type < 0))
1019-
return false;
1062+
if ((type >= MAXFONTS) || (fontsPointer[type] == NULL))
1063+
return false;
10201064

10211065
fontType = type;
10221066
fontWidth = pgm_read_byte(fontsPointer[fontType] + 0);

src/SFE_MicroOLED.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4444
#include <Wire.h> // Needed for TwoWire - even if we are using SPI or Parallel
4545
#include <SPI.h> // Needed for SPIClass - even if we are using I2C or Parallel
4646

47-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
48-
#include <avr/pgmspace.h>
47+
#if defined(ARDUINO_ARCH_MBED)
48+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
49+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
50+
#include <avr/pgmspace.h>
4951
#else
50-
#include <pgmspace.h>
52+
#include <pgmspace.h>
5153
#endif
5254

5355
#define I2C_ADDRESS_SA0_0 0b0111100

src/util/7segment.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ July 27, 2015
2525
#ifndef FONT7SEGMENT_H
2626
#define FONT7SEGMENT_H
2727

28-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
28+
#if defined(ARDUINO_ARCH_MBED)
29+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
30+
static const unsigned char sevensegment [] = {
31+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
2932
#include <avr/pgmspace.h>
33+
static const unsigned char sevensegment [] PROGMEM = {
3034
#else
3135
#include <pgmspace.h>
36+
static const unsigned char sevensegment [] PROGMEM = {
3237
#endif
33-
34-
static const unsigned char sevensegment [] PROGMEM = {
3538
// first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
3639
10,16,46,13,1,30,
3740
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

src/util/font5x7.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ July 27, 2015
2525
#ifndef FONT5X7_H
2626
#define FONT5X7_H
2727

28-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
28+
// Standard ASCII 5x7 font
29+
#if defined(ARDUINO_ARCH_MBED)
30+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
31+
static const unsigned char font5x7[] = {
32+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
2933
#include <avr/pgmspace.h>
34+
static const unsigned char font5x7[] PROGMEM = {
3035
#else
3136
#include <pgmspace.h>
37+
static const unsigned char font5x7[] PROGMEM = {
3238
#endif
33-
34-
// Standard ASCII 5x7 font
35-
static const unsigned char font5x7[] PROGMEM = {
3639
// first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
3740
5,8,0,255,12,75,
3841
0x00, 0x00, 0x00, 0x00, 0x00,

src/util/font8x16.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ July 27, 2015
2424
#ifndef FONT8X16_H
2525
#define FONT8X16_H
2626

27-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
27+
#if defined(ARDUINO_ARCH_MBED)
28+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
29+
static const unsigned char font8x16[] = {
30+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
2831
#include <avr/pgmspace.h>
32+
static const unsigned char font8x16[] PROGMEM = {
2933
#else
3034
#include <pgmspace.h>
35+
static const unsigned char font8x16[] PROGMEM = {
3136
#endif
32-
33-
static const unsigned char font8x16[] PROGMEM = {
3437
// first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
3538
8,16,32,96,2,56,
3639
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00,

src/util/fontlargeletter31x48.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ August 13, 2015
1919

2020
#ifndef FONTLARGELETTER31X48_H
2121
#define FONTLARGELETTER31X48_H
22-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
22+
23+
#if defined(ARDUINO_ARCH_MBED)
24+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
25+
static const unsigned char fontlargeletter31x48 [] = {
26+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
2327
#include <avr/pgmspace.h>
28+
static const unsigned char fontlargeletter31x48 [] PROGMEM = {
2429
#else
2530
#include <pgmspace.h>
31+
static const unsigned char fontlargeletter31x48 [] PROGMEM = {
2632
#endif
27-
static const unsigned char fontlargeletter31x48 [] PROGMEM = {
2833
// first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
2934
31,48,65,58,0,62,
3035
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xF8, 0xF8, 0xF8,

src/util/fontlargenumber.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ July 27, 2015
2525
#ifndef FONTLARGENUMBER_H
2626
#define FONTLARGENUMBER_H
2727

28-
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
28+
#if defined(ARDUINO_ARCH_MBED)
29+
// ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
30+
static const unsigned char fontlargenumber[] = {
31+
#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
2932
#include <avr/pgmspace.h>
33+
static const unsigned char fontlargenumber[] PROGMEM = {
3034
#else
3135
#include <pgmspace.h>
36+
static const unsigned char fontlargenumber[] PROGMEM = {
3237
#endif
33-
34-
static const unsigned char fontlargenumber[] PROGMEM = {
3538
// first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256)
3639
12,48,48,11,1,32,
3740
0x00, 0xC0, 0xF8, 0x7C, 0x3E, 0x3E, 0xFC, 0xF8, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0,

0 commit comments

Comments
 (0)