Coder Social home page Coder Social logo

maxint-rd / tm16xx Goto Github PK

View Code? Open in Web Editor NEW
159.0 10.0 34.0 15.3 MB

Arduino TM16xx library for LED & KEY and LED Matrix modules based on TM1638, TM1637, TM1640 and similar chips. Simply use print() on 7-segment and use Adafruit GFX on matrix.

C++ 94.68% C 5.32%
adafruit-gfx matrix onebutton-library arduino arduino-library tm1638 tm1640 tm1637 tm1650 tm1668

tm16xx's Introduction

TM16xx

Arduino TM16xx library for LED & KEY and LED Matrix modules based on TM1638, TM1637, TM1640 and similar chips. Simply use print() on 7-segment displays and use Adafruit GFX on matrix displays.

TM16xx LEDs and Buttons library

This Arduino library facilitates driving LED displays using TM16xx LED driver chips. The TM16xx chip family allows driving 7-segment LED displays or LED matrices. Next to built-in high-frequency LED multiplexing, they offer control of LED brightness. Most TM16xx chips also support reading key-scan data for button presses. Using this library you can simply use print() on a 7-segment display or use Adafruit GFX on a LED matrix. Currently this library supports the TM1616, TM1618, TM1620, TM1628, TM1630, TM1637, TM1638, TM1640, TM1650 TM1652 and TM1668 chips. Note that there are similar chips made by other manufacturers that may be compatible with the Titan Micro chips. For instance: the HBS640 by WINRISE is compatible with the TM1640.

Made by Maxint R&D. See https://github.com/maxint-rd/

Initial version was based on the TM1638 library by Ricardo Batista. Further inspiration from the TM1637 library by Avishay, the Max72xxPanel library by Mark Ruys and the OneButton library by Matthias Hertel.

Table of contents

TM16xx chip features

The TM16xx family is quite large. Currently the following chips are supported:

Type Segments x digits Buttons Interface Notes
TM1616 7 x 4 n/a DIN/CLK/STB
TM1618 5 x 7 - 8 x 4 5 x 1 multi DIO/CLK/STB Anode*
TM1620 8 x 6 - 10 x 4 n/a DIN/CLK/STB
TM1628 10 x 7 - 13 x 4 10 x 2 multi DIO/CLK/STB
TM1630 7 x 5 - 8 x 4 7 x 1 multi DIO/CLK/STB
TM1637 8 x 6 (common anode) 8 x 2 single DIO/CLK
TM1638 10 x 8 8 x 3 multi DIO/CLK/STB Anode/Inverted/QYF*
TM1640 8 x 16 n/a DIN/CLK Anode*
TM1650 8 x 4 7 x 4 single DIO/CLK Not real I2C SDA/SCL
TM1652 8 x 5 - 7 x 6 n/a DIN Single data line
TM1668 10 x 7 - 13 x 4 10 x 2 multi DIO/CLK/STB

* Alternative configurations TM1638QYF/TM1638Anode/InvertedTM1638, TM1618Anode and TM1640Anode are also supported.

See the documents folder for datasheets containing more information about these chips and their pinouts.

Library structure

This library has a layered structure to simplify the support of multiple TM16xx chips. By using a base class that provides a uniform API, your application doesn't need chip specific code. Likewise, the library can offer common functionality in display specific classes that support multiple chips.

The figure below illustrates that concept:

Layered structure

Library installation

The easiest way to install this library is using the Arduino Library Manager. Just search for "TM16xx LEDs and Buttons" and click the install button. You can also download the latest version or select one from the releases as zipfile and use Add .ZIP library in the Arduino IDE.

NOTE: AdafruitGFX needs to be installed, even if you don't use TM16xxMatrixGFX. If you don't want to install AdafruitGFX you can remove TM16xxMatrixGFX.h and TM16xxMatrixGFX.cpp from the library directory to avoid compilation errors.

Basic usage

After installation you can use this library by including the class header that matches the chip on your module and then instantiate the object:

#include <TM1638.h>

TM1638 module(8, 9, 7);   // DIO=8, CLK=9, STB=7

In the setup() function you can set the intensity of the display, but that's not mandatory:

void setup() {
  module.setupDisplay(true, 2);   // on=true, intensity-2 (range 0-7)
  module.setDisplayToString("HALO");    // display simple text
}

In the loop() function you can use basic display methods provided by the base class:

void loop() {
  int nTime = ((millis() / 1000) / 60) * 100 + (millis() / 1000) % 60; // convert time to minutes+seconds as integer
  module.setDisplayToDecNumber(nTime, _BV(4)); // display milliseconds with dot on digit 4
}

For the easy to use print() method and more advance display methods you can use the TM16xxDisplay class.

The TM16xx chip makes it easy to see if a button is pressed. To check if a button was pressed you can use the getButtons() method:

  uint32_t dwButtons=module.getButtons();
  Serial.println(dwButtons, HEX);

Please note that while you don't need to write any code for debouncing, the button state may be reset when you display something. For advanced detection of button clicks, double clicks and long presses you can use the TM16xxButtons class.

