-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10889 from ajithvasudevan/pr2_tm1637
Added support for TM1637 Seven-Segment Display
- Loading branch information
Showing
38 changed files
with
3,723 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build | ||
libraries | ||
sketches | ||
/.project | ||
*.h.gch | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: c | ||
before_install: | ||
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" | ||
- sleep 3 | ||
- export DISPLAY=:1.0 | ||
- wget https://downloads.arduino.cc/arduino-1.8.12-linux64.tar.xz | ||
- tar xf arduino-1.8.12-linux64.tar.xz | ||
- sudo mv arduino-1.8.12 /usr/local/share/arduino | ||
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino | ||
install: | ||
- ln -s $PWD /usr/local/share/arduino/libraries/SevenSegmentTM1637 | ||
script: | ||
- arduino --verify --board arduino:avr:uno --pref sketchbook.path="$PWD" $PWD/examples/Basic/Basic.ino | ||
notifications: | ||
email: | ||
on_success: change | ||
on_failure: change |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# SevenSegmentTM1637 Arduino Library | ||
|
||
* master [![Build Status](https://travis-ci.org/bremme/arduino-tm1637.svg?branch=master)](https://travis-ci.org/bremme/arduino-tm1637) | ||
* develop [![Build Status](https://travis-ci.org/bremme/arduino-tm1637.svg?branch=develop)](https://travis-ci.org/bremme/arduino-tm1637) | ||
|
||
|
||
Arduino library for controlling a TM163x based 7-segment display module. These modules are sold under various names by various suppliers. For example: | ||
|
||
* [Seed Studio: Grove 4 digit display](http://www.seeedstudio.com/depot/grove-4digit-display-p-1198.html) | ||
* [Ebay: 4 Bits Digital Tube LED TM1637](http://www.ebay.com/sch/i.html?_odkw=4+Bits+Digital+Tube+LED&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR0.TRC0.H0.X4+Bits+Digital+Tube+LED+TM1637.TRS0&_nkw=4+Bits+Digital+Tube+LED+TM1637&_sacat=0) | ||
* [DealExtreme: LED 4-Digit Display Module](http://www.dx.com/s/TM1637) | ||
|
||
They come in different sizes, colors and there is a clock (with a colon) and decimal (with four decimal dots) display variant. But the most common one is the red 0.36" clock version, this is also the cheapest one (you can get those for about $1.50). I've written this library using the above module, if I get my hands on any of the other variants I might add some specific code, for example to print floats on the decimal version. | ||
|
||
![TM1637](extras/img/TM1637-4-digit-colon.jpg) | ||
|
||
# Hardware setup | ||
|
||
| TM1637 PIN | Arduino PIN | Description | | ||
|------------|------------------|---------------------| | ||
| CLK | Any digital pin | Clock | | ||
| DIO | Any digital pin | Digital output | | ||
| VCC | 5V | Supply voltage | | ||
| GND | GND | Ground | | ||
|
||
|
||
# Installation | ||
|
||
Like any other Arduino library this library is installed by copying the files into a directory on the Arduino IDE search path. Most common is to put all files in a director in `your sketch folder/libraries/SevenSegmentTM1637/`. See [installing additional Arduino libraries](https://www.arduino.cc/en/Guide/Libraries) for more information. | ||
|
||
# Usage | ||
|
||
This library uses the [LCD API v1.0](http://playground.arduino.cc/Code/LCDAPI) so you can use the same functions/methods using this library as any lcd library which conforms to the LCD API. Furthermore this library (like described in the LCD API) inherent the Print class (See [Serial.print()](https://www.arduino.cc/en/Serial/Print) and for more details [Print.h](https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Print.h)). This means that you can use all Print class functions/methods like you're used to when you're doing `Serial.print("Something")` or `Serial.print(128, BIN)` for example. | ||
|
||
## Basic methods | ||
|
||
* `SevenSegmentTM1637(clkPin, dioPin)`Creates a display object | ||
* `init()` Initializes the display | ||
* `print(value)` Prints anything to the display (e.g. a string, number..) | ||
* `clear()` Clears the display (and resets cursor) | ||
* `home()` Resets cursor | ||
* `setCursor(row, col)` Set the cursor to specified position | ||
* `setBacklight(value)` Sets the brightness of the display | ||
* `on()` Turn the display on (set brightness to default) | ||
* `off()` Turns the display off (set brightness to zero) | ||
* `blink()` Blinks what ever is on the display | ||
* `setColonOn(bool)` Sets the colon in the middle of the display | ||
* `setPrintDelay(time)` Sets the delay when printing more than 4 characters | ||
|
||
## Advanced methods | ||
|
||
* `encode()` Encodes a single digit, single char or char array (C string) | ||
* `printRaw()` Prints raw byte(s) to the display | ||
* `command()` Sends one or more raw byte commands to the display | ||
|
||
## Low level methods | ||
|
||
* `comStart()` Serial communication start command | ||
* `comWriteByte(bytes)` Serial communication send byte command | ||
* `comAck()` Serial communication get acknowledged command | ||
* `comStop()` Serial communication stop command | ||
|
||
If you still want or need more functionality, I've included two super classes: | ||
|
||
* `SevenSegmentExtended()` Extends the base class with more usefull functions. | ||
* `SevenSegmentFun()` Even more extensions for fun. | ||
|
||
If you use any of these super classes, you will also get all the basic, advanced and low level methods as well. If you use the fun class extension you will get the extended class methods as well. | ||
|
||
## Extended class extra methods | ||
|
||
* `SevenSegmentExtended(clkPin, dioPin)` Creates a display object | ||
* `printTime(hour, min, [blink], [blinkDelay])` Prints the time to the display | ||
* `printTime(time, [blink], [blinkDelay])` Prints the time to the display | ||
* `printDualCounter(leftValue, rightValue)` Prints two digits to the display | ||
|
||
## Fun class extra methods | ||
|
||
* `SevenSegmentFun(clkPin, dioPin)` Creates a display object | ||
* `printLevelVertical(level, [leftToRight])` Print 0-100% (2 steps per digit) vertical level e.g. volume, battery | ||
* `printLevelVertical(level, leftToRight, symbol)` Print 0-100% (1 step per digit) vertical level using custom symbol | ||
* `printLevelHorizontal(levels[])` Prints 4 horizontal levels e.g. equalizer | ||
* `scrollingText()` Prints text and (keeps) scrolling | ||
* `snake()` Classic snake demo | ||
* `nightrider()` Nightrider Kit demo | ||
* `bombTimer()` Count down a (bomb) timer | ||
* `bouncingBall()` Bouncing ball demo | ||
|
||
For more extended information on what arguments all above functions accept and return see the header files of the classes (SevenSegmentTM1637.h, SevenSegmentExtended.h and SevenSegmentFun.h). | ||
|
||
# Trouble shooting | ||
|
||
* Some boards might not have enough power on their 5V pin. In that case try to use an external 5V power supply. People reported that the ESP8266 might be one of those boards. | ||
|
||
# Todo | ||
|
||
* Refactor library to make it more modular and support more chips | ||
+ Add support for all TM16xx chips (most should already work) | ||
+ Add support for MAX7219 displays | ||
+ Add support for TM74HC595 displays | ||
|
||
# Changelog | ||
|
||
+ 09-07-2020 version 1.1.1 | ||
+ Bug fixes | ||
+ fixed a typo in SevenSegmentFun.h file | ||
+ 04-07-2020 version 1.1.0 | ||
+ Improved `printLevelVertical()` using [pablo-lp](https://github.com/pablo-lp) suggestions | ||
+ The default `printLevelVertical()` can diplay twice the number of levels now (e.g. 9 levels for a defaulf 4 digit display) | ||
+ Add configurable blink delay when using the `printTime` methods (thanks to [simoneluconi](https://github.com/simoneluconi)) | ||
+ Added a new `printNumber()` method to make it easier to print right aligned numbers | ||
+ Thanks [dan2600](https://github.com/dan2600), [Bilick88](https://github.com/Bilick88), [jasonacox](https://github.com/jasonacox) for your suggestions. | ||
+ Bug fixes | ||
+ Merge PR from [berendkleinhaneveld](https://github.com/berendkleinhaneveld) to fix some compiler warnings | ||
+ Merge PR from [facelessloser](https://github.com/facelessloser) Remove some `Serial.prinln()` calls | ||
+ Merge PR from [RAnders00](https://github.com/RAnders00) Fix incorrect repsonse from `comReadByte()` | ||
+ Merge PR from [per1234](https://github.com/per1234) Use correct separator in `keywords.txt` | ||
+ 04-11-2016 version 1.0.4 | ||
+ Fixed bombTimer not counting down to zero (thanks to [foons](https://github.com/fooons) for opening an issue) | ||
* 22-05-2016 version 1.0.3 | ||
+ add support for all AVR MCU's (thanks to [per1234](https://github.com/per1234)) | ||
* 08-05-2016 version 1.0.2 | ||
+ fixed digitalHigh() macro for non AVR boards (thanks to [per1234](https://github.com/per1234)) | ||
* 28-09-2015 version 1.0.1 | ||
+ fixed folder structure to comply with Arduino library 1.5 rev 2 specifications | ||
* 28-09-2015 version 1.0.0 | ||
+ First release | ||
|
||
|
||
# Note | ||
|
||
I spend quite a bit of time to build this library. I hope it will be useful to others. I decided to publish it, although there still might be small bugs. If you find one, just let me know and I will try to fix it. If you have any other suggestion, don't hesitate to contact me. | ||
|
||
# Sources | ||
|
||
I've looked at many sources while constructing this library, bassicly all alternative Arduino TM1637 libraries and some AVR TM1637 libraries. While doing so I've found some really nice improvements compared to other implementations. For example, most libraries use a really low clock speed (~50us), I've tested with clock speeds as low as 1us and the chip still seems to respond well. Furthermore, from the (Chinese) datasheet it seems that you always have to perform three operation when communicating with the IC; set some configuration, set the address and send 1-4 digit data and set the display brightness. I've found out that this is not the case, you can do all of those separately if you want. | ||
|
||
Still without all these fine examples it would have taken me a lot more time to figure out the inner workings of this IC! | ||
|
||
Sources: | ||
* http://blog.3d-logic.com/2015/01/21/arduino-and-the-tm1637-4-digit-seven-segment-display/ | ||
* http://www.arduino.md/hardware/lcd-and-leds/0-36-led-display-4-digit-red/ | ||
* https://brainy-bits.com/tutorials/4-bits-7-segment-led-display-with-arduino/ | ||
|
||
|
||
#### Keywords | ||
|
||
People will probably Google for keywords when looking for a driver, so here are some: | ||
|
||
```TM1637 TM1636 library Arduino Led Driver 4 Digit Bits Digital LED Tube module LCD API Print.h Print class API display LCD AVR Atmega``` |
100 changes: 100 additions & 0 deletions
100
lib/lib_display/arduino-tm1637/SevenSegmentAsciiMap.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "SevenSegmentAsciiMap.h" | ||
|
||
// store an ASCII Map in PROGMEM (Flash memory) | ||
const uint8_t AsciiMap::map[] PROGMEM = { | ||
TM1637_CHAR_SPACE, | ||
TM1637_CHAR_EXC, | ||
TM1637_CHAR_D_QUOTE, | ||
TM1637_CHAR_POUND, | ||
TM1637_CHAR_DOLLAR, | ||
TM1637_CHAR_PERC, | ||
TM1637_CHAR_AMP, | ||
TM1637_CHAR_S_QUOTE, | ||
TM1637_CHAR_L_BRACKET, | ||
TM1637_CHAR_R_BRACKET, | ||
TM1637_CHAR_STAR, | ||
TM1637_CHAR_PLUS, | ||
TM1637_CHAR_COMMA, | ||
TM1637_CHAR_MIN, | ||
TM1637_CHAR_DOT, | ||
TM1637_CHAR_F_SLASH, | ||
TM1637_CHAR_0, // 48 (ASCII) | ||
TM1637_CHAR_1, | ||
TM1637_CHAR_2, | ||
TM1637_CHAR_3, | ||
TM1637_CHAR_4, | ||
TM1637_CHAR_5, | ||
TM1637_CHAR_6, | ||
TM1637_CHAR_7, | ||
TM1637_CHAR_8, | ||
TM1637_CHAR_9, | ||
TM1637_CHAR_COLON, | ||
TM1637_CHAR_S_COLON, | ||
TM1637_CHAR_LESS, | ||
TM1637_CHAR_EQUAL, | ||
TM1637_CHAR_GREAT, | ||
TM1637_CHAR_QUEST, | ||
TM1637_CHAR_AT, | ||
TM1637_CHAR_A, // 65 (ASCII) | ||
TM1637_CHAR_B, | ||
TM1637_CHAR_C, | ||
TM1637_CHAR_D, | ||
TM1637_CHAR_E, | ||
TM1637_CHAR_F, | ||
TM1637_CHAR_G, | ||
TM1637_CHAR_H, | ||
TM1637_CHAR_I, | ||
TM1637_CHAR_J, | ||
TM1637_CHAR_K, | ||
TM1637_CHAR_L, | ||
TM1637_CHAR_M, | ||
TM1637_CHAR_N, | ||
TM1637_CHAR_O, | ||
TM1637_CHAR_P, | ||
TM1637_CHAR_Q, | ||
TM1637_CHAR_R, | ||
TM1637_CHAR_S, | ||
TM1637_CHAR_T, | ||
TM1637_CHAR_U, | ||
TM1637_CHAR_V, | ||
TM1637_CHAR_W, | ||
TM1637_CHAR_X, | ||
TM1637_CHAR_Y, | ||
TM1637_CHAR_Z, | ||
TM1637_CHAR_L_S_BRACKET, // 91 (ASCII) | ||
TM1637_CHAR_B_SLASH, | ||
TM1637_CHAR_R_S_BRACKET, | ||
TM1637_CHAR_A_CIRCUM, | ||
TM1637_CHAR_UNDERSCORE, | ||
TM1637_CHAR_A_GRAVE, // 96 (ASCII) | ||
TM1637_CHAR_a, | ||
TM1637_CHAR_b, | ||
TM1637_CHAR_c, | ||
TM1637_CHAR_d, | ||
TM1637_CHAR_e, | ||
TM1637_CHAR_f, | ||
TM1637_CHAR_g, | ||
TM1637_CHAR_h, | ||
TM1637_CHAR_i, | ||
TM1637_CHAR_j, | ||
TM1637_CHAR_k, | ||
TM1637_CHAR_l, | ||
TM1637_CHAR_m, | ||
TM1637_CHAR_n, | ||
TM1637_CHAR_o, | ||
TM1637_CHAR_p, | ||
TM1637_CHAR_q, | ||
TM1637_CHAR_r, | ||
TM1637_CHAR_s, | ||
TM1637_CHAR_t, | ||
TM1637_CHAR_u, | ||
TM1637_CHAR_v, | ||
TM1637_CHAR_w, | ||
TM1637_CHAR_x, | ||
TM1637_CHAR_y, | ||
TM1637_CHAR_z, | ||
TM1637_CHAR_L_ACCON, // 123 (ASCII) | ||
TM1637_CHAR_BAR, | ||
TM1637_CHAR_R_ACCON, | ||
TM1637_CHAR_TILDE // 126 (ASCII) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#ifndef SevenSegmentAsciiMap_H | ||
#define SevenSegmentAsciiMap_H | ||
|
||
#include <Arduino.h> | ||
|
||
// ASCII MAPPINGS | ||
#define TM1637_CHAR_SPACE B00000000 // 32 (ASCII) | ||
#define TM1637_CHAR_EXC B00000110 | ||
#define TM1637_CHAR_D_QUOTE B00100010 | ||
#define TM1637_CHAR_POUND B01110110 | ||
#define TM1637_CHAR_DOLLAR B01101101 | ||
#define TM1637_CHAR_PERC B00100100 | ||
#define TM1637_CHAR_AMP B01111111 | ||
#define TM1637_CHAR_S_QUOTE B00100000 | ||
#define TM1637_CHAR_L_BRACKET B00111001 | ||
#define TM1637_CHAR_R_BRACKET B00001111 | ||
#define TM1637_CHAR_STAR B01011100 | ||
#define TM1637_CHAR_PLUS B01010000 | ||
#define TM1637_CHAR_COMMA B00010000 | ||
#define TM1637_CHAR_MIN B01000000 | ||
#define TM1637_CHAR_DOT B00001000 | ||
#define TM1637_CHAR_F_SLASH B00000110 | ||
#define TM1637_CHAR_0 B00111111 // 48 | ||
#define TM1637_CHAR_1 B00000110 | ||
#define TM1637_CHAR_2 B01011011 | ||
#define TM1637_CHAR_3 B01001111 | ||
#define TM1637_CHAR_4 B01100110 | ||
#define TM1637_CHAR_5 B01101101 | ||
#define TM1637_CHAR_6 B01111101 | ||
#define TM1637_CHAR_7 B00000111 | ||
#define TM1637_CHAR_8 B01111111 | ||
#define TM1637_CHAR_9 B01101111 | ||
#define TM1637_CHAR_COLON B00110000 | ||
#define TM1637_CHAR_S_COLON B00110000 | ||
#define TM1637_CHAR_LESS B01011000 | ||
#define TM1637_CHAR_EQUAL B01001000 | ||
#define TM1637_CHAR_GREAT B01001100 | ||
#define TM1637_CHAR_QUEST B01010011 | ||
#define TM1637_CHAR_AT B01011111 | ||
#define TM1637_CHAR_A B01110111 // 65 (ASCII) | ||
#define TM1637_CHAR_B B01111111 | ||
#define TM1637_CHAR_C B00111001 | ||
#define TM1637_CHAR_D TM1637_CHAR_d | ||
#define TM1637_CHAR_E B01111001 | ||
#define TM1637_CHAR_F B01110001 | ||
#define TM1637_CHAR_G B00111101 | ||
#define TM1637_CHAR_H B01110110 | ||
#define TM1637_CHAR_I B00000110 | ||
#define TM1637_CHAR_J B00001110 | ||
#define TM1637_CHAR_K B01110101 | ||
#define TM1637_CHAR_L B00111000 | ||
#define TM1637_CHAR_M B00010101 | ||
#define TM1637_CHAR_N B00110111 | ||
#define TM1637_CHAR_O B00111111 | ||
#define TM1637_CHAR_P B01110011 | ||
#define TM1637_CHAR_Q B01100111 | ||
#define TM1637_CHAR_R B00110011 | ||
#define TM1637_CHAR_S B01101101 | ||
#define TM1637_CHAR_T TM1637_CHAR_t | ||
#define TM1637_CHAR_U B00111110 | ||
#define TM1637_CHAR_V B00011100 | ||
#define TM1637_CHAR_W B00101010 | ||
#define TM1637_CHAR_X TM1637_CHAR_H | ||
#define TM1637_CHAR_Y B01101110 | ||
#define TM1637_CHAR_Z B01011011 | ||
#define TM1637_CHAR_L_S_BRACKET B00111001 // 91 (ASCII) | ||
#define TM1637_CHAR_B_SLASH B00110000 | ||
#define TM1637_CHAR_R_S_BRACKET B00001111 | ||
#define TM1637_CHAR_A_CIRCUM B00010011 | ||
#define TM1637_CHAR_UNDERSCORE B00001000 | ||
#define TM1637_CHAR_A_GRAVE B00010000 | ||
#define TM1637_CHAR_a B01011111 // 97 (ASCII) | ||
#define TM1637_CHAR_b B01111100 | ||
#define TM1637_CHAR_c B01011000 | ||
#define TM1637_CHAR_d B01011110 | ||
#define TM1637_CHAR_e B01111011 | ||
#define TM1637_CHAR_f TM1637_CHAR_F | ||
#define TM1637_CHAR_g B01101111 | ||
#define TM1637_CHAR_h B01110100 | ||
#define TM1637_CHAR_i B00000100 | ||
#define TM1637_CHAR_j B00001100 | ||
#define TM1637_CHAR_k TM1637_CHAR_K | ||
#define TM1637_CHAR_l B00110000 | ||
#define TM1637_CHAR_m TM1637_CHAR_M | ||
#define TM1637_CHAR_n B01010100 | ||
#define TM1637_CHAR_o B01011100 | ||
#define TM1637_CHAR_p TM1637_CHAR_P | ||
#define TM1637_CHAR_q TM1637_CHAR_Q | ||
#define TM1637_CHAR_r B01010000 | ||
#define TM1637_CHAR_s TM1637_CHAR_S | ||
#define TM1637_CHAR_t B01111000 | ||
#define TM1637_CHAR_u B00011100 | ||
#define TM1637_CHAR_v B00011100 | ||
#define TM1637_CHAR_w TM1637_CHAR_W | ||
#define TM1637_CHAR_x TM1637_CHAR_X | ||
#define TM1637_CHAR_y B01100110 | ||
#define TM1637_CHAR_z TM1637_CHAR_Z | ||
#define TM1637_CHAR_L_ACCON B01111001 // 123 (ASCII) | ||
#define TM1637_CHAR_BAR B00000110 | ||
#define TM1637_CHAR_R_ACCON B01001111 | ||
#define TM1637_CHAR_TILDE B01000000 // 126 (ASCII) | ||
|
||
class AsciiMap { | ||
public: | ||
const static uint8_t map[96]; | ||
}; | ||
// static const uint8_t asciiMap[96]; | ||
|
||
#endif |
Oops, something went wrong.