├── .DS_Store
├── .github
└── workflows
│ └── add_issue_to_project.yml
├── .gitignore
├── ISSUE_TEMPLATE.md
├── LICENSE.md
├── README.md
├── examples
├── Advanced
│ ├── 4_displays
│ │ └── 4_displays.ino
│ └── turn_on_all_segs
│ │ └── turn_on_all_segs.ino
├── Example_01_PrintString
│ └── Example_01_PrintString.ino
├── Example_02_TurnOnOneSegment
│ └── Example_02_TurnOnOneSegment.ino
├── Example_03_PrintChar
│ └── Example_03_PrintChar.ino
├── Example_04_SetBrightness
│ └── Example_04_SetBrightness.ino
├── Example_05_SetBlinkRate
│ └── Example_05_SetBlinkRate.ino
├── Example_06_ColonAndDecimal
│ └── Example_06_ColonAndDecimal.ino
├── Example_07_UnkownChar
│ └── Example_07_UnkownChar.ino
├── Example_08_MultiDisplay
│ └── Example_08_MultiDisplay.ino
├── Example_09_ScrollingString
│ └── Example_09_ScrollingString.ino
└── User Submitted
│ └── Example10_DefineChar
│ └── Example10_DefineChar.ino
├── keywords.txt
├── library.properties
└── src
├── SparkFun_Alphanumeric_Display.cpp
└── SparkFun_Alphanumeric_Display.h
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library/871796a88897811227261d5cb3cd0baf0c2fe70d/.DS_Store
--------------------------------------------------------------------------------
/.github/workflows/add_issue_to_project.yml:
--------------------------------------------------------------------------------
1 | name: Add new issue to our main project
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 |
8 | jobs:
9 | add-to-project:
10 | name: Add issue to project
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/add-to-project@main
14 | with:
15 | # You can target a project in a different organization
16 | # to the issue
17 | project-url: https://github.com/orgs/sparkfun/projects/19
18 | github-token: ${{ secrets.DEFECT_ADD_TO_PROJECT }}
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/*
2 | *.bin
3 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Subject of the issue
2 | Describe your issue here.
3 |
4 | ### Your workbench
5 | * What development board or microcontroller are you using?
6 | * What version of hardware or breakout board are you using?
7 | * How is the breakout board wired to your microcontroller?
8 | * How is everything being powered?
9 | * Are there any additional details that may help us help you?
10 |
11 | ### Steps to reproduce
12 | Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue.
13 |
14 | ### Expected behavior
15 | Tell us what should happen
16 |
17 | ### Actual behavior
18 | Tell us what happens instead
19 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | SparkFun License Information
2 | ============================
3 |
4 | SparkFun uses two different licenses for our files — one for hardware and one for code.
5 |
6 | Hardware
7 | ---------
8 |
9 | **SparkFun hardware is released under [Creative Commons Share-alike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/).**
10 |
11 | Note: This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by-sa/4.0/legalcode).
12 |
13 | You are free to:
14 |
15 | Share — copy and redistribute the material in any medium or format
16 | Adapt — remix, transform, and build upon the material
17 | for any purpose, even commercially.
18 | The licensor cannot revoke these freedoms as long as you follow the license terms.
19 | Under the following terms:
20 |
21 | Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
22 | ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
23 | No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
24 | Notices:
25 |
26 | You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
27 | No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
28 |
29 |
30 | Code
31 | --------
32 |
33 | **SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).**
34 |
35 | The MIT License (MIT)
36 |
37 | Copyright (c) 2016 SparkFun Electronics
38 |
39 | Permission is hereby granted, free of charge, to any person obtaining a copy
40 | of this software and associated documentation files (the "Software"), to deal
41 | in the Software without restriction, including without limitation the rights
42 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43 | copies of the Software, and to permit persons to whom the Software is
44 | furnished to do so, subject to the following conditions:
45 |
46 | The above copyright notice and this permission notice shall be included in all
47 | copies or substantial portions of the Software.
48 |
49 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55 | SOFTWARE.
56 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SparkFun Alphanumeric Display Library
2 | ========================================
3 |
4 | [](https://cdn.sparkfun.com/assets/parts/1/5/8/5/5/16919-SparkFun_Qwiic_Alphanumeric_Display_-_Pink-Demo.jpg)
5 |
6 | [*Qwiic Alphanumeric Display - Pink (COM-16919)*](https://www.sparkfun.com/products/16919)
7 |
8 | [](https://cdn.sparkfun.com/assets/parts/1/8/0/2/2/18566-SparkFun_Qwiic_Alphanumeric_Display_-_Green-Demo.jpg)
9 |
10 | [*Qwiic Alphanumeric Display - Green (COM-18566)*](https://www.sparkfun.com/products/18566)
11 |
12 | [](https://cdn.sparkfun.com/assets/parts/1/5/8/5/2/16916-SparkFun_Qwiic_Alphanumeric_Display_-_Red-Demo.jpg)
13 |
14 | [*Qwiic Alphanumeric Display - Red (COM-16916)*](https://www.sparkfun.com/products/16916)
15 |
16 | [](https://cdn.sparkfun.com/assets/parts/1/5/8/5/3/16917-SparkFun_Qwiic_Alphanumeric_Display_-_Blue-Demo.jpg)
17 |
18 | [*Qwiic Alphanumeric Display - Blue (COM-16917)*](https://www.sparkfun.com/products/16917)
19 |
20 | [](https://cdn.sparkfun.com/assets/parts/1/5/8/5/4/16918-SparkFun_Qwiic_Alphanumeric_Display_-_Purple-Demo.jpg)
21 |
22 | [*Qwiic Alphanumeric Display - Purple (COM-16918)*](https://www.sparkfun.com/products/16918)
23 |
24 | [](https://cdn.sparkfun.com/assets/parts/1/8/0/2/0/18565-SparkFun_Qwiic_Alphanumeric_Display_-_White-Demo.jpg)
25 |
26 | [*Qwiic Alphanumeric Display - White (COM-18565)*](https://www.sparkfun.com/products/18565)
27 |
28 | We are quite familiar with seven-segment displays. We see them on our alarm clocks, ovens, and microwaves. By adding more segments to each digit you can display more than just numbers! Introducing the brand new SparkFun Qwiic Alphanumeric Display. These fourteen-segment digits allow you to display all sorts of numbers, characters, and symbols. With [Qwiic](https://www.sparkfun.com/qwiic), simply plug it in and go. No soldering, no figuring out which is SDA or SCL, and no voltage regulation or translation required!
29 |
30 | The SparkFun Alphanumeric Display Arduino library makes printing strings to the display as easy as calling the print() function. With this library, you'll be able to send I2C commands to the VK16K33 LED driver chip to light up segments (including the decimal point or colon) and even scroll your string across the display. You can download the library through the Arduino library manager by searching 'SparkFun Alphanumeric Display' or you can get the GitHub repo as a .zip file and install the library from there.
31 |
32 | The VK16K33 also supports I2C address configuration. Simply close a combination of the address jumpers on the back and you can communicate with up to four displays on the same bus. Our slim board design also features detachable standoff holes, vertical Qwiic connectors, and internal mounting holes.
33 |
34 | SparkFun labored with love to create this code. Feel like supporting open source hardware?
35 | Buy a [board]() from SparkFun!
36 |
37 | Repository Contents
38 | -------------------
39 |
40 | * **/examples** - Example code to show how the functions work.
41 | * **/src** - Source files for the library (.cpp, .h).
42 | * **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
43 | * **libray.properties** - General library properties for the Arduino package manager
44 |
45 | Documentation
46 | --------------
47 |
48 | * **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
49 | * **[Product Repository](https://github.com/sparkfun/Qwiic_Alphanumeric_Display_Breakout)** - Main repository (including hardware files)
50 |
51 | License Information
52 | -------------------
53 |
54 | This product is _**open source**_!
55 |
56 | Please review the LICENSE.md file for license information.
57 |
58 | If you have any questions or concerns on licensing, please contact technical support on our [SparkFun forums](https://forum.sparkfun.com/viewforum.php?f=152).
59 |
60 | Distributed as-is; no warranty is given.
61 |
62 | - Your friends at SparkFun.
63 |
64 | __
65 |
--------------------------------------------------------------------------------
/examples/Advanced/4_displays/4_displays.ino:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2024 SparkFun Electronics
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a
7 | * copy of this software and associated documentation files (the "Software"),
8 | * to deal in the Software without restriction, including without limitation
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | * and/or sell copies of the Software, and to permit persons to whom the
11 | * Software is furnished to do so, subject to the following conditions: The
12 | * above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
14 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | * Distributed as-is; no warranty is given.
22 | *****************************************************************************************/
23 |
24 | #include
25 |
26 | #include //Click here to get the library: http://librarymanager/All#Alphanumeric_Display by SparkFun
27 | HT16K33 display;
28 |
29 | void setup() {
30 | Serial.begin(115200);
31 | Serial.println("Qwiic Alphanumeric examples");
32 | Wire.begin(); //Join I2C bus
33 |
34 | //check if displays will acknowledge
35 | // if (display.begin(0x70) == false)
36 | // if (display.begin(0x70, 0x71) == false)
37 | // if (display.begin(0x70, 0x71, 0x72) == false)
38 | if (display.begin(0x70, 0x71, 0x72, 0x73) == false)
39 | {
40 | Serial.println("Device did not acknowledge! Freezing.");
41 | while(1);
42 | }
43 | Serial.println("Displays acknowledged.");
44 |
45 | display.setBrightness(1);
46 | // display.setBlinkRate(2);
47 |
48 | // display.print("hell");
49 | // display.print("hello st");
50 | // display.print("hello stinky");
51 | display.print("hello stinky poo");
52 | }
53 |
54 | void loop()
55 | {
56 | }
57 |
--------------------------------------------------------------------------------
/examples/Advanced/turn_on_all_segs/turn_on_all_segs.ino:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2024 SparkFun Electronics
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a
7 | * copy of this software and associated documentation files (the "Software"),
8 | * to deal in the Software without restriction, including without limitation
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 | * and/or sell copies of the Software, and to permit persons to whom the
11 | * Software is furnished to do so, subject to the following conditions: The
12 | * above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
14 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | * Distributed as-is; no warranty is given.
22 | *****************************************************************************************/
23 |
24 | #include
25 |
26 | #include //Click here to get the library: http://librarymanager/All#Alphanumeric_Display by SparkFun
27 | HT16K33 display;
28 |
29 | void setup()
30 | {
31 | Serial.begin(115200);
32 | Serial.println("Qwiic Alphanumeric examples");
33 |
34 | Wire.begin(); //Join I2C bus
35 |
36 | if (display.begin(0x71) == false)
37 | {
38 | Serial.println("Device did not acknowledge! Freezing.");
39 | while (1);
40 | }
41 | Serial.println("Display acknowledged.");
42 |
43 | display.setBrightness(15);
44 | display.print("\t\t\t\t"); //Unknown char turns on all segements!
45 | display.decimalOn();
46 | display.colonOn();
47 | }
48 |
49 | void loop()
50 | {
51 | // for (uint8_t i = 0; i < 17; i++){
52 | // display.setBrightness(i);
53 | // display.print("\t\t\t\t"); //Unknown char turns on all segements!
54 | // display.decimalOn();
55 | // display.colonOn();
56 | // delay(1000);
57 | // }
58 | }
59 |
--------------------------------------------------------------------------------
/examples/Example_01_PrintString/Example_01_PrintString.ino:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************
2 | * This example tests illuminating whole 4 letter strings on the 14-segment display.
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 3, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | *
33 | * Distributed as-is; no warranty is given.
34 | ****************************************************************************************/
35 | #include
36 |
37 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
38 | HT16K33 display;
39 |
40 | void setup()
41 | {
42 | Serial.begin(115200);
43 | Serial.println("SparkFun Qwiic Alphanumeric - Example 1: Print String");
44 |
45 | Wire.begin(); //Join I2C bus
46 |
47 | if (display.begin() == false)
48 | {
49 | Serial.println("Device did not acknowledge! Freezing.");
50 | while (1);
51 | }
52 | Serial.println("Display acknowledged.");
53 |
54 | display.print("Milk");
55 | }
56 |
57 | void loop()
58 | {
59 | }
60 |
--------------------------------------------------------------------------------
/examples/Example_02_TurnOnOneSegment/Example_02_TurnOnOneSegment.ino:
--------------------------------------------------------------------------------
1 | /*******************************************************************************************
2 | * This example tests illuminating individual segments of the display. Pass in the segment
3 | * and digit you wish to illuminate to illuminateSegement().
4 | *
5 | * Priyanka Makin @ SparkFun Electronics
6 | * Original Creation Date: January 31, 2020
7 | *
8 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
9 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
10 | *
11 | * The MIT License (MIT)
12 | *
13 | * Copyright (c) 2024 SparkFun Electronics
14 | *
15 | * Permission is hereby granted, free of charge, to any person obtaining a
16 | * copy of this software and associated documentation files (the "Software"),
17 | * to deal in the Software without restriction, including without limitation
18 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 | * and/or sell copies of the Software, and to permit persons to whom the
20 | * Software is furnished to do so, subject to the following conditions: The
21 | * above copyright notice and this permission notice shall be included in all
22 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
23 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
24 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 | *
30 | * Hardware Connections:
31 | * Attach Red Board to computer using micro-B USB cable.
32 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
33 | *
34 | * Distributed as-is; no warranty is given.
35 | *****************************************************************************************/
36 | #include
37 |
38 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
39 | HT16K33 display;
40 |
41 | void setup()
42 | {
43 | Serial.begin(115200);
44 | Serial.println("SparkFun Qwiic Alphanumeric - Example 2: Turn On One Segment");
45 | Wire.begin(); //Join I2C bus
46 |
47 | //check if display will acknowledge
48 | if (display.begin() == false)
49 | {
50 | Serial.println("Device did not acknowledge! Freezing.");
51 | while(1);
52 | }
53 | Serial.println("Display acknowledged.");
54 |
55 | display.illuminateSegment('A', 0);
56 | display.illuminateSegment('L', 1);
57 | display.illuminateSegment('I', 2);
58 | display.illuminateSegment('G', 3);
59 | display.updateDisplay();
60 | }
61 |
62 | void loop()
63 | {
64 | }
65 |
--------------------------------------------------------------------------------
/examples/Example_03_PrintChar/Example_03_PrintChar.ino:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************
2 | * This example tests illuminating whole characters on the 14-segment display.
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 3, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | *
33 | * Distributed as-is; no warranty is given.
34 | *****************************************************************************************/
35 | #include
36 |
37 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
38 | HT16K33 display;
39 |
40 | void setup()
41 | {
42 | Serial.begin(115200);
43 | Serial.println("SparkFun Qwiic Alphanumeric - Example 3: Print Character");
44 | Wire.begin(); //Join I2C bus
45 |
46 | //check if display will acknowledge
47 | if (display.begin() == false)
48 | {
49 | Serial.println("Device did not acknowledge! Freezing.");
50 | while(1);
51 | }
52 | Serial.println("Display acknowledged.");
53 |
54 | display.printChar('W', 0);
55 | display.printChar('H', 1);
56 | display.printChar('A', 2);
57 | display.printChar('T', 3);
58 |
59 | display.updateDisplay();
60 | }
61 |
62 | void loop(){
63 | }
64 |
--------------------------------------------------------------------------------
/examples/Example_04_SetBrightness/Example_04_SetBrightness.ino:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************
2 | * This example sets the brightness of the Qwiic Alphanumeric display
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 18, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | *
33 | * Distributed as-is; no warranty is given.
34 | *****************************************************************************************/
35 | #include
36 |
37 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
38 | HT16K33 display;
39 |
40 | void setup() {
41 | Serial.begin(115200);
42 | Serial.println("SparkFun Qwiic Alphanumeric - Example 4: Set Brightness");
43 | Wire.begin(); //Join I2C bus
44 |
45 | //check if display will acknowledge
46 | if (display.begin() == false)
47 | {
48 | Serial.println("Device did not acknowledge! Freezing.");
49 | while(1);
50 | }
51 | Serial.println("Display acknowledged.");
52 |
53 | //The input to setBrightness is a duty cycle over 16
54 | //So, acceptable inputs to this function are ints between 0 (1/16 brightness) and 15 (full brightness)
55 | display.setBrightness(15);
56 |
57 | display.print("Milk");
58 | }
59 |
60 | void loop() {
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/examples/Example_05_SetBlinkRate/Example_05_SetBlinkRate.ino:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************
2 | * This example sets the blink rate of the Alphanumeric Display
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 18, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | *
33 | * Distributed as-is; no warranty is given.
34 | *****************************************************************************************/
35 | #include
36 |
37 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
38 | HT16K33 display;
39 |
40 | void setup() {
41 | Serial.begin(115200);
42 | Serial.println("SparkFun Qwiic Alphanumeric - Example 5: Set Blink Rate");
43 | Wire.begin(); //Join I2C bus
44 |
45 | //check if display will acknowledge
46 | if (display.begin() == false)
47 | {
48 | Serial.println("Device did not acknowledge! Freezing.");
49 | while(1);
50 | }
51 | Serial.println("Display acknowledged.");
52 |
53 | //Blink rate in Hz
54 | //Acceptable options are defined by HT16K33 datasheet and are 0.5, 1.0, or 2.0 Hz (float)
55 | display.setBlinkRate(2.0);
56 |
57 | display.print("Milk");
58 | }
59 |
60 | void loop() {
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/examples/Example_06_ColonAndDecimal/Example_06_ColonAndDecimal.ino:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************
2 | * This example tests the library's response to printing colons or decimal points.
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 3, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun!https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | *
33 | * Distributed as-is; no warranty is given.
34 | ****************************************************************************************/
35 | #include
36 |
37 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
38 | HT16K33 display;
39 |
40 | void setup(){
41 | Serial.begin(115200);
42 | Serial.println("SparkFun Qwiic Alphanumeric - Example 6: Colon And Decimal");
43 |
44 | Wire.begin();
45 |
46 | if (display.begin() == false)
47 | {
48 | Serial.println("Device did not acknowledge! Freezing.");
49 | while(1);
50 | }
51 | Serial.println("Display acknowledged.");
52 |
53 | //You can print colons and decimals
54 | //NOTE: they can only go in the character position determined by the layout of the display
55 | display.print("12:3.4");
56 |
57 | // display.decimalOn(); //Turn decimals on
58 | // display.decimalOff(); //Turn decimals off
59 | // display.decimalOnSingle(0); //Turn decimal on for one display
60 | // display.colonOn(); //Turn colons on
61 | // display.colonOff(); //Turn colons off
62 | // display.colonOnSingle(1); //Turn colon on for one display
63 | }
64 |
65 | void loop()
66 | {
67 | }
68 |
--------------------------------------------------------------------------------
/examples/Example_07_UnkownChar/Example_07_UnkownChar.ino:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************
2 | * This example tests the library's response to printing an unknown character.
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: March 13, 2020
6 | * Updated April 30, 2020 by Gaston Williams - changed exclamation to tab character
7 | *
8 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
9 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
10 | *
11 | * The MIT License (MIT)
12 | *
13 | * Copyright (c) 2024 SparkFun Electronics
14 | *
15 | * Permission is hereby granted, free of charge, to any person obtaining a
16 | * copy of this software and associated documentation files (the "Software"),
17 | * to deal in the Software without restriction, including without limitation
18 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 | * and/or sell copies of the Software, and to permit persons to whom the
20 | * Software is furnished to do so, subject to the following conditions: The
21 | * above copyright notice and this permission notice shall be included in all
22 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
23 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
24 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 | *
30 | * Hardware Connections:
31 | * Attach Red Board to computer using micro-B USB cable.
32 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
33 | *
34 | * Distributed as-is; no warranty is given.
35 | ****************************************************************************************/
36 | #include
37 |
38 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
39 | HT16K33 display;
40 |
41 | void setup() {
42 | Serial.begin(115200);
43 | Serial.println("SparkFun Qwiic Alphanumeric - Example 7: Unknown Char");
44 |
45 | Wire.begin();
46 |
47 | if (display.begin() == false)
48 | {
49 | Serial.println("Device did not acknowledge! Freezing.");
50 | while(1);
51 | }
52 | Serial.println("Display acknowledged.");
53 |
54 | //Because this is a character unknown to the library, expect the display
55 | //To turn on all segments for that unknown digit
56 | display.print("\t\t\t\t"); //tabs are not printable characters
57 | }
58 |
59 | void loop()
60 | {
61 | }
62 |
--------------------------------------------------------------------------------
/examples/Example_08_MultiDisplay/Example_08_MultiDisplay.ino:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | * This example tests printing across multiple alpha displays.
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 26, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | * Don't close any of the address jumpers so that it defaults to address 0x70.
33 | * Attach a second Alphanumeric display using Qwiic cable.
34 | * Close address jumper A0 so that this display's address become 0x71.
35 | *
36 | * Distributed as-is; no warranty is given.
37 | *****************************************************************************************/
38 | #include
39 |
40 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
41 | HT16K33 display;
42 |
43 | void setup() {
44 | Serial.begin(115200);
45 | Serial.println("SparkFun Qwiic Alphanumeric - Example 8: Multi Display");
46 | Wire.begin(); //Join I2C bus
47 |
48 | //check if displays will acknowledge
49 | //The first address in the begin() function should be the left-most display, traveling to the right from there
50 | //This is how the string will print across displays, reading from left to right.
51 | if (display.begin(0x70, 0x71) == false)
52 | {
53 | Serial.println("Device did not acknowledge! Freezing.");
54 | while(1);
55 | }
56 | Serial.println("Displays acknowledged.");
57 |
58 | display.print("Get Milk");
59 | }
60 |
61 | void loop()
62 | {
63 | }
64 |
--------------------------------------------------------------------------------
/examples/Example_09_ScrollingString/Example_09_ScrollingString.ino:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | * This example tests scrolling functionality of alphanumeric displays.
3 | *
4 | * Priyanka Makin @ SparkFun Electronics
5 | * Original Creation Date: February 26, 2020
6 | *
7 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
8 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16391
9 | *
10 | * The MIT License (MIT)
11 | *
12 | * Copyright (c) 2024 SparkFun Electronics
13 | *
14 | * Permission is hereby granted, free of charge, to any person obtaining a
15 | * copy of this software and associated documentation files (the "Software"),
16 | * to deal in the Software without restriction, including without limitation
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 | * and/or sell copies of the Software, and to permit persons to whom the
19 | * Software is furnished to do so, subject to the following conditions: The
20 | * above copyright notice and this permission notice shall be included in all
21 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
22 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
24 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | *
29 | * Hardware Connections:
30 | * Attach Red Board to computer using micro-B USB cable.
31 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
32 | * Don't close any of the address jumpers so that it defaults to address 0x70.
33 | * Attach a second Alphanumeric display using Qwiic cable.
34 | * Close address jumper A0 so that this display's address become 0x71.
35 | *
36 | * Distributed as-is; no warranty is given.
37 | *****************************************************************************************/
38 | #include
39 |
40 | #include //Click here to get the library: http://librarymanager/All#SparkFun_Qwiic_Alphanumeric_Display by SparkFun
41 | HT16K33 display;
42 |
43 | void setup() {
44 | Serial.begin(115200);
45 | Serial.println("SparkFun Qwiic Alphanumeric - Example 9: Scrolling String");
46 | Wire.begin(); //Join I2C bus
47 |
48 | //check if displays will acknowledge
49 | if (display.begin(0x70) == false)
50 | {
51 | Serial.println("Device did not acknowledge! Freezing.");
52 | while(1);
53 | }
54 | Serial.println("Displays acknowledged.");
55 |
56 | display.print("MILK");
57 | }
58 |
59 | void loop()
60 | {
61 | delay(300);
62 | display.shiftLeft();
63 | //Alternatively - you could also shift the string to the right
64 | //display.shiftRight();
65 | }
66 |
--------------------------------------------------------------------------------
/examples/User Submitted/Example10_DefineChar/Example10_DefineChar.ino:
--------------------------------------------------------------------------------
1 | /**************************************************************************************
2 | * This example redefines some characters of an alphanumeric display.
3 | *
4 | * Written by Gaston Williams
5 | * April 30, 2020
6 | *
7 | * Based on code written by
8 | * Priyanka Makin @ SparkFun Electronics
9 | * Original Creation Date: February 26, 2020
10 | *
11 | * SparkFun labored with love to create this code. Feel like supporting open source hardware?
12 | * Buy a board from SparkFun! https://www.sparkfun.com/products/16426
13 | *
14 | * The MIT License (MIT)
15 | *
16 | * Copyright (c) 2024 SparkFun Electronics
17 | *
18 | * Permission is hereby granted, free of charge, to any person obtaining a
19 | * copy of this software and associated documentation files (the "Software"),
20 | * to deal in the Software without restriction, including without limitation
21 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
22 | * and/or sell copies of the Software, and to permit persons to whom the
23 | * Software is furnished to do so, subject to the following conditions: The
24 | * above copyright notice and this permission notice shall be included in all
25 | * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
26 | * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
27 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
28 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 | *
33 | * Hardware Connections:
34 | * Attach Red Board to computer using micro-B USB cable.
35 | * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
36 | * Don't close any of the address jumpers so that it defaults to address 0x70.
37 | *
38 | * Distributed as-is; no warranty is given.
39 | *****************************************************************************************/
40 | #include
41 | HT16K33 display;
42 |
43 | void setup() {
44 | Serial.begin(115200);
45 | Serial.println("Qwiic Alphanumeric examples");
46 | Wire.begin(); //Join I2C bus
47 |
48 | //check if display will acknowledge
49 | if (display.begin() == false)
50 | {
51 | Serial.println("Device did not acknowledge! Freezing.");
52 | while(1);
53 | }
54 | Serial.println("Display acknowledged.");
55 |
56 | //Just for demo purposes, show original characters before change
57 | display.print("cafe");
58 | delay(500);
59 | display.print("size");
60 |
61 |
62 | //Update a, e, f, s and z to new characters
63 | //This change is not permanent, and lasts only for this program.
64 |
65 | //Define 14 segment bits: nmlkjihgfedcba
66 | display.defineChar('a', 0b01000001011000);
67 | display.defineChar('e', 0b10000001011000);
68 | display.defineChar('f', 0b01010101000000);
69 | //Also can use constants SEG_A - SEG_N to define characters
70 | display.defineChar('s', SEG_L | SEG_I | SEG_D); // 0b00100100001000
71 | display.defineChar('z', SEG_N | SEG_G | SEG_D); // 0b10000001001000
72 | }
73 |
74 | void loop()
75 | {
76 | //Show the new characters
77 | delay(500);
78 | display.print("cafe");
79 | delay(500);
80 | display.print("size");
81 | }
82 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Datatypes (KEYWORD1)
3 | #######################################
4 | HT16K33 KEYWORD1
5 |
6 | #######################################
7 | # Methods and Functions (KEYWORD2)
8 | #######################################
9 | begin KEYWORD2
10 | isConnected KEYWORD2
11 | initialize KEYWORD2
12 | checkDeviceID KEYWORD2
13 | lookUpDisplayAddress KEYWORD2
14 | clear KEYWORD2
15 | setBrightness KEYWORD2
16 | setBrightnessSingle KEYWORD2
17 | setBlinkRate KEYWORD2
18 | setBlinkRateSingle KEYWORD2
19 | displayOn KEYWORD2
20 | displayOff KEYWORD2
21 | displayOnSingle KEYWORD2
22 | displayOffSingle KEYWORD2
23 | setDisplayOnOff KEYWORD2
24 | enableSystemClock KEYWORD2
25 | disableSystemClock KEYWORD2
26 | enableSystemClockSingle KEYWORD2
27 | disableSystemclockSingle KEYWORD2
28 | illuminateSegment KEYWORD2
29 | illuminateChar KEYWORD2
30 | printChar KEYWORD2
31 | updateDispplay KEYWORD2
32 | decimalOnSingle KEYWORD2
33 | decimalOffSingle KEYWORD2
34 | setDecimalOnOff KEYWORD2
35 | colonOnSingle KEYWORD2
36 | colonOffSingle KEYWORD2
37 | setColonOnOff KEYWORD2
38 | shiftRight KEYWORD2
39 | shiftLeft KEYWORD2
40 | write KEYWORD2
41 | write KEYWORD2
42 | write KEYWORD2
43 | readRAM KEYWORD2
44 | writeRAM KEYWORD2
45 | writeRAM KEYWORD2
46 |
47 | #######################################
48 | # Constants (LITERAL1)
49 | #######################################
50 | DEFAULT_ADDRESS LITERAL1
51 | DEV_ID LITERAL1
52 | DEFAULT_NOTHING_ATTACHED LITERAL1
53 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=SparkFun Qwiic Alphanumeric Display Arduino Library
2 | version=2.2.11
3 | author=SparkFun Electronics
4 | maintainer=SparkFun Electronics
5 | sentence=A library to drive the Holtek HT16K33 LED Driver with an Alphanumeric Display.
6 | paragraph=Use our solderless and easy-to-use Qwiic system to send I2C commands to the SparkX Qwiic Alphanumeric Display to print strings. The I2C address is configurable, so you can connect up to four displays on one I2C bus!
7 | category=Display
8 | url=https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library
9 | architectures=*
10 |
--------------------------------------------------------------------------------
/src/SparkFun_Alphanumeric_Display.cpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | SparkFun_Alphanumeric_Display.cpp
3 | SparkFun Alphanumeric Display Library Source File
4 | Priyanka Makin @ SparkFun Electronics
5 | Original Creation Date: February 25, 2020
6 | https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library
7 |
8 | Updated May 2, 2020 by Gaston Williams to add defineChar function
9 |
10 | Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391
11 |
12 | This file implements all functions of the HT16K33 class. Functions here range
13 | from printing to one or more Alphanumeric Displays, changing the display settings, and writing/
14 | reading the RAM of the HT16K33.
15 |
16 | The Holtek HT16K33 seems to be susceptible to address changes intra-sketch. The ADR pins
17 | are muxed with the ROW and COM drivers so as semgents are turned on/off that affect
18 | the ADR1/ADR0 pins the address has been seen to change. The best way around this is
19 | to do a isConnected check before updateRAM() is sent to the driver IC.
20 |
21 | Development environment specifics:
22 | IDE: Arduino 1.8.9
23 | Hardware Platform: Arduino Uno
24 | Alphanumeric Display Breakout Version: 1.0.0
25 |
26 | The MIT License (MIT)
27 |
28 | Copyright (c) 2024 SparkFun Electronics
29 |
30 | Permission is hereby granted, free of charge, to any person obtaining a
31 | copy of this software and associated documentation files (the "Software"),
32 | to deal in the Software without restriction, including without limitation
33 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 | and/or sell copies of the Software, and to permit persons to whom the
35 | Software is furnished to do so, subject to the following conditions: The
36 | above copyright notice and this permission notice shall be included in all
37 | copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
38 | "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
39 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
40 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
41 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
42 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 |
45 | Distributed as-is; no warranty is given.
46 | ******************************************************************************/
47 |
48 | #include
49 |
50 | /*--------------------------- Character Map ----------------------------------*/
51 | #define SFE_ALPHANUM_UNKNOWN_CHAR 95
52 |
53 | //This is the lookup table of segments for various characters
54 | //For AVR architecture, use PROGMEM
55 | #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
56 | #include
57 | static const uint16_t PROGMEM alphanumeric_segs[96]{
58 | #else
59 | static const uint16_t alphanumeric_segs[96]{
60 | #endif
61 | // nmlkjihgfedcba
62 | 0b00000000000000, // ' ' (space)
63 | 0b00001000001000, // '!'
64 | 0b00001000000010, // '"'
65 | 0b01001101001110, // '#'
66 | 0b01001101101101, // '$'
67 | 0b10010000100100, // '%'
68 | 0b00110011011001, // '&'
69 | 0b00001000000000, // '''
70 | 0b00000000111001, // '('
71 | 0b00000000001111, // ')'
72 | 0b11111010000000, // '*'
73 | 0b01001101000000, // '+'
74 | 0b10000000000000, // ','
75 | 0b00000101000000, // '-'
76 | 0b00000000000000, // '.'
77 | 0b10010000000000, // '/'
78 | 0b00000000111111, // '0'
79 | 0b00010000000110, // '1'
80 | 0b00000101011011, // '2'
81 | 0b00000101001111, // '3'
82 | 0b00000101100110, // '4'
83 | 0b00000101101101, // '5'
84 | 0b00000101111101, // '6'
85 | 0b01010000000001, // '7'
86 | 0b00000101111111, // '8'
87 | 0b00000101100111, // '9'
88 | 0b00000000000000, // ':'
89 | 0b10001000000000, // ';'
90 | 0b00110000000000, // '<'
91 | 0b00000101001000, // '='
92 | 0b01000010000000, // '>'
93 | 0b01000100000011, // '?'
94 | 0b00001100111011, // '@'
95 | 0b00000101110111, // 'A'
96 | 0b01001100001111, // 'B'
97 | 0b00000000111001, // 'C'
98 | 0b01001000001111, // 'D'
99 | 0b00000101111001, // 'E'
100 | 0b00000101110001, // 'F'
101 | 0b00000100111101, // 'G'
102 | 0b00000101110110, // 'H'
103 | 0b01001000001001, // 'I'
104 | 0b00000000011110, // 'J'
105 | 0b00110001110000, // 'K'
106 | 0b00000000111000, // 'L'
107 | 0b00010010110110, // 'M'
108 | 0b00100010110110, // 'N'
109 | 0b00000000111111, // 'O'
110 | 0b00000101110011, // 'P'
111 | 0b00100000111111, // 'Q'
112 | 0b00100101110011, // 'R'
113 | 0b00000110001101, // 'S'
114 | 0b01001000000001, // 'T'
115 | 0b00000000111110, // 'U'
116 | 0b10010000110000, // 'V'
117 | 0b10100000110110, // 'W'
118 | 0b10110010000000, // 'X'
119 | 0b01010010000000, // 'Y'
120 | 0b10010000001001, // 'Z'
121 | 0b00000000111001, // '['
122 | 0b00100010000000, // '\'
123 | 0b00000000001111, // ']'
124 | 0b10100000000000, // '^'
125 | 0b00000000001000, // '_'
126 | 0b00000010000000, // '`'
127 | 0b00000101011111, // 'a'
128 | 0b00100001111000, // 'b'
129 | 0b00000101011000, // 'c'
130 | 0b10000100001110, // 'd'
131 | 0b00000001111001, // 'e'
132 | 0b00000001110001, // 'f'
133 | 0b00000110001111, // 'g'
134 | 0b00000101110100, // 'h'
135 | 0b01000000000000, // 'i'
136 | 0b00000000001110, // 'j'
137 | 0b01111000000000, // 'k'
138 | 0b01001000000000, // 'l'
139 | 0b01000101010100, // 'm'
140 | 0b00100001010000, // 'n'
141 | 0b00000101011100, // 'o'
142 | 0b00010001110001, // 'p'
143 | 0b00100101100011, // 'q'
144 | 0b00000001010000, // 'r'
145 | 0b00000110001101, // 's'
146 | 0b00000001111000, // 't'
147 | 0b00000000011100, // 'u'
148 | 0b10000000010000, // 'v'
149 | 0b10100000010100, // 'w'
150 | 0b10110010000000, // 'x'
151 | 0b00001100001110, // 'y'
152 | 0b10010000001001, // 'z'
153 | 0b10000011001001, // '{'
154 | 0b01001000000000, // '|'
155 | 0b00110100001001, // '}'
156 | 0b00000101010010, // '~'
157 | 0b11111111111111, // Unknown character (DEL or RUBOUT)
158 | };
159 |
160 | /*--------------------------- Device Status----------------------------------*/
161 |
162 | bool HT16K33::begin(uint8_t addressDisplayOne, uint8_t addressDisplayTwo, uint8_t addressDisplayThree, uint8_t addressDisplayFour, TwoWire &wirePort)
163 | {
164 | _deviceAddressDisplayOne = addressDisplayOne; // grab the address of the alphanumeric
165 | _deviceAddressDisplayTwo = addressDisplayTwo;
166 | _deviceAddressDisplayThree = addressDisplayThree;
167 | _deviceAddressDisplayFour = addressDisplayFour;
168 |
169 | if (_deviceAddressDisplayFour != DEFAULT_NOTHING_ATTACHED)
170 | numberOfDisplays = 4;
171 | else if (_deviceAddressDisplayThree != DEFAULT_NOTHING_ATTACHED)
172 | numberOfDisplays = 3;
173 | else if (_deviceAddressDisplayTwo != DEFAULT_NOTHING_ATTACHED)
174 | numberOfDisplays = 2;
175 | else
176 | numberOfDisplays = 1;
177 |
178 | //TODO: malloc more displayRAM
179 |
180 | _i2cPort = &wirePort; // Remember the user's setting
181 |
182 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
183 | {
184 |
185 | if (isConnected(i) == false)
186 | {
187 | return false;
188 | }
189 | // if (checkDeviceID(i) == false)
190 | // {
191 | // Serial.println(i);
192 | // Serial.println("Hello, I've failed checkDeviceID()");
193 | // return false;
194 | // }
195 | delay(100);
196 | }
197 |
198 | if (initialize() == false)
199 | {
200 | return false;
201 | }
202 |
203 | if (clear() == false) // Clear all displays
204 | {
205 | return false;
206 | }
207 |
208 | displayContent[4 * 4] = '\0'; // Terminate the array because we are doing direct prints
209 |
210 | return true;
211 | }
212 |
213 | // Check that the display is responding on the I2C bus
214 | // The Holtek IC sometimes fails to respond. This attempts multiple times before giving up.
215 | bool HT16K33::isConnected(uint8_t displayNumber)
216 | {
217 | uint8_t triesBeforeGiveup = 5;
218 |
219 | for (uint8_t x = 0; x < triesBeforeGiveup; x++)
220 | {
221 |
222 | _i2cPort->beginTransmission(lookUpDisplayAddress(displayNumber));
223 | if (_i2cPort->endTransmission() == 0)
224 | {
225 | return true;
226 | }
227 | delay(100);
228 | }
229 | return false;
230 | }
231 |
232 | // Run through initialization procedure for each display connected on the bus
233 | bool HT16K33::initialize()
234 | {
235 | // Turn on system clock of all displays
236 | if (enableSystemClock() == false)
237 | {
238 | return false;
239 | }
240 |
241 | // Set brightness of all displays to full brightness
242 | if (setBrightness(15) == false)
243 | {
244 | return false;
245 | }
246 |
247 | // Turn blinking off for all displays
248 | if (setBlinkRate(ALPHA_BLINK_RATE_NOBLINK) == false)
249 | {
250 | return false;
251 | }
252 |
253 | // Turn on all displays
254 | if (displayOn() == false)
255 | {
256 | return false;
257 | }
258 |
259 | return true;
260 | }
261 |
262 | // Turn on the system oscillator for all displays on the I2C bus
263 | bool HT16K33::enableSystemClock()
264 | {
265 | bool status = true;
266 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
267 | {
268 | if (enableSystemClockSingle(i) == false)
269 | status = false;
270 | }
271 | return status;
272 | }
273 |
274 | // Turn off the system oscillator for all displays on the bus
275 | bool HT16K33::disableSystemClock()
276 | {
277 | bool status = true;
278 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
279 | {
280 | if (disableSystemClockSingle(i) == false)
281 | status = false;
282 | }
283 | return status;
284 | }
285 |
286 | // Turn on the system oscillator for normal operation mode
287 | bool HT16K33::enableSystemClockSingle(uint8_t displayNumber)
288 | {
289 | uint8_t dataToWrite = ALPHA_CMD_SYSTEM_SETUP | 1; // Enable system clock
290 |
291 | bool status = writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite);
292 | delay(1); // Allow display to start
293 | return (status);
294 | }
295 |
296 | // Turn off the system oscillator for standby mode
297 | bool HT16K33::disableSystemClockSingle(uint8_t displayNumber)
298 | {
299 | uint8_t dataToWrite = ALPHA_CMD_SYSTEM_SETUP | 0; // Standby mode
300 |
301 | return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite));
302 | }
303 |
304 | // This function connects the display number to its coressponding address
305 | uint8_t HT16K33::lookUpDisplayAddress(uint8_t displayNumber)
306 | {
307 | switch (displayNumber)
308 | {
309 | case 1:
310 | return _deviceAddressDisplayOne;
311 | break;
312 | case 2:
313 | return _deviceAddressDisplayTwo;
314 | break;
315 | case 3:
316 | return _deviceAddressDisplayThree;
317 | break;
318 | case 4:
319 | return _deviceAddressDisplayFour;
320 | break;
321 | }
322 |
323 | return 0; // We shouldn't get here
324 | }
325 |
326 | /*-------------------------- Display configuration functions ---------------------------*/
327 |
328 | // Turn off all segments of all displays connected to bus
329 | bool HT16K33::clear()
330 | {
331 | // Clear the displayRAM array
332 | for (uint8_t i = 0; i < 16 * numberOfDisplays; i++)
333 | displayRAM[i] = 0;
334 |
335 | digitPosition = 0;
336 |
337 | return (updateDisplay());
338 | }
339 |
340 | // This function sets the brightness of all displays on the bus.
341 | // Duty cycle valid between 0 (1/16 brightness) and 15 (full brightness)
342 | bool HT16K33::setBrightness(uint8_t duty)
343 | {
344 | bool status = true;
345 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
346 | {
347 | if (setBrightnessSingle(i, duty) == false)
348 | status = false;
349 | }
350 | return status;
351 | }
352 |
353 | // Set the brightness of a single display
354 | // Duty cycle valid between 0 (1/16 brightness) and 15 (full brightness)
355 | bool HT16K33::setBrightnessSingle(uint8_t displayNumber, uint8_t duty)
356 | {
357 | if (duty > 15) // Error check
358 | duty = 15;
359 |
360 | uint8_t dataToWrite = ALPHA_CMD_DIMMING_SETUP | duty;
361 | return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite));
362 | }
363 |
364 | // Set the blink rate of all displays on the bus
365 | // Parameter "rate" in Hz
366 | // Valid options for "rate" are defined by datasheet: 2.0, 1.0, or 0.5 Hz
367 | // Any other input to this function will result in steady alphanumeric display
368 | bool HT16K33::setBlinkRate(float rate)
369 | {
370 | bool status = true;
371 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
372 | {
373 | if (setBlinkRateSingle(i, rate) == false)
374 | status = false;
375 | }
376 | return status;
377 | }
378 |
379 | // Set the blink rate of a single display on the bus
380 | // Parameter "rate" is in Hz
381 | // Valid options for "rate" are defined by datasheet: 2.0, 1.0, or 0.5 Hz
382 | // Any other input to this function will result in steady alphanumeric display
383 | bool HT16K33::setBlinkRateSingle(uint8_t displayNumber, float rate)
384 | {
385 | if (rate == 2.0)
386 | {
387 | blinkRate = ALPHA_BLINK_RATE_2HZ;
388 | }
389 | else if (rate == 1.0)
390 | {
391 | blinkRate = ALPHA_BLINK_RATE_1HZ;
392 | }
393 | else if (rate == 0.5)
394 | {
395 | blinkRate = ALPHA_BLINK_RATE_0_5HZ;
396 | }
397 | //default to no blink
398 | else
399 | {
400 | blinkRate = ALPHA_BLINK_RATE_NOBLINK;
401 | }
402 |
403 | uint8_t dataToWrite = ALPHA_CMD_DISPLAY_SETUP | (blinkRate << 1) | displayOnOff;
404 | return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite));
405 | }
406 |
407 | // Turn a single alphanumeric display on
408 | bool HT16K33::displayOnSingle(uint8_t displayNumber)
409 | {
410 | return setDisplayOnOff(displayNumber, true);
411 | }
412 |
413 | // Turn a single alphanumeric display off
414 | bool HT16K33::displayOffSingle(uint8_t displayNumber)
415 | {
416 | return setDisplayOnOff(displayNumber, false);
417 | }
418 |
419 | // Set or clear the display on/off bit of a given display number
420 | bool HT16K33::setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay)
421 | {
422 | if (turnOnDisplay) {
423 | displayOnOff = ALPHA_DISPLAY_ON;
424 | }
425 | else {
426 | displayOnOff = ALPHA_DISPLAY_OFF;
427 | }
428 |
429 | uint8_t dataToWrite = ALPHA_CMD_DISPLAY_SETUP | (blinkRate << 1) | displayOnOff;
430 | return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite));
431 | }
432 |
433 | // Turn on all displays on the I2C bus
434 | bool HT16K33::displayOn()
435 | {
436 | bool status = true;
437 |
438 | displayOnOff = ALPHA_DISPLAY_ON;
439 |
440 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
441 | {
442 | if (displayOnSingle(i) == false)
443 | status = false;
444 | }
445 |
446 | return status;
447 | }
448 |
449 | // Turn off all displays on the I2C bus
450 | bool HT16K33::displayOff()
451 | {
452 | bool status = true;
453 |
454 | displayOnOff = ALPHA_DISPLAY_OFF;
455 |
456 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
457 | {
458 | if (displayOffSingle(i) == false)
459 | status = false;
460 | }
461 |
462 | return status;
463 | }
464 |
465 | // Turn the decimal point on for a single display
466 | bool HT16K33::decimalOnSingle(uint8_t displayNumber, bool updateNow)
467 | {
468 | return setDecimalOnOff(displayNumber, true, updateNow);
469 | }
470 |
471 | // Turn the decimal point off for a single display
472 | bool HT16K33::decimalOffSingle(uint8_t displayNumber, bool updateNow)
473 | {
474 | return setDecimalOnOff(displayNumber, false, updateNow);
475 | }
476 |
477 | // Set or clear the decimal on/off bit
478 | bool HT16K33::setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal, bool updateNow)
479 | {
480 | uint8_t adr = 0x03;
481 | uint8_t dat;
482 |
483 | if (turnOnDecimal == true)
484 | {
485 | decimalOnOff = ALPHA_DECIMAL_ON;
486 | dat = 0x01;
487 | }
488 | else
489 | {
490 | decimalOnOff = ALPHA_DECIMAL_OFF;
491 | dat = 0x00;
492 | }
493 |
494 | displayRAM[adr + (displayNumber - 1) * 16] &= 0xFE;
495 | displayRAM[adr + (displayNumber - 1) * 16] |= dat;
496 |
497 | if(updateNow)
498 | {
499 | return updateDisplay();
500 | }
501 | else
502 | {
503 | return true;
504 | }
505 | }
506 |
507 | // Turn the decimal on for all displays on bus
508 | bool HT16K33::decimalOn()
509 | {
510 | bool status = true;
511 |
512 | decimalOnOff = ALPHA_DECIMAL_ON;
513 |
514 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
515 | {
516 | if (decimalOnSingle(i) == false)
517 | status = false;
518 | }
519 |
520 | return status;
521 | }
522 |
523 | // Turn the decimal point off for all displays on bus
524 | bool HT16K33::decimalOff()
525 | {
526 | bool status = true;
527 |
528 | decimalOnOff = ALPHA_DECIMAL_OFF;
529 |
530 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
531 | {
532 | if (decimalOffSingle(i) == false)
533 | status = false;
534 | }
535 | return status;
536 | }
537 |
538 | // Turn the colon on for a single display
539 | bool HT16K33::colonOnSingle(uint8_t displayNumber, bool updateNow)
540 | {
541 | return setColonOnOff(displayNumber, true, updateNow);
542 | }
543 |
544 | // Turn the colon off for a single display
545 | bool HT16K33::colonOffSingle(uint8_t displayNumber, bool updateNow)
546 | {
547 | return setColonOnOff(displayNumber, false, updateNow);
548 | }
549 |
550 | // Set or clear the colon on/off bit
551 | bool HT16K33::setColonOnOff(uint8_t displayNumber, bool turnOnColon, bool updateNow)
552 | {
553 | uint8_t adr = 0x01;
554 | uint8_t dat;
555 |
556 | if (turnOnColon == true)
557 | {
558 | colonOnOff = ALPHA_COLON_ON;
559 | dat = 0x01;
560 | }
561 | else
562 | {
563 | colonOnOff = ALPHA_COLON_OFF;
564 | dat = 0x00;
565 | }
566 |
567 | displayRAM[adr + (displayNumber - 1) * 16] &= 0xFE;
568 | displayRAM[adr + (displayNumber - 1) * 16] |= dat;
569 |
570 | if(updateNow)
571 | {
572 | return updateDisplay();
573 | }
574 | else
575 | {
576 | return true;
577 | }
578 | }
579 |
580 | // Turn the colon on for all displays on the bus
581 | bool HT16K33::colonOn()
582 | {
583 | bool status = true;
584 |
585 | colonOnOff = ALPHA_COLON_ON;
586 |
587 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
588 | {
589 | if (colonOnSingle(i) == false)
590 | status = false;
591 | }
592 | return status;
593 | }
594 |
595 | // Turn the colon off for all displays on the bus
596 | bool HT16K33::colonOff()
597 | {
598 | bool status = true;
599 |
600 | colonOnOff = ALPHA_COLON_OFF;
601 |
602 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
603 | {
604 | if (colonOffSingle(i) == false)
605 | status = false;
606 | }
607 | return status;
608 | }
609 |
610 | /*---------------------------- Light up functions ---------------------------------*/
611 |
612 | // Given a segment and a digit, set the matching bit within the RAM of the Holtek RAM set
613 | void HT16K33::illuminateSegment(uint8_t segment, uint8_t digit)
614 | {
615 | uint8_t com;
616 | uint8_t row;
617 |
618 | com = segment - 'A'; // Convert the segment letter back to a number
619 |
620 | if (com > 6)
621 | com -= 7;
622 | if (segment == 'I')
623 | com = 0;
624 | if (segment == 'H')
625 | com = 1;
626 |
627 | row = digit % 4; // Convert digit (1 to 16) back to a relative position on a given digit on display
628 | if (segment > 'G')
629 | row += 4;
630 |
631 | uint8_t offset = digit / 4 * 16;
632 | uint8_t adr = com * 2 + offset;
633 |
634 | // Determine the address
635 | if (row > 7)
636 | adr++;
637 |
638 | // Determine the data bit
639 | if (row > 7)
640 | row -= 8;
641 | uint8_t dat = 1 << row;
642 |
643 | displayRAM[adr] = displayRAM[adr] | dat;
644 | }
645 |
646 | // Given a binary set of segments and a digit, store this data into the RAM array
647 | void HT16K33::illuminateChar(uint16_t segmentsToTurnOn, uint8_t digit)
648 | {
649 | for (uint8_t i = 0; i < 14; i++) // There are 14 segments on this display
650 | {
651 | if ((segmentsToTurnOn >> i) & 0b1)
652 | illuminateSegment('A' + i, digit); // Convert the segment number to a letter
653 | }
654 | }
655 |
656 | // Print a character, for a given digit, on display
657 | void HT16K33::printChar(uint8_t displayChar, uint8_t digit)
658 | {
659 | // moved alphanumeric_segs array to PROGMEM
660 | uint16_t characterPosition = 65532;
661 |
662 | // space
663 | if (displayChar == ' ')
664 | characterPosition = 0;
665 | // Printable Symbols -- Between first character ! and last character ~
666 | else if (displayChar >= '!' && displayChar <= '~')
667 | {
668 | characterPosition = displayChar - '!' + 1;
669 | }
670 |
671 | uint8_t dispNum = digitPosition / 4;
672 |
673 | // Take care of special characters by turning correct segment on
674 | if (characterPosition == 14) // '.'
675 | decimalOnSingle(dispNum+1, false);
676 | if (characterPosition == 26) // ':'
677 | colonOnSingle(dispNum+1, false);
678 | if (characterPosition == 65532) // unknown character
679 | characterPosition = SFE_ALPHANUM_UNKNOWN_CHAR;
680 |
681 | uint16_t segmentsToTurnOn = getSegmentsToTurnOn(characterPosition);
682 |
683 | illuminateChar(segmentsToTurnOn, digit);
684 | }
685 |
686 | // Update the list to define a new segments display for a particular character
687 | bool HT16K33::defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn)
688 | {
689 | bool result = false;
690 |
691 | // Check to see if character is within range of displayable ASCII characters
692 | if (displayChar >= '!' && displayChar <= '~')
693 | {
694 | // Get the index of character in table and update its 14-bit segment value
695 | uint16_t characterPosition = displayChar - '!' + 1;
696 |
697 | // Create a new character definition
698 | struct CharDef * pNewCharDef = (CharDef *)calloc(1, sizeof(CharDef));
699 |
700 | // Set the position to the table index
701 | pNewCharDef -> position = characterPosition;
702 | // Mask the segment value to 14 bits only
703 | pNewCharDef -> segments = segmentsToTurnOn & 0x3FFF;
704 | // New definition always goes at the end of the list
705 | pNewCharDef -> next = NULL;
706 |
707 | // If list is empty set it to the new item
708 | if (pCharDefList == NULL)
709 | {
710 | pCharDefList = pNewCharDef;
711 | }
712 | else
713 | {
714 | // Otherwise go to the end of the list and add it there
715 | struct CharDef * pTail = pCharDefList;
716 |
717 | while(pTail->next != NULL)
718 | {
719 | pTail = pTail->next;
720 | }
721 |
722 | pTail->next = pNewCharDef;
723 | }
724 | // We added the definition so we're all good
725 | result = true;
726 | }
727 | return result;
728 | }
729 |
730 | // Get the character map from the definition list or default table
731 | uint16_t HT16K33::getSegmentsToTurnOn(uint8_t charPos)
732 | {
733 | uint16_t segments = 0;
734 | // pointer to a defined character in list
735 | struct CharDef * pDefChar = pCharDefList;
736 |
737 | // Search the chacters list for a match
738 | while(pDefChar && (pDefChar->position != charPos))
739 | {
740 | pDefChar = pDefChar -> next;
741 | }
742 |
743 | // If we found a match return that value
744 | if (pDefChar != NULL)
745 | {
746 | segments = pDefChar -> segments;
747 | }
748 | // Otherwise get the value from the table
749 | else
750 | {
751 | segments = pgm_read_word_near(alphanumeric_segs + charPos);
752 | }
753 | return segments;
754 | }
755 |
756 | /*
757 | * Write a byte to the display.
758 | * Required for overloading the Print function.
759 | */
760 | size_t HT16K33::write(uint8_t b)
761 | {
762 | // If user wants to print '.' or ':', don't increment the digitPosition!
763 | if (b == '.' || b == ':')
764 | printChar(b, 0);
765 | else
766 | {
767 | printChar(b, digitPosition++);
768 | digitPosition %= (numberOfDisplays * 4); // Convert displays to number of digits
769 | }
770 |
771 | return (updateDisplay()); // Send RAM buffer over I2C bus
772 | }
773 |
774 | /*
775 | * Write a character buffer to the display.
776 | * Required for overloading the Print function.
777 | */
778 | size_t HT16K33::write(const uint8_t *buffer, size_t size)
779 | {
780 | uint8_t buff;
781 |
782 | // Clear the displayRAM array
783 | for (uint8_t i = 0; i < 16 * numberOfDisplays; i++)
784 | displayRAM[i] = 0;
785 |
786 | digitPosition = 0;
787 | size_t stringIndex = 0;
788 |
789 | while (stringIndex < size && digitPosition < (4 * numberOfDisplays))
790 | {
791 | buff = buffer[stringIndex];
792 | // For special characters like '.' or ':', do not increment the digitPosition
793 | if (buff == '.')
794 | printChar('.', 0);
795 | else if (buff == ':')
796 | printChar(':', 0);
797 | else
798 | {
799 | printChar(buff, digitPosition);
800 | displayContent[digitPosition] = buff; // Record to internal array
801 |
802 | digitPosition++;
803 | }
804 | stringIndex++;
805 | }
806 |
807 | updateDisplay(); // Send RAM buffer over I2C bus
808 |
809 | return stringIndex;
810 | }
811 |
812 | /*
813 | * Write a string to the display.
814 | * Required for overloading the Print function.
815 | */
816 | size_t HT16K33::write(const char *str)
817 | {
818 | if (str == NULL)
819 | return 0;
820 | return write((const uint8_t *)str, strlen(str));
821 | }
822 |
823 | // Push the contents of displayRAM out to the various displays in 16 byte chunks
824 | bool HT16K33::updateDisplay()
825 | {
826 |
827 | bool status = true;
828 |
829 | for (uint8_t i = 1; i <= numberOfDisplays; i++)
830 | {
831 | if (writeRAM(lookUpDisplayAddress(i), 0, (uint8_t *)(displayRAM + ((i-1) * 16)), 16) == false)
832 | {
833 | //Serial.print("updateDisplay fail at display 0x");
834 | //Serial.println(lookUpDisplayAddress(i), HEX);
835 | status = false;
836 | }
837 | }
838 |
839 | return status;
840 | }
841 |
842 | // Shift the display content to the right one digit
843 | bool HT16K33::shiftRight(uint8_t shiftAmt)
844 | {
845 | for (uint8_t x = (4 * numberOfDisplays) - shiftAmt; x >= shiftAmt; x--)
846 | {
847 | displayContent[x] = displayContent[x - shiftAmt];
848 | }
849 |
850 | // Clear the leading characters
851 | for (uint8_t x = 0; x < shiftAmt; x++)
852 | {
853 | if (x + shiftAmt > (4 * numberOfDisplays))
854 | break; // Error check
855 |
856 | displayContent[0 + x] = ' ';
857 | }
858 |
859 | return (print(displayContent));
860 | }
861 |
862 | // Shift the display content to the left one digit
863 | bool HT16K33::shiftLeft(uint8_t shiftAmt)
864 | {
865 | for (int x = 0; x < 4 * numberOfDisplays; x++)
866 | {
867 | if (x + shiftAmt > (4 * numberOfDisplays))
868 | break; // Error check
869 | displayContent[x] = displayContent[x + shiftAmt];
870 | }
871 |
872 | // Clear the trailing characters
873 | for (int x = 0; x < shiftAmt; x++)
874 | {
875 | if (4 * numberOfDisplays - 1 - x < 0)
876 | break; //Error check
877 |
878 | displayContent[4 * numberOfDisplays - 1 - x] = ' ';
879 | }
880 |
881 | return (print(displayContent));
882 | }
883 |
884 | /*----------------------- Internal I2C Abstraction -----------------------------*/
885 |
886 | bool HT16K33::readRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize)
887 | {
888 | uint8_t displayNum = 1;
889 | if (address == _deviceAddressDisplayTwo)
890 | displayNum = 2;
891 | else if (address == _deviceAddressDisplayThree)
892 | displayNum = 3;
893 | else if (address == _deviceAddressDisplayFour)
894 | displayNum = 4;
895 | isConnected(displayNum); // Wait until display is ready
896 |
897 | _i2cPort->beginTransmission(address);
898 | _i2cPort->write(reg);
899 | _i2cPort->endTransmission(false);
900 |
901 | if (_i2cPort->requestFrom(address, buffSize) > 0)
902 | {
903 | for (uint8_t i = 0; i < buffSize; i++)
904 | buff[i] = _i2cPort->read();
905 | return true;
906 | }
907 |
908 | return false;
909 | }
910 |
911 | // Write the contents of the RAM array out to the Holtek IC
912 | bool HT16K33::writeRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize)
913 | {
914 | uint8_t displayNum = 1;
915 | if (address == _deviceAddressDisplayTwo)
916 | displayNum = 2;
917 | else if (address == _deviceAddressDisplayThree)
918 | displayNum = 3;
919 | else if (address == _deviceAddressDisplayFour)
920 | displayNum = 4;
921 | isConnected(displayNum); //Wait until display is ready
922 |
923 | _i2cPort->beginTransmission(address);
924 | _i2cPort->write(reg);
925 |
926 | for (uint8_t i = 0; i < buffSize; i++)
927 | _i2cPort->write(buff[i]);
928 |
929 | if (_i2cPort->endTransmission() == 0)
930 | return true;
931 |
932 | return false;
933 | }
934 |
935 | // Write a single byte to the display. This is often a command byte.
936 | // The address of the data to write is contained in the first four bits of dataToWrite
937 | bool HT16K33::writeRAM(uint8_t address, uint8_t dataToWrite)
938 | {
939 | uint8_t temp = 0;
940 | return (writeRAM(address, dataToWrite, (uint8_t *)&temp, 0));
941 | }
942 |
--------------------------------------------------------------------------------
/src/SparkFun_Alphanumeric_Display.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | SparkFun_Alphanumeric_Display.h
3 | SparkFun Alphanumeric Display Library Header File
4 | Priyanka Makin @ SparkFun Electronics
5 | Original Creation Date: July 25, 2019
6 | https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library
7 |
8 | Updated April 30, 2020 by Gaston Williams to add defineChar function
9 |
10 | Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391
11 |
12 | This file prototypes the HT16K33 class, implemented in SparkFun_Alphanumeric_Display.cpp.
13 |
14 | Development environment specifics:
15 | IDE: Arduino 1.8.9
16 | Hardware Platform: Arduino Uno
17 | Alphanumeric Display Breakout Version: 1.0.0
18 |
19 | The MIT License (MIT)
20 |
21 | Copyright (c) 2024 SparkFun Electronics
22 |
23 | Permission is hereby granted, free of charge, to any person obtaining a
24 | copy of this software and associated documentation files (the "Software"),
25 | to deal in the Software without restriction, including without limitation
26 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
27 | and/or sell copies of the Software, and to permit persons to whom the
28 | Software is furnished to do so, subject to the following conditions: The
29 | above copyright notice and this permission notice shall be included in all
30 | copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
31 | "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
33 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
34 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
35 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
36 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 |
38 | Distributed as-is; no warranty is given.
39 | ******************************************************************************/
40 | #ifndef __SparkFun_Alphanumeric_Display_H__
41 | #define __SparkFun_Alphanumeric_Display_H__
42 |
43 | #include
44 | #include
45 | #include
46 | #include
47 |
48 | #define DEFAULT_ADDRESS 0x70 // Default I2C address when A0, A1 are floating
49 | #define DEFAULT_NOTHING_ATTACHED 0xFF
50 |
51 | // Define constants for segment bits
52 | #define SEG_A 0x0001
53 | #define SEG_B 0x0002
54 | #define SEG_C 0x0004
55 | #define SEG_D 0x0008
56 | #define SEG_E 0x0010
57 | #define SEG_F 0x0020
58 | #define SEG_G 0x0040
59 | #define SEG_H 0x0080
60 | #define SEG_I 0x0100
61 | #define SEG_J 0x0200
62 | #define SEG_K 0x0400
63 | #define SEG_L 0x0800
64 | #define SEG_M 0x1000
65 | #define SEG_N 0x2000
66 |
67 |
68 | typedef enum
69 | {
70 | ALPHA_BLINK_RATE_NOBLINK = 0b00,
71 | ALPHA_BLINK_RATE_2HZ = 0b01,
72 | ALPHA_BLINK_RATE_1HZ = 0b10,
73 | ALPHA_BLINK_RATE_0_5HZ = 0b11,
74 | } alpha_blink_rate_t;
75 |
76 | typedef enum
77 | {
78 | ALPHA_DISPLAY_ON = 0b1,
79 | ALPHA_DISPLAY_OFF = 0b0,
80 | } alpha_display_t;
81 |
82 | typedef enum
83 | {
84 | ALPHA_DECIMAL_ON = 0b1,
85 | ALPHA_DECIMAL_OFF = 0b0,
86 | } alpha_decimal_t;
87 |
88 | typedef enum
89 | {
90 | ALPHA_COLON_ON = 0b1,
91 | ALPHA_COLON_OFF = 0b0,
92 | } alpha_colon_t;
93 |
94 | typedef enum
95 | {
96 | ALPHA_CMD_SYSTEM_SETUP = 0b00100000,
97 | ALPHA_CMD_DISPLAY_SETUP = 0b10000000,
98 | ALPHA_CMD_DIMMING_SETUP = 0b11100000,
99 | } alpha_command_t;
100 |
101 | // Structure for defining new character displays
102 | struct CharDef {
103 | uint8_t position;
104 | int16_t segments;
105 | struct CharDef * next;
106 | };
107 |
108 | // class HT16K33
109 | class HT16K33 : public Print
110 | {
111 | private:
112 | TwoWire *_i2cPort; // The generic connection to user's chosen I2C hardware
113 | uint8_t _deviceAddressDisplayOne; // Address of primary alphanumeric display
114 | uint8_t _deviceAddressDisplayTwo;
115 | uint8_t _deviceAddressDisplayThree;
116 | uint8_t _deviceAddressDisplayFour;
117 | uint8_t digitPosition = 0;
118 | uint8_t numberOfDisplays = 1;
119 | bool displayOnOff = 0; // Tracks display on/off bit of display setup register
120 | bool decimalOnOff = 0;
121 | bool colonOnOff = 0;
122 | uint8_t blinkRate = ALPHA_BLINK_RATE_NOBLINK; // Tracks blink bits in display setup register
123 |
124 | // Enough RAM for up to 4 displays on same I2C bus
125 | uint8_t displayRAM[16 * 4];
126 | char displayContent[4 * 4 + 1] = "";
127 |
128 | // Linked List of character definitions
129 | struct CharDef * pCharDefList = NULL;
130 |
131 | public:
132 | // Device status
133 | bool begin(uint8_t addressDisplayOne = DEFAULT_ADDRESS,
134 | uint8_t addressDisplayTwo = DEFAULT_NOTHING_ATTACHED,
135 | uint8_t addressDisplayThree = DEFAULT_NOTHING_ATTACHED,
136 | uint8_t addressDisplayFour = DEFAULT_NOTHING_ATTACHED,
137 | TwoWire &wirePort = Wire); // Sets the address of the device and opens the Wire port for communication
138 | bool isConnected(uint8_t displayNumber);
139 | bool initialize();
140 | uint8_t lookUpDisplayAddress(uint8_t displayNumber);
141 |
142 | //Display configuration functions
143 | bool clear();
144 | bool setBrightness(uint8_t duty);
145 | bool setBrightnessSingle(uint8_t displayNumber, uint8_t duty);
146 | bool setBlinkRate(float rate);
147 | bool setBlinkRateSingle(uint8_t displayNumber, float rate);
148 | bool displayOn();
149 | bool displayOff();
150 | bool displayOnSingle(uint8_t displayNumber);
151 | bool displayOffSingle(uint8_t displayNumber);
152 | bool setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay);
153 |
154 | bool enableSystemClock();
155 | bool disableSystemClock();
156 | bool enableSystemClockSingle(uint8_t displayNumber);
157 | bool disableSystemClockSingle(uint8_t displayNumber);
158 |
159 | // Light up functions
160 | void illuminateSegment(uint8_t segment, uint8_t digit);
161 | void illuminateChar(uint16_t disp, uint8_t digit);
162 | void printChar(uint8_t displayChar, uint8_t digit);
163 | bool updateDisplay();
164 |
165 | // Define Character Segment Map
166 | bool defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn);
167 | uint16_t getSegmentsToTurnOn (uint8_t charPos);
168 |
169 | // Decimal functions
170 | bool decimalOn();
171 | bool decimalOff();
172 | bool decimalOnSingle(uint8_t displayNumber, bool updateNow = true);
173 | bool decimalOffSingle(uint8_t displayNumber, bool updateNow = true);
174 | bool setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal, bool updateNow = true);
175 |
176 | // Colon functions
177 | bool colonOn();
178 | bool colonOff();
179 | bool colonOnSingle(uint8_t displayNumber, bool updateNow = true);
180 | bool colonOffSingle(uint8_t displayNumber, bool updateNow = true);
181 | bool setColonOnOff(uint8_t displayNumber, bool turnOnColon, bool updateNow = true);
182 |
183 | // Shifting
184 | bool shiftRight(uint8_t shiftAmt = 1);
185 | bool shiftLeft(uint8_t shiftAmt = 1);
186 |
187 | // For overloading the print function
188 | virtual size_t write(uint8_t);
189 | virtual size_t write(const uint8_t *buffer, size_t size);
190 | virtual size_t write(const char *str);
191 |
192 | // I2C abstraction
193 | bool readRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize);
194 | bool writeRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize);
195 | bool writeRAM(uint8_t reg, uint8_t data);
196 | };
197 |
198 | #endif
--------------------------------------------------------------------------------