TM16xxDisplay class

The TM16xxDisplay class adds some bytes to the memory footprint, but it provides the familiar easy to use print() and println() functions. Next to that it also provides some more advanced display methods. To use that class on top of the base class, all you need to do is instantiate it, refering to the chip specific class:

TM1638 module(8, 9, 7);   // DIO=8, CLK=9, STB=7
TM16xxDisplay display(&module, 8);    // TM16xx object, 8 digits

Simple print example using the TM16xxDisplay class:

#include <TM1638.h>
#include <TM16xxDisplay.h>

TM1638 module(8, 9, 7);   // DIO=8, CLK=9, STB=7
TM16xxDisplay display(&module, 8);    // TM16xx object, 8 digits

void setup() {
  display.println(F("HELLO !"));
}

int nCount=0;
void loop() {
  delay(1000);
  display.print("Count:");
  display.println(nCount++);
}

If you want you can combine multiple modules into a single TM16xxDisplay object. When combined print() and println() will use all available digits to print the string. See TM16xxDisplay.h for the provided methods.

TM16xxMatrix class

The TM16xxMatrix class provides basic methods for using a single LED-matrix module. For more advanced graphics use the TM16xxMatrixGFX class. To use the TM16xxMatrix class on top of the base class, all you need to do is instantiate it, refering to the chip specific class:

TM1640 module(9, 10);    // DIN=9, CLK=10
#define MATRIX_NUMCOLUMNS 16
#define MATRIX_NUMROWS 8
TM16xxMatrix matrix(&module, MATRIX_NUMCOLUMNS, MATRIX_NUMROWS);    // TM16xx object, columns, rows

Note that the TM1640 has sufficient outputs to drive two 8x8 matrices.

These methods can be used to set the pixels of the matrix:

  matrix.setAll(true);    // set all pixels on
  matrix.setPixel(5,6, true);   // set one pixel on
  matrix.setPixel(3,2, false);   // set another pixel off

See TM16xxMatrix.h for the provided methods.

TM16xxMatrixGFX class

The TM16xxMatrixGFX class implements the popular Adafruit GFX interface to drive one or more TM16xx based LED-matrix modules. To use the TM16xxMatrixGFX class you first need to include the proper header files:

#include <Adafruit_GFX.h>
#include <TM1640.h>
#include <TM16xxMatrixGFX.h>

Then you can instantiate the TM16xxMatrixGFX class, refering to the chip specific class:

TM1640 module(13, 14);    // For ESP8266/WeMos D1-mini: DIN=D7/13/MOSI, CLK=D5/14/SCK
#define MATRIX_NUMCOLUMNS 8
#define MATRIX_NUMROWS 8
TM16xxMatrixGFX matrix(&module, MATRIX_NUMCOLUMNS, MATRIX_NUMROWS);    // TM16xx object, columns, rows

Note that the TM1640 has sufficient outputs to drive two 8x8 matrices. The WeMOS D1 Mini Matrix LED Shield also uses the TM1640, but has only one 8x8 matrix.

These methods can be used to draw on the matrix:

  matrix.setIntensity(1);         // Use a value between 0 and 7 for brightness
  matrix.fillScreen(LOW);         // Clear the matrix
  matrix.drawPixel(1, 4, HIGH);   // set one pixel in the memory bitmap on
  matrix.write();                 // Send the memory bitmap to the display

In addition all the Adafruit GFX methods can be used, e.g.:

  matrix.drawChar(0, 0, 'A', HIGH, LOW, 1);
  matrix.drawLine(0, matrix. height(), matrix.width(), 0, HIGH);
  matrix.drawRect(0, 0, 6, 6, HIGH);

Multiple identical modules can be combined to form a large matrix. The data line can be shared to reduce the number of pins:

  TM1640 module(D7, D5);    // For ESP8266/WeMos D1-mini: DIN=D7/13/MOSI, CLK=D5/14/SCK
  TM1640 module2(D7, D6);   // For ESP8266/WeMos D1-mini: shared DIN=D7/13/MOSI, different CLK
  TM16xx * modules[]={&module,&module2};      // put modules in an array
  TM16xxMatrixGFX matrix(modules, MODULE_SIZECOLUMNS, MODULE_SIZEROWS, 2, 1);    // modules, size of each module, size combined

See Adafruit GFX documentation and TM16xxMatrixGFX.h for the provided methods. See the library examples for more information.

NOTE: AdafruitGFX needs to be installed, even if you don't use TM16xxMatrixGFX. If you don't want to install AdafruitGFX you can remove TM16xxMatrixGFX.h and TM16xxMatrixGFX.cpp from the library directory to avoid compilation errors. To reduce this dependency, the TM16xxMatrixGFX class may be moved to a separate library in future versions

TM16xxButtons class

The TM16xxButtons class enlarges the footprint a bit, but based on the popular OneButton library library, it adds more advanced methods to use buttons. Next to simply polling the state of each button, you can define callback functions that will be called when a button is released, clicked, double-clicked or long pressed. To use this class on top of the base class, all you need to do is include the proper headers and instantiate the buttons object, refering to the chip specific class, for example:

