Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Nov 23, 2023
1 parent 1a75a9e commit 9086fdc
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 102 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.9] - 2023-11-22
- update readme.md
- section about hardware performance (Kudos to SteveMicroCode #29)
- incl badges to platformIO
- badges to platformIO + issues
- improve related section
- update keywords.txt
- **keyScan()** replaces keyscan() => prefer camelCase (prep 0.4.0)
- patched examples.
- minor edits


## [0.3.8] - 2023-07-15
Expand Down
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Library for TM1637 driven displays and key scans.
The TM1637 drives 7 segment displays and can also scan a 16 key keyboard.

The library is mainly tested with Arduino UNO, both a 6 digits display and 4 digit (clock) display.
The TM1637 can scan max 2 rows and 8 columns or a smaller keyboard.
It is therefore not possible to scan a "standard" 3x4 or 4x4 matrix keypad.

ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull/5

Expand All @@ -28,6 +30,10 @@ ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull
- https://docs.wokwi.com/parts/wokwi-tm1637-7segment#simulator-examples
- https://github.com/SteveMicroCode/PIC-TM1637-Library-CodeOn
- includes interesting hardware notes.
- https://github.com/RobTillaart/HT16K33
- https://github.com/RobTillaart/AnalogKeypad
- https://github.com/RobTillaart/I2CKeyPad
- https://github.com/RobTillaart/I2CKeyPad8x8


#### Hardware connection and performance
Expand Down Expand Up @@ -131,14 +137,14 @@ TM.displayCelsius(temperature, (temperature < -9) || (temperature > 99));
Note that the effective range of Celsius and Fahrenheit differs.
When Fahrenheit goes from -9 to 99 Celsius goes from -26 to 37 (etc).

| F | C | | F | C |
| F | C | | C | F |
|:-----:|:-----:|:----:|:-----:|:-----:|
| -9 | -26 | | 16 | -9 |
| 99 | 37 | | 210 | 99 |
| -9 | -26 | | -9 | 16 |
| 99 | 37 | | 99 | 210 |

A three digit temperature, e.g. range -99 .. 999, would be possible but one has
to leave out either the ° character or the C/F.
As the C/F is more informative, the choice is fairly easy.
A three digit temperature, e.g. range -99 .. 999, or -9.9 .. 99.9 would be possible.
Then one has to leave out either the ° character or the C/F.
As the C/F is far more informative, the choice is fairly easy.
Question is how to API should change, new function of new behaviour?
See future.

Expand All @@ -151,8 +157,8 @@ See future.

#### KeyScan

- **uint8_t keyscan(void)** scans the keyboard once and return result.
The keyscan() function cannot detect multiple keys.
- **uint8_t keyScan(void)** scans the keyboard once and return result.
The keyScan() function cannot detect multiple keys.


#### DisplayRaw explained
Expand Down Expand Up @@ -247,15 +253,15 @@ Feel free to file an issue to get your processor supported.

- Kudos to wfdudley for this section - See #11

Calling **keyscan()** returns a uint8_t, whose value is 0xff if no keys are being pressed at the time.
Calling **keyScan()** returns a uint8_t, whose value is 0xff if no keys are being pressed at the time.
The TM1637 can only see one key press at a time, and there is no "rollover".
If a key is pressed, then the values are as follows:

<CENTER>
<TABLE>
<TR>
<TD colspan = 10 align="center">
keyscan results are reversed left for right from the data sheet.
keyScan results are reversed left for right from the data sheet.
</TD>
</TR>
<TR>
Expand All @@ -273,15 +279,14 @@ If a key is pressed, then the values are as follows:
</TABLE>
</CENTER>


To modify a "generic" TM1637 board for use with a keyboard, you must add connections to either
or both of pins 19 and 20 (these are the "row" selects) and then to as many of pins 2 through 9
(the "columns") as needed. It is easiest to connect to the "column pins" (2-9) by picking them
up where they connect to the LED displays (see second photo).
Generic keyboards that are a 4x4 matrix won't work; the TM1637 can only scan a 2x8 matrix.
Of course, fewer keys are acceptable; I use a 1x4 keyboard in my projects.

Further, the TM1637 chip needs a fairly hefty pull-up on the DIO pin for the keyscan() routine to work.
Further, the TM1637 chip needs a fairly hefty pull-up on the DIO pin for the keyScan() routine to work.
There is no pull-up in the TM1637 itself, and the clone boards don't seem to have one either,
despite the data sheet calling for 10K ohms pull-ups on DIO and CLOCK. 10K is too weak anyway.
The slow rise-time of the DIO signal means that the "true/high" value isn't reached fast enough and
Expand Down Expand Up @@ -328,14 +333,14 @@ hooked to the TRIGGER pin, and the two channel probes hooked to DIO and CLK.
Vertical sensitivity is 2v/division, horizontal timebase is 20usec/division.


## Keyscan
## KeyScan

Implemented in version 0.3.0 Please read the datasheet to understand the limitations.

```
// NOTE:
// on the TM1637 boards tested by @wfdudley, keyscan() works well
// if you add a 910 ohm or 1 Kohm pull-up resistor from DIO to 3.3v
// on the TM1637 boards tested by @wfdudley, keyScan() works well
// if you add a 910 ohm or 1000 ohm pull-up resistor from DIO to 3.3v
// This reduces the rise time of the DIO signal when reading the key info.
// If one only uses the pull-up inside the microcontroller,
// the rise time is too long for the data to be read reliably.
Expand All @@ -353,6 +358,7 @@ See examples

- (0.4.0)
- remove obsolete **init()** from code
- remove keyscan() => keyScan()
- **setLeadingZeros(bool on = false)** leading zeros flag, set data array to 0.
- **getLeadingZeros()**

Expand All @@ -367,7 +373,6 @@ See examples

#### Could

- **keyScan()** camelCase ?
- add parameter for **hideSegement(idx, character == SPACE)** to overrule hide char.
- space underscore or - are possible.
- add **TM1637_UNDERSCORE** to char set. ```seg[19] == 0x08```
Expand Down
8 changes: 4 additions & 4 deletions TM1637.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// URL: https://github.com/RobTillaart/TM1637_RT

// NOTE:
// on the inexpensive TM1637 boards @wfdudley has used, keyscan
// on the inexpensive TM1637 boards @wfdudley has used, keyScan
// works if you add a 1000 ohm pull-up resistor from DIO to 3.3v
// This reduces the rise time of the DIO signal when reading the key info.
// If one only uses the pull-up inside the microcontroller,
Expand Down Expand Up @@ -539,15 +539,15 @@ void TM1637::writeSync(uint8_t pin, uint8_t val)
}


// keyscan results are reversed left for right from the data sheet.
// here are the values returned by keyscan():
// keyScan results are reversed left for right from the data sheet.
// here are the values returned by keyScan():
//
// pin 2 3 4 5 6 7 8 9
// sg1 sg2 sg3 sg4 sg5 sg6 sg7 sg8
// 19 k1 0xf7 0xf6 0xf5 0xf4 0xf3 0xf2 0xf1 0xf0
// 20 k2 0xef 0xee 0xed 0xec 0xeb 0xea 0xe9 0xe8

uint8_t TM1637::keyscan(void)
uint8_t TM1637::keyScan(void)
{
uint8_t halfDelay = _bitDelay >> 1;
uint8_t key;
Expand Down
17 changes: 11 additions & 6 deletions TM1637.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// URL: https://github.com/RobTillaart/TM1637_RT

// NOTE:
// on the inexpensive TM1637 boards @wfdudley has used, keyscan
// on the inexpensive TM1637 boards @wfdudley has used, keyScan
// works if you add a 1000 ohm pull-up resistor from DIO to 3.3v
// This reduces the rise time of the DIO signal when reading the key info.
// If one only uses the pull-up inside the microcontroller,
Expand Down Expand Up @@ -71,7 +71,7 @@ class TM1637


// KEY SCAN
uint8_t keyscan(void);
uint8_t keyScan(void);


// CONFIGURATION
Expand All @@ -83,14 +83,19 @@ class TM1637
uint8_t g = 6, uint8_t h = 7);


// OBSOLETE
// init will be replaced by begin() in the future (0.4.0)
void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);

// DEBUG only
void dumpCache();


// OBSOLETE
// init() => begin() in 0.4.0
[[deprecated("Use begin() instead")]]
void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);
// keyscan() => keyScan() in 0.4.0
[[deprecated("Use keyScan() instead => camelCase!")]]
uint8_t keyscan(void) { return keyScan(); };


private:
uint8_t _clockPin = -1;
uint8_t _dataPin = -1;
Expand Down
4 changes: 2 additions & 2 deletions examples/TM1637_HEX/TM1637_HEX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void test()
start = millis();
for (int i = 0; i < 1000; i++)
{
TM.displayHex(val); // there is loop overhead etc
TM.displayHex(val); // there is loop overhead etc
val++;
}
stop = millis();
Expand All @@ -65,5 +65,5 @@ void test()
}


// -- END OF FILE --
// -- END OF FILE --

6 changes: 3 additions & 3 deletions examples/TM1637_alpha/TM1637_alpha.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void ascii_to_7segment(char *buff, uint8_t *data) {
data[j--] = buff[i] - 'g' + 18;
}
else if(buff[i] == '.') {
data[j+1] |= 0x80; // decimal point on previous digit
data[j+1] |= 0x80; // decimal point on previous digit
}
else {
data[j--] = 0x10; // blank
data[j--] = 0x10; // blank
}
}
}
Expand All @@ -59,5 +59,5 @@ uint8_t data[10];
}


// -- END OF FILE --
// -- END OF FILE --

8 changes: 4 additions & 4 deletions examples/TM1637_clock_4digits/TM1637_clock_4digits.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ void setup()
// left as exercise for the programmer ;)
void loop()
{
uint32_t now = millis() % 100000; // 0 - 99999
float value = now * 0.001; // 0 - 99.999
if (value - int(value) < 0.5) value *= 100; // for blink :
uint32_t now = millis() % 100000; // 0 - 99999
float value = now * 0.001; // 0 - 99.999
if (value - int(value) < 0.5) value *= 100; // for blink :
TM.displayFloat(value);
}

Expand All @@ -65,5 +65,5 @@ void loop2()
}


// -- END OF FILE --
// -- END OF FILE --

50 changes: 25 additions & 25 deletions examples/TM1637_custom/TM1637_custom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// URL: https://github.com/radionerd

// Demonstration of how to display char *buff and override the TM1637 library asciiTo7Segment virtual function
// to create a custom 7 segment character set.
// to create a custom 7 segment character set.
// The letter 'A' becomes swapped with @ in this trivial example
// Status: Experimental. Tested on STM32F103C8T6 Blue Pill and Arduino Nano only

Expand All @@ -23,15 +23,15 @@ const int DISPLAY_DIGITS_6 = 6;
class myTM1637 : TM1637 {
public:
void setBrightness(uint8_t b) { TM1637::setBrightness(b);};

void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6) {TM1637::begin(clockPin,dataPin,digits);};
void displayPChar( char * data ) {
TM1637::displayPChar( &data[0] ); // Call the base class
Serial.println(data); // Copy display output to the serial port

void displayPChar( char * data ) {
TM1637::displayPChar( &data[0] ); // Call the base class
Serial.println(data); // Copy display output to the serial port
};
uint8_t asciiTo7Segment ( char c ) { // Override library ascii to 7 segment conversion

uint8_t asciiTo7Segment ( char c ) { // Override library ascii to 7 segment conversion

// -01-
// 20 | | 02
Expand All @@ -40,15 +40,15 @@ class myTM1637 : TM1637 {
// -08- .80

//7+1 Segment patterns for ASCII 0x30-0x5F
const uint8_t asciiTo8Segment[] = {
0x00,0x86,0x22,0x7f, 0x6d,0x52,0x7d,0x02, // !"# $%&'
0x39,0x0f,0x7f,0x46, 0x80,0x40,0x80,0x52, // ()*+ ,-./
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, // 0123 4567
0x7f,0x6f,0x09,0x89, 0x58,0x48,0x4c,0xD3, // 89:; <=>?
0x77,0x5f,0x7c,0x39, 0x5E,0x79,0x71,0x3d, // @aBC DEFG NB: @ <-> A in this derived class
0x74,0x06,0x0E,0x75, 0x38,0x37,0x54,0x5c, // HIJK LMNO
0x73,0x67,0x50,0x6D, 0x78,0x3E,0x1C,0x9c, // PQRS TUVW
0x76,0x6E,0x5B,0x39, 0x52,0x0F,0x23,0x08 // XYZ[ /]^_
const uint8_t asciiTo8Segment[] = {
0x00,0x86,0x22,0x7f, 0x6d,0x52,0x7d,0x02, // !"# $%&'
0x39,0x0f,0x7f,0x46, 0x80,0x40,0x80,0x52, // ()*+ ,-./
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, // 0123 4567
0x7f,0x6f,0x09,0x89, 0x58,0x48,0x4c,0xD3, // 89:; <=>?
0x77,0x5f,0x7c,0x39, 0x5E,0x79,0x71,0x3d, // @aBC DEFG NB: @ <-> A in this derived class
0x74,0x06,0x0E,0x75, 0x38,0x37,0x54,0x5c, // HIJK LMNO
0x73,0x67,0x50,0x6D, 0x78,0x3E,0x1C,0x9c, // PQRS TUVW
0x76,0x6E,0x5B,0x39, 0x52,0x0F,0x23,0x08 // XYZ[ /]^_
};

uint8_t segments = c &0x80;
Expand All @@ -69,25 +69,25 @@ void setup()
delay(1000);
Serial.println(__FILE__);

// set clockpin, datapin to your own board pin names
// e.g. myTM.begin(PB8, PB9 , DISPLAY_DIGITS_6 );
myTM.begin( 14, 15 , DISPLAY_DIGITS_6 ); // clockpin, datapin, and digits
// set clockpin, datapin to your own board pin names
// e.g. myTM.begin(PB8, PB9 , DISPLAY_DIGITS_6 );
myTM.begin( 14, 15 , DISPLAY_DIGITS_6 ); // clockpin, datapin, and digits

myTM.setBrightness(2);

}


void loop()
{
char buff[20];
static int seconds;
// Show A and @ swapped over on custom character set
// Compare the 7 segment display with the text shown on the serial monitor
// Show A and @ swapped over on custom character set
// Compare the 7 segment display with the text shown on the serial monitor
sprintf(buff,"@-A%3d", seconds++%100 );
myTM.displayPChar(buff); // send buffer to display and serial port
myTM.displayPChar(buff); // send buffer to display and serial port
delay(1000);
}


// -- END OF FILE --
// -- END OF FILE --
2 changes: 1 addition & 1 deletion examples/TM1637_displayTime/TM1637_displayTime.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --
2 changes: 1 addition & 1 deletion examples/TM1637_displayTime2/TM1637_displayTime2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --
8 changes: 4 additions & 4 deletions examples/TM1637_float/TM1637_float.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ void setup()
TM.displayFloat(1.42425);
// TM.dumpCache();
delay(2000);

TM.displayFloat(-1.42425);
// TM.dumpCache();
delay(2000);

TM.displayClear();
// TM.dumpCache();
delay(2000);
Expand All @@ -47,7 +47,7 @@ void test()
start = millis();
for (int i = 0; i < 1000; i++)
{
TM.displayFloat(f); // there is loop overhead etc
TM.displayFloat(f); // there is loop overhead etc
f += 1;
}
stop = millis();
Expand All @@ -57,5 +57,5 @@ void test()
}


// -- END OF FILE --
// -- END OF FILE --

2 changes: 1 addition & 1 deletion examples/TM1637_hide_segment/TM1637_hide_segment.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --
Loading

0 comments on commit 9086fdc

Please sign in to comment.