Giter Club home page Giter Club logo

tm1637's Introduction

TM1637

Arduino library for TM1637 (LED Driver)

Description

An Arduino library for 7-segment display modules based on the TM1637 chip, such as Seeed Studio's Grove 4 digit display. The TM1637 chip also has keyboard input capability, but it's not implemented in this library.

Hardware Connection

The display modules has two signal connection (and two power connections) which are CLK and DIO. These pins can be connected to any pair of digital pins on the Arduino. When an object is created, the pins should be configured. There is no limitation on the number of instances used concurrently (as long as each instance has a pin pair of its own)

Installation

The library is installed as any Arduino library, by copying the files into a directory on the library search path of the Arduino IDE

Usage

The library provides a single class named TM1637Display. An instance of this class provides the following functions:

  • setSegments - Set the raw value of the segments of each digit
  • showNumberDec - Display a decimal number
  • showNumberDecEx - Display a decimal number with decimal points or colon
  • setBrightness - Sets the brightness of the display

The information given above is only a summary. Please refer to TM1637Display.h for more information. An example is included, demonstrating the operation of most of the functions.

tm1637's People

Contributors

avishorp avatar jsdevel avatar kasoo avatar mcauser avatar mortenfyhn avatar per1234 avatar rolkwo avatar smartblug avatar smougenot 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tm1637's Issues

showDots for letters

We have showNumberDecEx which is great for showing dots and such for numbers. It would be nice to expose showDots or something for letters. Any plans on doing so?

GPIO not doing anything.

Hello, I have used your libary without a problem for quite a long time.

But just two days ago for seemingly no reason it just stopped displaying data. I am shifting 3,3v of the bluepill board to the 5v display and it has always worked. I even get a nice light up of the shifting LEDs when the pins are sending bits. They arent lighting up anymore showing me its not the fault of the display.

To get it even more confusing I happened to have a old version of my program on a different stm32. I simply plugged it in and it works. Problem is there isnt a single difference in my code.

I have checked multiple times and built new projects just to test the display but all I can guess is a problem with some update for the stm32 framework?

I feel im in a dead end here, thanks for all and any input or advice!

No Display

I've tried all the test codes, and I cant get any of them to work, I've used SevenSegmentTM1637 and this works fine but I would prefer to use your smaller .h .cpp
I'm using a UNO with CLK 4, DIO 5
Anyone had this problem and found a fix.

decimal dot

// note to .cpp file:
//
// A
// ---
// F | | B
// -G-
// E | | C
// --- . = X
// D
//

// .cpp added code for to show a decimal dot:
void TM1637Display::showNumberDecDot(int num, bool leading_zero, uint8_t length, uint8_t pos, int decimal_dot_place)
{
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;

    if (d == 0) {
      if (leading_zero || !leading || (k == 3))
        {
     digits[k] = encodeDigit(d);
     if (decimal_dot_place==k)
     digits[k] += 0b10000000;
    }
      else
        digits[k] = 0;
     if (decimal_dot_place==k)
     digits[k] += 0b10000000;
    }



    else {
        digits[k] = encodeDigit(d);
        num -= d * divisor;
        leading = false;
     if (decimal_dtot_place==k)
     digits[k] += 0b10000000;
    }
}

setSegments(digits + (4 - length), length, pos);

}

//.h file description added:
void showNumberDecDot(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0, int decimal_dot_place = 5);
//! @param decimal_dot_place - show decimal dot on selected segment

show or hide colon

Hi! I want create watch with flashing colon every second, do you make create public method: void showDots(uint8_t dots = 0) ?
Now if I want show/hide colon without change digits, I use showNumberDecEx() and digits has lags.

Brightness protocol

I noticed the brightness in the example being used differently than the header file mentions, so to clarify this is what I've found through testing.

COM3 = 0x8X (First 4 bits indicate the brightness command)

Next four bit structure:
Bit 1 = Display on/off
Bit 2 - 4 = Unsigned integer between 0 and 7

0XXX = Display off
1000 = Display brightness 1 (lowest)
1001 = Display brightness 2
...
1111 = Display brightness 8

My current code to reflect this looks like:

//! Sets the brightness of the display.
//!
//! The setting takes effect when a command is given to change the data being
//! displayed.
//!
//! @param brightness A number from 0 (Off) to 8 (highest brightness)

void TM1637Display::setBrightness(uint8_t brightness)
{
  if(brightness > 0){
    m_brightness = ((brightness - 1) & 0x07) | 0x08;
  } else {
    m_brightness = 0x00;
  }
}

show colon (colon only display)

Hi
I am trying to show the time on my display without a leading zero in the minute column.
When I use the following code

uint16_t time = (mins * 100) + secs;
myLeds.showNumberDecEx(time, colon, true);

The colon displays when time is 00:00.
When I use the following code

  myLeds.showNumberDecEx(mins,colon,false,2,0);
  myLeds.showNumberDecEx(secs,colon,true,2,2);

the colon only gets displayed if either mins is greater than 0, or I set show leading zeros to true.

I would like to display 0:00, can you please advise me

Regards
Paul

support for mcp23017

Would be nice to be able to use this library with an MCP23017 expander. Something like https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library and a class where I can pass in the mcp instance that this library would call on instead of using the global pinMode. One of their examples:

Adafruit_MCP23017 mcp;
  
void setup() {  
  mcp.begin();      // use default address 0

  mcp.pinMode(0, INPUT);
  mcp.pullUp(0, HIGH);  // turn on a 100K pullup internally

  pinMode(13, OUTPUT);  // use the p13 LED as debugging
}

void loop() {
  // The LED will 'echo' the button
  digitalWrite(13, mcp.digitalRead(0));
}

multiple displays?

I am trying to find a way to use multiple tm1637 displays with different outputs. Is there a way to do this?

Support 6 digit displays

The TM1637 can support 6 seven segment displays but this library only properly supports 4 digits.

Not the expected results

I'm using the following code and the values between Serial and TM1637 are different.
long rssi = 0; rssi = WiFi.RSSI(); Serial.print("\tsignal strength (RSSI):"); Serial.println(rssi); display.showNumberDec(rssi);
TM1637 is showing 98
Serial is showing -78
RSSI has different ranges depending on a manufacturers preference, for the ESP8266 (NodeMCU) that I'm using the standard range is apparently 0 to -120 where signal drops out around -99 and is impossible to obtain at -120. So I assume that -78 is the correct value based on the distance from my router.

I'm wondering if there is a bug in how negative numbers are handled in the TM1637 library?

Propositions (and code) for new functions

Hello,
First of all, thank you for this library which allows us to use TM1637-based displays. While studying this library, it seemed to me that it was not very easy to display basic data without taking care about their formatting. So I developed an extension for your library for my personal use. As it works well, I suggest that you make it available to everyone by integrating it into your own code. A simple copy and paste and a small optimization should suffice. I didn't know C++ at all before that, so there must be some optimizations to be made.
That extension adds these functions:
-> SEG_mot // SIZE_mot : these constants define the words to be displayed with the display_message function.
-> display_message(const uint8_t segments[], int size) displays a message on the display.
-> bool display_number(double number, int ndecdigits = -1) displays a number with or without decimal part. If optional ndecdigits is defined, the number of digits after the decimal point will be fixed at this value.
-> bool display_seconds (unsigned long time, int base_seconds = 60) displays a value with seconds and hundredths of seconds from a timestamp (millis() for instance). base_seconds is used to know at which value the seconds restart start from zero.
-> bool display_minutes (unsigned long time, int base_minutes = 60) displays a value with minutes and seconds. base_minutes is used to know at which value the minutes start again at zero.
-> bool display_heures (unsigned long time, int base_hours = 24) displays a value with hours and minutes. base_hours is used to know at which value the hours start from zero.
-> void display_all(uint8_t segment) is only used to display the same value on all displays. This can be used to test them or simulate an initialization sequence.
I am at your disposal to translate the comments if you have any problems with French.
Feel free to modify and use it as you want.

TM1637Evo.zip

Central Colunm Activation