#include <TM1638.h>
#include <TM16xxButtons.h>

TM1638 module(8, 9, 7);   // DIO=8, CLK=9, STB=7
TM16xxButtons buttons(&module);    // TM16xx object

Then you define the functions you want to use to handle the button events:

void fnClick(byte nButton)
{ // byte nButton is the button-number (first button is number 0)
  Serial.print(F("Button "));
  Serial.print(nButton);
  Serial.println(F(" click."));
}

In setup() you need to attach the callback function:

void setup()
{
    .
    .
    buttons.attachClick(fnClick);
}

(BTW. Besides a click function, you can also attach a function to handle release, doubleclick and longpress events).

In loop() you need to call the tick() function that detects all state changes and calls the callback functions as needed:

void loop()
{
  buttons.tick();
  .
  .
  // do your other things
}

Some TM16xx chips support multiple simultaneous key presses. To implement a shift key, you can use the isPressed() function. See TM16xxButtons.h for the provided methods and the Button clicks example for more information.

New in this library

Added library functionality:

  • Support for ATtiny's (44A, 84A, 85), ESP8266, ESP32, LGT8F328P, Pi Pico, in addition to regular Arduinos.
  • Revised library structure to simplify support of other TM16xx chips in addition to TM1638/TM1640.
  • Basic functionality in base class for a uniform API.
  • Reduced required RAM memory by using PROGMEM fonts.
  • Separate classes for LED matrix and advanced LED display support.
  • Simple display of text and numbers on 7-segment and 14-segment displays using familiar print() and println() methods.
  • Support for combining multiple 7-segment and 14-segment display modules into one large display.
  • Support for the Adafruit GFX graphics library for advanced graphics on a LED matrix.
  • Support for combining multiple matrix modules into one large Adafruit GFX matrix.
  • Support for TM1616 (suggested by @NickLplus)
  • Support for TM1618 with 8x4 common cathode or 7x5 common anode displays (suggested by @ArnieO).
  • Support for TM1620 (thanks @eddwhite)
  • Support for TM1628. Note: TM1628 can be used in 10x7 - 13x4 display modes.
  • Support for TM1630 (thanks @tokuhira)
  • Support for TM1637. Note: TM1637 does not support simultaneous button presses. (Method derived from TM1637 library but using pins in standard output mode when writing).
  • Support for scanning all possible keys (K1, K2 and K3 lines) on TM1638.
  • Full support for QYF-TM1638 module (8 digit common anode LED display and 4x4 keypad)
  • Support for TM1638 in Anode Mode (10 digit common anode LED 8 segment display) (see TM1638Anode.h)
  • Support for TM1640 in Anode Mode (8 digit common anode LED 16 segment display) (see TM1640Anode.h)
  • Support for TM1650. Note: TM1650 can be used in 8x4 or 7x4 display mode. Datasheet fully translated.
  • Support for TM1652. Note: TM1652 uses a single data line and fixed timing to determine the clock. Datasheet fully translated.
  • Support for TM1668. Note: TM1668 can be used in 10x7 - 13x4 display modes. Datasheet partly translated.
  • Support for release, click, doubleclick and long press button detection using callback functions.
  • Added library examples.

Functionality in original library by Ricardo Batista:

  • Support for the TM1638 and TM1640, including common anode TM1638 module;
  • Helper methods for displaying numbers in decimal, hexadecimal and binary;
  • Support for multiple chained TM1638 and for TM1638 in inverted position;
  • Support for dimming the display and LEDs and for writing text;
  • Reading simultaneous button presses on TM1638;

