Using a 4 digit, 7 segment LED with Arduino

WP_20160316_22_25_00_Raw_LIDisplays.  I love them.  Pretty much anything that lights up is cool, but things that can display numbers, letters and other symbols are just awesome and making them work, even better.  One of the coolest things I remember from my childhood are seeing those red, seven segment displays. They became cool (and cheap) and showed up everywhere.  Newspapers and magazines would emulate the look in articles and stories and the ads. Science Fiction movies and tv shows ate them up.  They were everywhere.  Then…sometime in the late eighties…they sort of went away, in favor of LCD and other display tech.  Or, worse…they changed color!  But, for me, its’ those RED ones.

I just had to make something with those uber cool RED seven segments.  But, what? Well, why not a clock? Yeah, a clock.

So, I ordered one, four digit, seven segment display bar.  A Catalex.  Wow.

Well, the thing arrived and it looked cool. But, there was a problem…how the hell do I send it data?

It uses four pins: GND, VCC, DIO and CLK.

DIO and CLK can be any digital pins, that wasn’t the issue. My problem was how to do so in CODE.

A little bit of digging revealed a nice little library that worked great with the display. And, you can download it here.WP_20160316_22_24_45_Raw_LI

The trickiest part of the library is figuring out which digits go where.  Fortunately, it easy:

display.showNumberDec(number, show leading zero (true or false), number of digits, position)

Example:

display.showNumberDec(now.hour(),true,2,0);
display.showNumberDec(now.minute(),true,2,2);

The first line puts the hours in the left most digits and hours on the right most digits, starting at digit 2 (the numbering starts at zero) and with leading zeros, so 8:03 would display as 08 03.

The one thing I have not yet figured out is how to display the colon. It is there, but I have yet to turn the bloody thing on.

This is really nifty little display and was cheap…about two US dollars if you shop. I did not and paid nearly four bucks, but, it did not matter, I got it in a day, thanks to Amazon Prime.

Below is my early attempt at a clock.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
‪#‎include‬ <Wire.h>
#include “RTClib.h”
#include <Arduino.h>
#include <TM1637Display.h>

RTC_DS1307 rtc;

// Module connection pins (Digital Pins)
‪#‎define‬ CLK 2
#define DIO 3

// The amount of time (in milliseconds) between tests
#define TEST_DELAY 2000

TM1637Display display(CLK, DIO);

void setup () {

if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
}

if (! rtc.isrunning()) {
Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
display.setBrightness(0x0f);

// All segments on
display.setSegments(data);
}

void loop()
{
DateTime now = rtc.now();

display.showNumberDec(now.hour(),true,2,0);
display.showNumberDec(now.minute(),true,2,2);

delay(5000);

display.showNumberDec(now.month(),true,2,0);
display.showNumberDec(now.day(),true,2,2);

delay(5000);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s