Hello friends.
First of all I would like to thank you for the wonderful work you have done.
I am using a library developed by you on a personal project of a clock.
However, I am not able to activate the central column of the display. I'm using version 1.1.0 of the library. I noticed that there is no implementation for the "point" method: display.point (POINT_ON); Display.point (POINT_OFF);
can you help me?

Thank you.

Showing a colon

Hello folks,

so I'm building a digital clock using the ds1307 RTC module, and everything works fine, except the issue that there's no colon or a dot showing in between hours and minutes. Is there a way that I can solve this.
Thanks in advance!

Reimplementation to get rid of small annoyances

Not really an issue, I'm just abusing this to send you a message. :)

First, thanks for the library. I used it a lot.

It however has several small glitches that I tried to fix, like setBrightness not taking effect immediately, not working with negative numbers, the colon at the center of the display can't be set without setting the second digit etc. I found that improving this would be difficult (or sometimes impossible) because the library does not store the content of the display. I ended up basically reimplementing the library, keeping only the low-level functions for communication with TM1637.

I also changed the behaviour and/or signature of several methods, I removed some and added some, so my version is no longer compatible with your original. Thus I renamed it, so I can have both and still use my older projects (and project from others).

I'd create a pull request here, but my code is too different and I don't even know whether you want this functionality at all. So I'm writing this just to inform you of my fork, https://github.com/janezd/Led7Segment from which you can perhaps backport something useful to your original library. In particular, showNumber may be interesting.

Blink Display

hi
thanks for your useful library.
i tried to make blink function in my sketch by display.setbritness() function but i failed.
could you help me please?

Including wrong header file when using Library Manager for Arduino

I encountered a little error while importing the library using the default Arduino Library Manager.
If you install and include the library it said "#include <TM1637.h>" but the header file is called TM1637Display.h

It can be fixed by editing the library.properties file and change the line "includes=TM1637.h" with "includes=TM1637Display.h"

After that reopen the Arduino Project and include the library again, and it will call the correct header file.

Little issue showing colon

I found a little issue with the library. When you try to show num = 0 without leading zeros, with something like this:
display.showNumberDecEx(hour, dospuntos, false, 2, 0);
colon is not longer shown.
To solve this I added the following in line 148 of TM1637Display.cpp:
if(dots != 0) { showDots(dots, digits); }
I used the library with a MSP430G2553 and it works fine. It's really very versatile.

Serial.parseInt(); stops. Cannot send input to serial monitor via keyboard.

After running this sample code I got from youtube, the serial monitor stops accepting input in the serial monitor:

#define TimeInSeconds(_time_) ((_time_ / 1000) % 60)
#define TimeInMinutes(_time_) (((_time_ / 1000) / 60) % 60)

#include <Arduino.h>
#include <TM1637Display.h>

// Constants

const uint8_t OFF[] = {0, 0, 0, 0};
const uint8_t PLAY[] = {B01110011, B00111000, B01011111, B01101110};

int serialInput = 0;

unsigned long timeLimit = 3600000;

TM1637Display display(2, 4);

// Setup
void setup() {
Serial.begin(9600);
delay(5000);
display.setBrightness(0x0c);
display.setSegments(OFF);
}

// Main loop
void loop() {
if(Serial.available()){
serialInput = Serial.parseInt();

switch(serialInput){
case 1:
Serial.println("Ready For Station One.");
break;
case 2:
Serial.println("Ready For Station Two.");
break;
case 3:
Serial.println("Ready For Station Three.");
break;
case 4:
Serial.println("Ready For Station Four.");
break;
}
}
countdown();
}

void countdown() {
unsigned long timeRemaining = timeLimit - millis();

while(timeRemaining > 0) {

int seconds = TimeInSeconds(timeRemaining);
int minutes = TimeInMinutes(timeRemaining);

display.showNumberDecEx(seconds, 0, true, 2, 2);
display.showNumberDecEx(minutes, 0x80>>3, true, 2, 0);

timeRemaining = timeLimit - millis();
}
}

Is there anything wrong with the code implementation? Or I'm just using it incorrectly? Thanks in advance for the correction.

"d" not encoded correctly in TM1637Display.cpp

corrected below ...

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 // corrected DBM Mar 26 14
0b01111001, // E
0b01110001 // F
};