Features & limitations

  • The current version of this library supports ESP8266/ESP32, Atmel ATmega (e.g. ATmega328 and ATmega168) and Atmel ATtiny MCUs. Due to the required memory, the smallest ATtiny MCU supported is the ATtiny44. Compatible MCUs such as LGT8F328P are also supported. Raspberry Pi Pico RP2040 is supported too (tested with core 2.5.2 by Earle Philhower). Support for CH32/STM32 is under development. Please let me know if you've successfully used this library with other MCUs.
  • For TM1640 on Pi Pico stability issues were reported (requiring further analysis).
  • The TM16xx chips offer no support for daisychaining multiple chips, but when separate Clk or Latch lines are used the Din line can be shared for combined displays.
  • It is possible to define multiple display objects for multiple different modules (see the TM1638_TM1637ex_two_modules example). The library now supports combining multiple 7-segment modules into one display using the TM16xxDisplay class (example for combined TM16xxDisplay to be included soon).
  • The TM16xxMatrixGFX class does support combining multiple LED Matrix module into one large matrix. Please note that the TM1640 supports up to 16 digits or an 8x16 LED matrix.
  • The QYF-TM1638 module (TM138 with common anode display) is fully supported. Please note that while multiple buttons can be pressed, pressing more than two buttons can give faulty results due to the lack of short-out preventing diodes on the module.
  • The popular TM1638 LED & KEY module comes in a number of varieties. My version has some odd button wiring sequence: S1=KS1, S5=KS2, S2=KS3, S6=KS4, S3=KS5, S7=KS6, S4=KS7, S8=KS8
  • The TM1640Anode class can be used with a Common Anode configuration to support 8 digits of 16 segments, such as the 5241BS 14-segment plus dot LED display (example for combined TM1640Anode to be included soon).
  • TM1628/TM1668 allow 13 segment mode, support for using 13-segment displays is still outstanding due to lack of having such dsiplays for testing.
  • The TM1650 datasheet mentions SDA and SCL pins. The used protocol resembles I2C, but lacks addressing. For that reason this library doesn't use the I2C Wire library, but (slow) bitbanging using digitalWrite.
  • The TM1652 allows more levels of LED dimming than supported. For uniformity only 8 levels of duty cycle are used, at maximum grid current.
  • The TM1668 class has experimental support for using RGB LEDs on Grids 5-7. Some information about the wiring can be found in the example code. In future versions this functionality may be replaced by a specific class for using RGB LEDs. (TODO: The TM1680 has 8x24 outputs which sounds ideal for creating a 8x8 RGB matrix. Unfortunately these chips don't support individual LED brightness, only intensity of the whole display).
  • The WeMOS D1 mini Matrix LED Shield and the TM1640 Mini LED Matrix 8x16 by Maxint R&D have R1 on the right-top. Call setMirror(true) to reverse the x-mirrorring.
  • When using TM16xxButtons, the amount of memory used can become too large. To preserve RAM memory on smaller MCUs such as the ATtiny84 and ATtiny85, the number of buttons tracked is limited to 2 combined button presses. This can be changed by setting the maximum button slots in the TM16xxButtons.h header file:
#define TM16XX_BUTTONS_MAXBUTTONSLOTS 2   // Note: changing this define requires recompilation of the library
  • Unfortunately ATtiny44/45 and smaller don't have enough flash to support both TM16xxDisplay and TM16xxButtons classes. However, it is possible to combine the module base class with only TM16xxButtons or only TM16xxDisplay.
  • An experimental RAM implementation using dynamic memory allocation is available, but not suitable for small MCUs as using malloc/free will increase the required FLASH program space by over 600 bytes. Modify the TM16XX_OPT_BUTTONS_... defines in the header file at your own risk.

More information

Examples

See the library examples for more information on how to use this library. See also the original examples by Ricardo Batista. Most will still work or only require minor changes.

Real world devices using a TM16xx chip

Some users found a TM16xx chip in their device and shared their experience:

If you happen to own a device featuring a TM16xx chip, feel free to open a new issue, sharing your experience. All contributions are appreciated!

Links

Disclaimer

  • All code on this GitHub account, including this library is provided to you on an as-is basis without guarantees and with all liability dismissed. It may be used at your own risk. Unfortunately I have no means to provide support.

tm16xx's People

Contributors

coldfirehunter avatar eddwhite avatar maxint-rd avatar per1234 avatar peter-kutak avatar skullkill avatar tokuhira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tm16xx's Issues

TM16xxDisplay.cpp bug

#if(TM16XX_OPT_COMBIDISPLAY) condition reversed in functions:
M16xxDisplay::setIntensity (line105), and
TM16xxDisplay::clear (line 203).

i.e. it refer to _aModules[I] when TM16XX_OPT_COMBIDISPLAY set to 0

Can I act _as_ a TM1651?

Hi,

This seems cool - I'm just now realizing that the TM16xx protocol is both a read and a write one, so it seems that libraries will support both - or at least this does (due to the buttons thing).

I have a situation where I want to take over a control panel for a device (a heater) and replace it with an ESP32. The panel contains a TM1651 chip to drive a 2-digit display, the heater communicates with the panel and has the two lines needed (CLK, DIO). The panel also has a beeper and a button.

Ideally, I'll interact with the heater through this data line, and be able to read the display codes the control panel was meant to show (I'll send them over wifi). Likewise, in the end, I want to send button pushes through the data line back to the heater to have it turn on/off. I have no idea how the beeper is hooked up - maybe it uses one of the not-yet-mapped wires (6 total) and is completely separate.

Is it possible to act as a TM16xx chip, and read segments and send button pushes (or keys) through this library?

Mike.

TM1650 Arduino library for 2 x 7 led display

Hey all I am using a 2 digit 7 segment TM1650 and I cant seem to find the setting for that? I can only find TM1650_DISPMODE_4x8 and TM1650_DISPMODE_4x7. No 2x7.

Digit animation

If someone could let me know how to go about modifying the code in order to allow me to use just 2 digitals instead of 4 then that would be great!

The current arduino nano code I am using:

#include <TM1650.h>
#include <TM16xxDisplay.h>
//              [data Pin]
//              |  [clock Pin]
//              |  |  [num Digits]
//              |  |  |  [activate Display]
//              |  |  |  |     [intensity]
//              |  |  |  |     |  [display mode]
//              ↓  ↓  ↓  ↓     ↓  ↓
TM1650 display1(2, 3, 2, true, 7   );

void setup()
{
}

