What is the different between TM1637.h & TM1637Display.h ?

I am confused here, guys.
I am not a programmer, I am just someone how started to love Arduino. (couple of months ago I accidentally found it ... and started to learn.. when I have time :frowning: )

I wrote an IF-Statment based :smiley: "smart-bedroom-automatic-light" sketch and built the project itself.
However, I still need to working on it. That's why I left the prototype on my desk :slight_smile:

Because I used the display for the project (First 7 Segment Display) I needed to get another one.

I purchased this: Second 7 Segment Display
BUT it does not work on my project. It does not work on the test sketch that this library includes.
I have the library from here: Arduino Playground - TM1637

Are they two different (???) library maybe?

"TM1637.h" & "TM1637Display.h" ? Or are they not different at all?

If they are not different why is this new display not working with it?

Info: I have something downloaded called "seeed_grove_4digital_diplay_g-master" and in this library in the test sketch they used "TM1637.h" and if I upload it to Arduino then the Second 7 Segment Display is working!

This is the point where I am totally not getting it and I spent a time to find the answer but I am still not getting it.

Could someone please explain to me what I cannot see here?
Are they different or not...?
Why one display works with the same test sketch and other does not? :frowning:

Thank you so much!

Are they two different (? ? ?) library maybe?

If the authors followed convention, and named the file the same as the class, then they are two different libraries. What those differences are will be up to you to determine, as you are the only one that how both of them (or knows where you found them).

I totally appreciated your reply, thank you. However, does not help me a lot. :frowning:
I re-arrange my questions then.
Where can I find the original TM1637.h library? Because looks like this should be the one but not!
http://playground.arduino.cc/Main/TM1637

As that one in the sketch showing this: TM1637Display.h

So, and I even not sure I express myself well: Are they different?
Why is that, everywhere I go, I look, I will see in the helps and tutorials: "...use this library: TM1637.h"
But this f....ing library NO WHERE :slight_smile:

I only found the above linked (should be the one) library but it is NOT TM1637.h it is: TM1637Display.h
in the sketches.

Please explain to me because I am going to crazy :slight_smile: with it.. :slight_smile:

I know the problem is with me... I know as no one else complaining about it.
But then please, show me where I am wrong... :frowning:
Where is this fricking TM1637.h library ??? where? :slight_smile:

Last question: Why the "official above linked" library (TM1637Display.h) handling one of the display I have and why not works with the other one? ???

1000x THANK YOU! :slight_smile:

You didn't use code tags to post your code. It's important that you use them - if you don't, the forum software sometimes interprets sequences of characters in the code as directives to format text in some way. It won't display those sequences, and it will unexpectedly reformat the rest of the text. When that happens, and someone tries to copy your code and paste it into the IDE, it often throws an error, and readers will complain that the code fails to compile. Using code tags also makes it easier to read, and can be copied with a single mouse click.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, open it in a text editor, then copy it to the IDE. It's much easier to just view the code in your post.

The code tags make the code look

like this

when posting source code files.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the [code] and [/code] metatags.

When you are finished that, please read this post:

How to use this forum - please read.

Hi, I faced a problem with 2 types of display board with 2 library. At beginning, I used "CATALEX" label display board with "TM1637Display.h" on Wemos D1 mini. It worked OK. After that, I bought another batch of 4 digit display, but there is no "CATALEX" label . The board does not work with "TM1637Display.h" . I found "TM1637.h" then tested on Arduino UNO, it worked but does not worked on Wemos D1 mini .

After I searched a library worked on no "CATALEX" label on Wemos D1 mini, I found "SevenSegmentTM1637.h" . It works on "CATALEX" labeled board, too.

I made override class library for me to make compatible with "TM1637Display.h", which I used to use. I want to share the code with TM1637Display sample called "TM1637TEST". Maybe my coding is not good. You can modify by yourself if needed.

#include "SevenSegmentTM1637.h"