Using native I2C bus on MKR1000

  • Your library asks for two of the eigth general purpose I/O pins which, I suppose, will be used as a software emulated I2C port. Is there any way to use the native I2C port of the processor, on pin labelled "SCL" and "SDA" which do not have a "pin" number in the arduino sense, but are pins 13 and 14 on the MKR1000 socket and pins 38, 39 of the Atmel ATSAMW25H18 processor.
  • I suppose also that there are some other Arduino boards with native I2C. Using it will be faster and will save other GP I/Os ...

colon display when not showing leading zeros and the value is 0

I use a 4-digid display with a single colon in the center. The colon is not displayed when I have the leading zeros parameter set to false, and the value is zero.

red.showNumberDecEx(hour(), 0b11111111*(second()%2), false, 2, 0);
red.showNumberDec(minute(), true, 2, 2);

It works correctly for any other value than zero, but if hour() in the above example is 0, the colon does not show. This seems to me like a small bug.

Library not recognized in Arduino IDE

Arduino IDE will not install the library using install from Zip. In addition, even after manually adding the library to the libraries folder, Arduino IDE does not recognize the library.
The Issue can be solved by adding the following line to the library.properties file:

maintainer=

See the pull request Add maintainer field to library.properties

Support for 6 digit displays

I have some 6 digit versions of the TM1637 and wondering if the library can support this with minimal changes?

read button

hi,is that possible to read a key(high or low) by tm1637 using this library?
if answer is no,is that possible to add this to library?
thank you

Turn Display Off?

I'm having trouble blanking the display. I've tried sending an empty array with setSegments but it just crashes

MKR1010 pinMode INPUT doesn't work

I tried this library, but doesn't work with MKR1010.
I use the pin A3 and A4 to CLK and DIO, and the display module include 10K pull up resistor and 100p capacitor on both channel.
I verified the CLK and DIO with oscilloscope, and it is not able to pull up to Vcc in this speed.
I have two choice, one of them to decrease the speed or change the pinMode to digitalWrite.
The digitalWrite solved our problem.

Bad owerflow math

function SetTimer
Was:
Clock = (hours * 3600) + (minutes * 60) + (seconds % 60);
Should be:
Clock = (hours * 3600) + ((minutes % 60) * 60) + (seconds % 60);
because otherwise input:
T.SetTimer(0, 60, 0);
returns
2 hours 0 minutes 0 seconds

Default bitDelay() of 50us is too fast for some devices.

The default bitDelay() of 50 microseconds is too fast for some TM1637-based devices.

I suggest a lower default, and perhaps comments in the code/example to suggest using faster values if the device can take it.

Tested using generic device off ebay. Genuine Arduino Micro and Uno, and RFDuino Duemilanove.

Enabling the decimal point

Hi - First, thank you for writing this driver. Alot of work, little reward.
I am using a flavor of the tm1637 IC, the ebay item is
https://www.ebay.com/itm/112674024638?ViewItem=&item=112674024638
the LED has both the colon and the decimal points (there are number of flavors with either or, this has both).
I can get the colon to work, but not the decimal point no matter what I have for the "dots" parameter, including all lit.
I am using the Wemos D1 esp8266 module if that makes any difference, and I needed to use 100us for the bitDelay to get this to work at all. the 50 that you had in your library did not work.
Many Thanks
-yurij

Test case fail "expect 04__"

The test sketch line:
display.showNumberDec(4, true, 2, 2); // Expect: 04__

Fails to display properly. Instead __04 displays.

Arduino 1.8.8. Linux x86_64 Fedora 29. Library version 1.2.0 installed via the Library Manager. Board esp8266 based "NodeMCU 1.0 (ESP-12E Module)" supported from "esp8266 by ESP8266 Community" version 2.5.0.

Let me know if you can't reproduce.

Clocking out the LSB first?

This is a clean, well-written library. But one thing I do not understand.

While sending data to TM1637, is there a reason you are clocking out the LSB first, and not the MSB? I was under the impression that the TM1637 interface is essentially I2C, which clocks out the MSB first.