void loop()
{
   int n;

   for (n = 0; n < 10; n++)
   {
      //                             [nNumber]
      //                             |  [byte bDots]
      //                             ↓  ↓
      display1.setDisplayToDecNumber(n, 0b0000);
      delay(250);                               
   }
}

Monitoring TM1628

Is there any way to use this library to listen to the serial comms. to my TM1628.

Sort of this library in reverse so I can make some of my 'dumb' devices 'smarter'. Read what's displayed on the 7 segments, listen for and make buttons presses on the grid, view other LED that are lit on the device, etc..

I'd like passively listen for everything and interpret the results. Ideally also send button presses from the library as well.

This is an older Royal Sovereign BDH-450 dehumidifier I'd like to remotely monitor and control.

I created fonts for the segments & LED based on playing around.

Segment 0 is the status LED for this device
Segment 1 is the right digit
Segment 2 is the left digit

Segment bitmap

 -- 1 --
|       |
2       0
 -- 3 --
6       7
|       |
 -- 4 --  .5

Segment display maps

byte SEG_DIGITS[] = {
  0b11101011, // 0
  0b10000001, // 1
  0b11011010, // 2
  0b11011001, // 3
  0b10110001, // 4
  0b01111001, // 5
  0b01111011, // 6
  0b11000001, // 7
  0b11111011, // 8
  0b11110001, // 9
  0b11110011, // A
  0b11111011, // B
  0b01101010, // C
  0b11101011, // D
  0b01111010, // E
  0b01110010  // F
};

Status LED for machine

byte STATUS_LIGHTS[] = {
  0b00000001, // FULL RESERVOIR
  0b00000010, // DEFROST
  0b00000100, // ?
  0b00001000, // ?
  0b00010000, // FAN - LOW
  0b00100000, // FAN - MEDIUM
  0b01000000, // FAN - HIGH
  0b10000000, // POWER
};

Using the getbutton listeners it returns the following
Down Arrow - Button 1
Up Arrow - Button 2
Fan Speed - Button 6
Power - Button 7

Redback 7-segment led and button module with TM1652

I've found a TM1682 on a piece of equipment I took apart. I've been unable to find a datasheet for it, but I did stumble on this repository.

The IC controls a display with four 7-segment displays, ten "symbols" which I assume are just LEDs and four push buttons.
image
It has six symbols not visible along the top. I'm counting those as well as the four signal strength bars as the ten LEDs.

How likely is it that the library can work with this IC? It has a Titan Micro symbol that matches other TM ICs. If there's a way to test, what would I need to modify, if anything?

Here's what I've mapped out so far, I'm surprised to not immediately see three pin inputs. I only see one data pin.
image

TM16xxDisplay.h compilation error under Linux

Thanks very much for doing and sharing this. Especially for for the Adafruit GFX integration: I've been using that for OLED and LCD displays, so it'll be really nice to be able to use it for the matrix LEDs I just bought.

At line 20 of TM16xxDisplay.h you include <print.h>, but it's not found under Linux because filenames are case-sensitive. Changing it to <Print.h> got rid of the error.

Add pinMode() to sendData() and getButtons()

TM16XX and DS1302 their pin definitions are very similar, so I connect their pins together to do use.
The DS1302 also uses pinMode() to change the GPIO settings, so I recommend adding pinMode() to sendData() to make sure it doesn't cause any problems in use.

void TM16xx::sendData(byte address, byte data)
{
  // Pull-up off
  pinMode(dataPin, OUTPUT);
  digitalWrite(dataPin, LOW);
  
  sendCommand(TM16XX_CMD_DATA_FIXED);							// use fixed addressing for data
  start();
  send(TM16XX_CMD_ADDRESS | address);						// address command + address
  send(data);
  stop();
}
uint32_t TM1620B::getButtons(void)
{
	// Pull-up off
	pinMode(dataPin, OUTPUT);
	digitalWrite(dataPin, LOW);

	word keys_K2 = 0;
	byte received;

	start();
	send(TM16XX_CMD_DATA_READ); // send read buttons command
	for (int i = 0; i < 3; i++)
	{
		received = receive();
		keys_K2 |= ((((received & _BV(1)) >> 1) | ((received & _BV(4)) >> 3)) << (2 * i));
	}
	stop();
	return (uint32_t)keys_K2;
}

Adafruit_GFX.h always needed

As far as I understand, Adafruit_GFX.h is needed for matrix display.
I'm trying to use only the segments display of the TM1620 (I have only put the #include TM1620 in the code), and the compiler is giving the error of Adafruit_GFX.h missing.

Why is the library required if it is not used? (as far as I know...)

Thanks in advance

Halt when useing RP2040 with TM1652

I tried using RP2040 to drive TM1652, but the example would crash and Windows would prompt an unrecognized USB devices.
But I can use hardware serial to driven TM1652, just use 'Serial2.begin(19200,SERIAL_8O2);' and set the TX pin to hardware serial pin, just
pay attention to the initialization, need to add a about 6ms of delay between the cleardisplay and send command.