const uint8_t digitToSegment[] = {
 // XGFEDCBA
  0b00111111,    // 0
  0b00000110,    // 1
  0b01011011,    // 2
  0b01001111,    // 3
  0b01100110,    // 4
  0b01101101,    // 5
  0b01111101,    // 6
  0b00000111,    // 7
  0b01111111,    // 8
  0b01101111,    // 9
  0b01110111,    // A
  0b01111100,    // b
  0b00111001,    // C
  0b01011110,    // d
  0b01111001,    // E
  0b01110001     // F
  };

class TM1637Display : public SevenSegmentTM1637
{
   public :
     TM1637Display(uint8_t pinClk, uint8_t pinDIO);
     void setBrightness(uint8_t brightness, bool on = true);
     void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
     void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
     uint8_t encodeDigit(uint8_t digit);
     void showNumberDecEx(int num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
  };

     TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO) : SevenSegmentTM1637(pinClk, pinDIO)
     {
        SevenSegmentTM1637(pinClk, pinDIO);
     }

     void TM1637Display::setBrightness(uint8_t brightness, bool on)
      {
          uint8_t setDisplayCmd   = B10000000; // bit 6,7
          uint8_t brightnessBits  =      B111; // bit 0,1,2 (7 = max)
          uint8_t displayOnBit    =     B1000; // bit 3
          // construct complete command
          uint8_t command = setDisplayCmd | brightnessBits | displayOnBit;

         // turn display on and set brightness to max (7)
         bool ack = SevenSegmentTM1637::command(command);

         // write init to display using automatic address
         uint8_t setDataCmd      = B01000000;  // bit 6,7
         ack = SevenSegmentTM1637::command(setDataCmd);

        // setBacklight(brightness);

      }
     void TM1637Display::showNumberDec(int num, bool leading_zero, uint8_t length, uint8_t pos)
      {
        showNumberDecEx(num, 0, leading_zero, length, pos);
      }

     void TM1637Display::showNumberDecEx(int num, uint8_t dots, bool leading_zero, uint8_t length, uint8_t)
     {
      
      bool ack;
        
       uint8_t digits[4];
       const static int divisors[] = { 1, 10, 100, 1000 };
       bool leading = true;

       for(int8_t k = 0; k < 4; k++) {
      int divisor = divisors[4 - 1 - k];
      int d = num / divisor;
      uint8_t digit = 0;

      if (d == 0) {
        if (leading_zero || !leading || (k == 3))
           digit = encodeDigit(d);
        else
           digit = 0;
        }
     else {
       digit = encodeDigit(d);
       num -= d * divisor;
       leading = false;
     }
    
     // Add the decimal point/colon to the digit
     digit |= (dots & 0x80); 
     dots <<= 1;
    
     digits[k] = digit;
   }

   uint8_t commands[5];
   commands[0] = TM1637_COM_SET_ADR|B0000000;
   commands[1] = digits[0];
   if(dots!=0) {
     commands[2] = digits[1]|B10000000;
   } else {
     commands[2] = digits[1];    
   }
   commands[3] = digits[2];
   commands[4] = digits[3];

   ack = SevenSegmentTM1637::command(commands, 5);

     }

      void TM1637Display::setSegments(const uint8_t segments[], uint8_t length, uint8_t pos)
      {
        uint8_t commands[5];
        commands[0] = B11000000+pos;
        commands[1] = segments[0];
        commands[2] = segments[1];
        commands[3] = segments[2];
        commands[4] = segments[3];


        TM1637Display::command(commands,length+1);
      }
      
uint8_t TM1637Display::encodeDigit(uint8_t digit)
{
  //return SevenSegmentTM1637::encode((int16_t) digit)
  return digitToSegment[digit & 0x0f];
}

#define SEG_A   0b00000001
#define SEG_B   0b00000010
#define SEG_C   0b00000100
#define SEG_D   0b00001000
#define SEG_E   0b00010000
#define SEG_F   0b00100000
#define SEG_G   0b01000000


