Yesterday, I got a small 4 digit, 7 segment LED display board in the mail from dx.com. Cost was around $3 shipped, and the module uses a 4 pin interface (power, ground, clock and data). Originally, I thought it was I2C, but like other modules I have received based upon chipsets made by Titan Micro (using the TM1638 and TM1640) it looks superficially like I2C, but doesn’t use the open collector bus and addressing scheme of I2C. You end up clocking commands to the board using two dedicated pins.
The driver that I’m using comes from here. It is based upon the driver from avishorp, but includes support for the colon that separates the two pairs of digits on this display, which I wanted to allow blinking to help indicate that the clock was running. This was my example sketch, which is completely unremarkable. It doesn’t set the time from a real source, I just hard coded it to set the time to a specific constant near when I compiled it.
[sourcecode lang=”cpp”]
#include <Time.h>
#include <TM1637Display.h>
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
setTime(1432823831UL);
display.setBrightness(0xF);
}
boolean colon = true ;
void loop() {
// put your main code here, to run repeatedly:
int t = hour() * 100 + minute() ;
display.setColon(colon);
colon = !colon ;
display.showNumberDec(t, true);
delay(1000) ;
}
[/sourcecode]
It works reasonably well.
Addendum: I received this tweet:
@brainwagon A cute RTC library hack I learned while doing my little toy clock: rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
— Josh Myer (@xek) May 28, 2015
Not a bad little trick to archive. Instead of using the Time library, you need to use the RTClib library. I modified my program above to do it. Here’s the new version:
[sourcecode lang=”cpp”]
#include <Wire.h>
#include <RTClib.h>
#include <TM1637Display.h>
RTC_Millis rtc;
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);
void setup() {
Serial.begin(9600);
display.setBrightness(0xF);
rtc.begin(DateTime(F(__DATE__), F(__TIME__))) ;
}
boolean colon = true ;
void loop() {
DateTime now = rtc.now() ;
int t = now.hour() * 100 + now.minute() ;
;
display.setColon(colon);
colon = !colon ;
display.showNumberDec(t, true);
delay(1000) ;
}
[/sourcecode]
Note: the time gets set to the time when the code is compiled. If you compile and install it, it will likely be a couple of seconds off. And when the Arduino gets reset, it will get reset to that same time. This is most useful in setting the time on an external time keeping module.
error code, This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: “Arduino Uno”
sketch_jun02b.ino: In function ‘void loop()’:
sketch_jun02b:24: error: ‘class TM1637Display’ has no member named ‘setColon’
sketch_jun02b:27: error: expected `}’ at end of input
You have to use the version of the library at this link. Some others don’t support the “setColon” call. https://github.com/chamie/TM1637
Please, help me ….
error: ‘class TM1637Display’ has no member named ‘setColon’
https://github.com/chamie/TM1637 ….. installed´,