Arduino IDE version: 1.8.19
RP2040 version: 3.6.0 by Earle F. Philhower, III

And there's my code:
my_TM1652.zip

It would be great if this library could be used hardware serial with all the good features of TM16XX library!

Problem while using this library with ESP32

Hi

i am using this Library with ESP32 with GPIO-23 as DIN and GPIO-19 as SCLK
the segment is Common Anode.
i tried using the TM1640Anod.h also but its not working.

`
#include <TM1640Anode.h>

#if !defined(LED_BUILTIN)
#define LED_BUILTIN 2
#endif

// Define a 4-digit display module. Pin suggestions:
// ESP8266 (Wemos D1): data pin 5 (D1), clock pin 4 (D2)
// ATtiny44A: data pin 9, clock pin 10 (LED_BUILTIN: 8 on ATTinyCore)
TM1640Anode module(23, 19,12); // data, clock, 4 digits

void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
//module.setDisplayToString("11111111");
module.sendAsciiChar(1,'b',true);
delay(500); // wait
//module.clearDisplay();
}

void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
//module.setupDisplay(true, 7); // sometimes noise on the line may change the intensity level
int nTime = ((millis() / 1000) / 60) * 100 + (millis() / 1000) % 60; // minutes+seconds as integer
//module.setDisplayToDecNumber(nTime, _BV(4)); // display dot on digit 4
module.sendAsciiChar(2,'2',true);
delay(500); // wait
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
//module.setDisplayToDecNumber(nTime, _BV(3)); // display colon on digit 3
module.sendAsciiChar(3,'1',true);
delay(500); // wait
}
`

Did i miss something please let me know.

Thanks

Hello Any help on TM1621

How to control TM1621 on arduino. i am noob arduino and i have to control Sonoff THR316 Display by arduino. Its working tasmota and esphome. Help me pls

Redefine Pins

Hello, I'm looking for where the pins are defined. We have a custom application for the 1620 chip and the pins are defined differently. I'm trying to figure out where in the library to redefine which segment of the display each output pin is connected to.

For whatever reason this is how the PCB designer set it up.
1620 PIN Segment
2 A
3 F
4 B
5 G
6 C
7 DP
8 D
9 E

2 TM16xxButtons seems to crash

I have 2 TM1637 chips, and I can use 2 of the tm16x matrix fine displaying LEDS, and I can use 1 Buttons class fine, but the minute I add a second and upload the arduino pro micro seems to brick and no comp port even shows up I have to hard reset and reflash without the second button for it to work.
I have enough RAM/ Flash so that doesn't seem to be the issue. any ideas?

how we can use 4 segment with dot

am building a clock how can i use centre dp ":" on tm1628

``#include <TM1628.h>
#include <TM16xxDisplay.h>

TM1628 module(11, 10, 9); // DIO=8, CLK=9, STB=7
#define NUM_DIGITS 5
TM16xxDisplay display(&module, NUM_DIGITS);

void setup() {

   display.print("10:30");

}

void loop() {
// put your main code here, to run repeatedly:

}
``

Schematic_328 +1628_2023-09-03

Button numbering question for TM1638 LED&KEY module (8 LEDS, 8 digits, 8 Buttons)?

I am testing this library by running the TM16xxButtons_clicks.ino example. I was expecting the Button numbers to be reported as either 0 thru 7, or 1 thru 8. However this is what I see:
ButtonPressed DisplayedValue fnClick Reported Button
1 10000 Button 16 Click
2 40000 Button 18 Click
3 100000 Button 20 Click
4 400000 Button 22 Click
5 20000 Button 17 Click
6 80000 Button 19 Click
7 200000 Button 21 Click
8 800000 Button 23 Click

I think I see where these values are created: TM1628::getButtons(void) in TM1628.cpp

Is there something simple I'm missing to get the values I was expecting? Or do i have to do a manual translation to get the expected values?
Thx!

How do you control the TM1638 discrete LEDS?

More TM1638 libraries I've seen have functions to drive the row of discrete LEDs that are along the top of the board. I don't see an equivalent in this library. Am I missing something?

reading data TM1620

hi @maxint-rd , regarding the process of reading through the code at the MCU, give me a note what i can do :

*i do with SPI slave, but it coming out data
0,64,191,32,190,190,16,80,241,64,2,3,0,0,
with 0.00Kg

TM1650.h compilation error

Found under Arduino 1.8.4, compiling for Wemos D1 mini. I was actually compiling TM16xxMatrixGFX_Ticker.ino for a TM1640 display, but the IDE wanted to build everything it found in the library's src directory:

In file included from /root/Arduino/libraries/TM16xx-master/src/TM1650.cpp:12:0:
/root/Arduino/libraries/TM16xx-master/src/TM1650.h:49:18: error: extra qualification 'TM1650::' on member 'receive' [-fpermissive]
virtual byte TM1650::receive();
^
exit status 1
Error compiling for board WeMos D1 R2 & mini.

Changing the line to:
virtual byte receive();

eliminated the error message. It should have no effect on function, but I have no way to test, since I don't have any TM1650 devices.