#define TEST_DELAY   2000
const uint8_t SEG_DONE[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,           // d
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
  SEG_C | SEG_E | SEG_G,                           // n
  SEG_A | SEG_D | SEG_E | SEG_F | SEG_G            // E
  };



/*  Above is class definition to be replaced with #include "TM1637Display.h" */



const int CLK = D2; //Set the CLK pin connection to the display
const int DIO = D3; //Set the DIO pin connection to the display



TM1637Display display(CLK, DIO); //set up the 4-Digit Display.




void setup()
{
}


void loop()
{
  int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  display.setBrightness(0x07);

  // All segments on
  display.setSegments(data);
  delay(TEST_DELAY);

  // Selectively set different digits
  data[0] = 0b01001001;
  data[1] = display.encodeDigit(1);
  data[2] = display.encodeDigit(2);
  data[3] = display.encodeDigit(3);

  for(k = 3; k >= 0; k--) {
  display.setSegments(data, 1, k);
  delay(TEST_DELAY);
  }

  display.setSegments(data+2, 2, 2);
  delay(TEST_DELAY);

  display.setSegments(data+2, 2, 1);
  delay(TEST_DELAY);

  display.setSegments(data+1, 3, 1);
  delay(TEST_DELAY);


  // Show decimal numbers with/without leading zeros
  bool lz = false;
  for (uint8_t z = 0; z < 2; z++) {
  for(k = 0; k < 10000; k += k*4 + 7) {
    display.showNumberDec(k, lz);
    delay(TEST_DELAY);
  }
  lz = true;
  }

  // Show decimal number whose length is smaller than 4
  for(k = 0; k < 4; k++)
  data[k] = 0;
  display.setSegments(data);

  // Run through all the dots
  for(k=0; k <= 4; k++) {
    display.showNumberDecEx(0, (0x80 >> k), true);
    delay(TEST_DELAY);
  }

  display.showNumberDec(153, false, 3, 1);
  delay(TEST_DELAY);
  display.showNumberDec(22, false, 2, 2);
  delay(TEST_DELAY);
  display.showNumberDec(0, true, 1, 3);
  delay(TEST_DELAY);
  display.showNumberDec(0, true, 1, 2);
  delay(TEST_DELAY);
  display.showNumberDec(0, true, 1, 1);
  delay(TEST_DELAY);
  display.showNumberDec(0, true, 1, 0);
  delay(TEST_DELAY);

  // Brightness Test
  for(k = 0; k < 4; k++)
  data[k] = 0xff;
  for(k = 0; k < 7; k++) {
    display.setBrightness(k);
    display.setSegments(data);
    delay(TEST_DELAY);
  }
  
  // On/Off test
  for(k = 0; k < 4; k++) {
    display.setBrightness(7, false);  // Turn off
    display.setSegments(data);
    delay(TEST_DELAY);
    display.setBrightness(7, true); // Turn on
    display.setSegments(data);
    delay(TEST_DELAY);  
  }

  // Done!
  display.setSegments(SEG_DONE);

  while(1);
}

Hi - Slightly unrelated, but has anyone gotten the decimal point to work? i am using the tm1637 part in

this display, and trying all the various tm1637 libraries does not light up the dp. any help would be greatly appreciated. thx
-yurij

Hi, I think the TM1637Display.h is to more or less official library. It looks like TM1637 is for the Grove 4-Digit Display at Grove - 4-Digit Display | Seeed Studio Wiki. Probably pretty interchangeable but the seeedstudio version isn't documented very well and has different functions driven at the display being a clock, stopwatch, etc.

If you go to Documents/Arduino/Libraries you will see them both installed there and can go into the .h files to see the various functions that are available. I have been struggling with the decimals as well but I will let you know if I get it to work.

Hi my brother ,after many attempts ,I used "TM1637Display.h" from the link below:

and its work well