// 8 Data Bits
  for(uint8_t i = 0; i < 8; i++) {
    // CLK low
    pinMode(m_pinClk, OUTPUT);
    bitDelay();

	// Set data bit
    if (data & 0x01)
      pinMode(m_pinDIO, INPUT);
    else
      pinMode(m_pinDIO, OUTPUT);

    bitDelay();

	// CLK high
    pinMode(m_pinClk, INPUT);
    bitDelay();
    data = data >> 1;
  }

Have you tested this code with an actual TM1637? I assume that you have.

add `showNumberHex()` method

with the same param of the void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0) method, add a new showNumberHex() to show Hex Numbers for maxi 4 digits.

I would try to do it, but i'm not shure of the result ...

Enable colon

i'm making an extremely simple clock but i cant figure out how to light the colon.
heres my code:

#include <TM1637Display.h>
#define CLK 4 //can be any digital pin
#define DIO 5 //can be any digital pin
TM1637Display display(CLK, DIO);

int hours = 6;      //set these to 
int minutes = 40;   //whatever time it is
bool am = false;    //define if its am or pm
const int led = 6;  //am/pm led indicator pin

void setup() {
}

void loop() {
  display.setBrightness(1);
  display.showNumberDec(hours * 100 + minutes, false, 4, 0);
  minutes += 1;
  if (minutes >= 60)
  {
    minutes = 0;
    hours += 1;
  }
  if (hours >= 12)
  {
    hours = 1;
    if (am == true)
    {
      am = false;
    }
    else
    {
      am = true;
    }
  }
  if (am == true)
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }
  delay(60000); //60 seconds
}

the following code works to enable the colon:

uint8_t segto;
int value = 1244;
segto = 0x80 | display.encodeDigit((value / 100)%10);
display.setSegments(&segto, 1, 1);

but i cant figure out how to change the number being displayed

Multiple instances used concurrently.

Hi, thanks for your great library which I have been using successfully.
My only issue, which is probably not really an issue, just my ignorance, is that I can't seem to create multiple instances so that I can use more than one 4 digit displays as you describe...

Dots and leading zero

It's the simple question - Why dots? Usually dots separate integral and fractional parts of a number. Current library understand only integer numbers. For this reason we have to prepare numbers for display and convert fractional part to integer number. We have to manipulate with dots in parallel flow. And control how many fractional digits we want to display and where is the dot.
It was an lyric introduction in trouble. A example: I want to show numbers with 2 fractional digits like that 1.25 without leading zero. And if I have to show totally zero result in the same format I'm waiting for 0.00. But library show just one zero in right position and not sowing dot. In kind of time without leading zero we waiting 0:00 on display.
Simple way to make it possible and save backward compatibility is to convert boolean leading zeros to byte to make it possible describe how many zeros to show.

TM1637 not working

i just got a TM1637 to use with my arduino, but it's not working. none of the displays are showing any segments lit. (the led on the back is lit) an article online suggested that removing two capacitors from the backside may fix this problem, i have done so to no avail. please help me.

Digispark ATtiny85

I've used your code on a NodeMCU, but I'm having trouble on a Digispark ATtiny85. I'll be debugging this weekend, but in the meantime I thought I'd ask if you've have the opportunity to test on the digispark attiny85 hardware.

There are two form factors; a male usb header, and a female micro usb header. I have the microusb header like this one:
https://www.aliexpress.com/item/Mini-ATTINY85-Micro-USB-Development-Board-for-Digispark-Kickstarter/32658933669.html?spm=2114.13010608.0.0.vQXWLx

first two digits are buggy

Hey, I got the module 3642BH.
In my first test the function setNumberDec having length=4 and pos=0 just works proberbly. But after I tried length=1 or length=2 and pos=0 or pos=1 the given (one digit) number will be always displayed on the first two digits repeated.
That applies also for the setSegment function.

In my observations I saw this behaviour only for the first and second display digits.

Incorrect use of GPIOs

Hey, thanks for the lib. However, you are using the incorrect functions for the GPIOs: instead of using the functionality for setting pins high/low, you are setting them as input/output. This should only be done for the SDA-pin when waiting for an ACK. I think the arduino-functions for setting the output low or high is digitalWrite().

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.