Problems with TM1618

Running this test code on a CA 7-segment display without dot:

#include <TM1618.h>

// GPIO I/O pins on the Arduino connected to strobe, clock, data,
#define  STROBE_TM PIN_PB3  // strobe = GPIO connected to strobe line of module.  PB3: Pin 8
#define  CLOCK_TM PIN_PB2   // clock = GPIO connected to clock line of module     PB2: Pin 9
#define  DIO_TM PIN_PB1     // data = GPIO connected to data line of module       PB1: Pin 10

// Constructors
TM1618 module(DIO_TM, CLOCK_TM , STROBE_TM);

void setup() {
  module.setupDisplay(true, 7);
}

void loop() {
  for (int i=0; i<=7; i++)
  {
    module.setSegments(1,i);
    delay(200);
    module.clearDisplay();
  }
}

Segments A, B, C and D are working correctly:
Segments A, B, C, D are connected to GRID1, GRID2, GRID3 and GRID4.

I get nothing on E, F or G.
Segment E is connected to SEG14/GRID5 pin
Segment F is connected to SEG13/GRID6 pin
Segment G is connected to SEG12/GRID7 pin

Checked with oscilloscope: Nothing on those 3 outputs.

image

Am I doing something wrong here?

Another TM1652 device

Hello, this is not an issue, but a message to report the usage of TM16xx library on a device.

The Xiaomi XIAO AI Smart Alarm Clock (product code: zimi.clock.myk01) features a nice 7-segments display with a TM1652 chip that drives it.

History:
I bought that alarm clock for 3€ on a flea market with the intention to hack/modify/replace the embedded linux sytem on its mainboard (ARM board). It has many fetaures I don't like: basically it's a black-box puppet computer controlled from mainland China's cloud with wifi, bluetooth gateway and microphone, AI assistant (like Google, Alexa) but that speaks chinese only, and it need a smartphone app to do anything else... I gave up the project to hack the mainboard, because no time nor brain slot available....

But the 7-segment display is really nice and I wanted to repurpose it. So I digged further this strange 1 pin controlled and found out the controller is TM1652, then a web search led me to this repository.

20231011_090610v2

Connections on the display are VDD - SDA - GND, connected on the mainboard to VCC - EN - GND. I measured working voltage to 4.6V.

So I reconnected the display to a tiny ESP32 board (Seeed Studio XIAO ESP32C3), and tested the display with "TM16xx_setSegments.ino" example. It does work, all segments are lighting up, except the middle colon.

20231012_102749v2

So now it's a repurposed as a simple NTP clock, without all the nasty stuff, and with a K.I.S.S. approach.
It connects to wifi just at start up and then once a day to sync time to NTP, then switch the wifi off. Low luminosity between 21h and 8h. Perfect for my mother bedroom.

20231011_235605v2

Thanks for TM16xx and the addition of TM1652

Initialization functions in constructors are causing undefined behaviour, crashes ESP32

When I upload TM1637 example sketches to the ESP32 Devkit V1, the program crashes with a watchdog reset. I already found the cause, and the fix. The problem is, the fix requires a big change to several example and driver files.

It's a simple issue, actually. In some of the constructors of inherited classes like TM1637, there is initialization code that uses 'micros()'. In the Arduino environment, you can not safely call system functions from a constructor, because 'init()' which sets up functions like that, does not run until just before setup(). The reason it runs on the AVR and not on the ESP, is because the behaviour of such functions is "undefined" and so can be processor dependent.

There are two global changes that have to be applied:

  1. All class constructors must be modified to remove all display initialization code.
  2. All example sketches must be modified to call setupDisplay() in setup() before any other display code is run, instead of depending on the constructor to do it.

I have already forked the library and tested the change locally, it is the only way to use the ESP32 (and possibly the ESP8266, not tested yet) with this display library. I'm able and willing to write the changes, but I thought I should invite some discussion first, as more than one file needs updating.

Request: Reverse Row and Segments

I am using a Common Anode 16 segment LED 4 digit, I would love to use this library.
I have it working by sending
setSegments(Digit number, Segment) so its reverse to normal, but I can't get a "font lookup table"
working where I can use setdisplay to string.

Is this a possible enhancement?

Compiling error TM1638 with ESP8266 Wemos D1?

I'm trying to use the examples with my wemos D1 and TM1638 board but I'm always get
"sketch/TM16xxMatrixGFX.cpp:8:26: fatal error: Adafruit_GFX.h: No such file or directory
#include <Adafruit_GFX.h>

                      ^

compilation terminated.
exit status 1
Erro ao compilar para a placa WeMos D1 R1."

Do you know what might be the problem?

TM1624

Will this code work with TM1624 led driver?

TM16xx without leading zeros issue

Hi,
I am using TM1650. when variable value is zero the display showing blank screen. This is happening when we select " Set the display to a decimal number without leading zeros", due to this issue I am unable to shown the zero number on the 7 segment display.

error: '_BV' was not declared in this scope

C:\Users\LocalAdmin\Documents\Arduino\libraries\TM16xx_LEDs_and_Buttons\src\TM1630.cpp: In member function 'virtual uint32_t TM1630::getButtons()':
C:\Users\LocalAdmin\Documents\Arduino\libraries\TM16xx_LEDs_and_Buttons\src\TM1630.cpp:77:31: error: '_BV' was not declared in this scope
77 | keys_K2 |= ((((received & _BV(1)) >> 1) | ((received & _BV(4)) >> 3)) << (2 * i)); // bit 1 for K2/KS3|5|7 and bit 4 for K2/KS2|4|6|8
| ^~~
C:\Users\LocalAdmin\Documents\Arduino\libraries\TM16xx_LEDs_and_Buttons\src\TM1628.cpp: In member function 'virtual uint32_t TM1628::getButtons()':
C:\Users\LocalAdmin\Documents\Arduino\libraries\TM16xx_LEDs_and_Buttons\src\TM1628.cpp:98:29: error: '_BV' was not declared in this scope
98 | keys_K1 |= (( (received&_BV(0)) | ((received&_BV(3))>>2)) << (2*i)); // bit 0 for K1/KS1 and bit 3 for K1/KS2
| ^~~
C:\Users\LocalAdmin\Documents\Arduino\libraries\TM16xx_LEDs_and_Buttons\src\TM1637.cpp: In member function 'virtual uint32_t TM1637::getButtons()':
C:\Users\LocalAdmin\Documents\Arduino\libraries\TM16xx_LEDs_and_Buttons\src\TM1637.cpp:107:9: error: '_BV' was not declared in this scope
107 | return(_BV((0xFF-received)&0x0F)); // return bit set for the button that is pressed (bits 0-15)
| ^~~
exit status 1

tm1680

is there any hope for creating and publishing a library for tm1680?
Thank you

Request: Flip 8x8 matrix

Hello, I am using two 8x8 dot matrix displays with TM1640. Due to my PCB design 8x8 matrices are flipped 90 degress counter clockwise.
Can I do something with code to correct the orientation? Thanks.

Display device compatibility testing with STM32 boards

I tested the TM1637 example sketch with a few different boards using STM32 series IC's. They are all 3.3V powered, so I also powered the TM1637 from the same 3.3V power. I used a somewhat arbitrary PB8 and PB9 for I/O. I tried first Blue Pill with the STMF103C8T6, it worked with this configuration:

OS - Windows 10 Home version 21H1
pins - 3.3V, gnd, PB8->DIO, PB9->CLK
display: DM 6 digit TM1637 (basically Robodyn clone)
IDE: Arduino 1.8.12
core: stm32duino core 2.1.0
test program: TM1637_extended

Subsequently, I went on to test an STM32F401CC, and STM32H705x and the display did perform the test up to a point. However, during this I went down a wrong path for a while, I think. I saw that the display just went blank after a while. Anxious about the hardware, I quickly shut it down and only realized later when looking at the test code, that it seems to actually do that. Is it true, at the end of the TM1637 test, it goes dark and samples keys?

For results, I am wondering if I should put it together more as a table or spreadsheet because it would facilitate keeping track of which pins are used, not just in the code, but also in a place where you can compare them all.

I made some previous modifications to the test program and had some after thoughts... one is to differentiate between "test" and "example" sketches. The examples do make good demonstrations, but for this testing I want something more purely test, along the lines of a factory test but simplified. It should include some burn in test - extended on, extended off and so on. Lacking light measuring instruments, a slower and more self labelling brightness change test. Inter segment shorts. Stuff like that. So I am building a generic test sketch, with a header file defining the target display, and the board/processor. I think it will make it easier to test the many boards that I have.

However, in the mean time, I intend to repeat the display tests of the F103, F401 and H705 with the distributed example sketch, and combine them in a table that I will put here.

I almost forgot to add - I received a TM1650 display today, and it ran with a modifed TM1650 sketch on the Blue Pill. It will also get a repeat and be added to the table.
But, unless I was wrong about the example sketch ending up blank, the current result is that those 3 boards passed, and that it's then highly likely that most of the almost 100 different variants would also pass.

Request: Function to flip 7-segment display

Hello, is it possible to add a fuction that flips the TM1637-based 7-segment 4-digit display, so the numbers (time) are showing as rotated 180 degrees? I'm building a timer that can be used/mounted in 2 positions, and would like to flip the display based on the value of the accelerometer's Z orientation. Thank you.

Example for setting dots in setDisplayToString?

Hi is it possible you can provide an example for setting dots in setdisplay to string?
I see it takes a word for setting dots as second parameter, but I'm not sure how to work that.
Ie what do I send to make dot 3 and 5 on?

regarding interfacing of tm1640

hey there
i am using TM1640 and controller used is esp32-s3
is there any way to interface with this ic.
from developer point of view does he/she need to develop from scratch as there are no APIs available for TM1640 with esp32-s3

whether there any other ic available to replicate this functionality as our basic requirement is to drive common anode.
platform used ESP-IDF.

There is also confusion regarding how you have implemented the interfacing as the two wire interface mentioned in datasheet is not I2C.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.