TM1637.h & DS3231 - Blank Digit?

I'm displaying clock information on a 7-seg (TM1637) display. I am using the old TM1637.h library. When the hour is a single digit, does anyone know how I can blank out the "0" position on the display? The example code leaves a '0' visible under such cases -- like '07:37' and I want to show, ' 7:37'.

#include <Arduino.h>
#include "TM1637.h"
#include <Wire.h>
#include <RTClib.h>
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>

RTC_DS3231 rtc;
int hh,mm;

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

TM1637 tm1637(CLK, DIO);

// include SdFat for FAT32 support with long filenames; available through Library Manager
#include <SdFat.h>
SdFat SD;

// select the display driver class (only one) for your  panel
#define GxEPD2_DRIVER_CLASS GxEPD2_420     // GDEW042T2   400x300

#if defined(__AVR)
#define SD_CS 4  // adapt to your wiring
#define EPD_CS 10 // adapt to your wiring
GxEPD2_DRIVER_CLASS display(/*CS=10*/ EPD_CS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7);
#endif

#include "GxEPD2_SD_AVR_boards_added.h"

// function declaration with default parameter
void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color = true);

void setup()
{
  
  tm1637.init();
  tm1637.set(1); // 7=brightest
  
  Serial.begin(115200);
  Serial.println();
  Serial.println(F("setup"));

  display.init(115200);

  Serial.print(F("Initializing SD card..."));
  if (!SD.begin(SD_CS))
  {
    Serial.println(F("SD failed!"));
    return;
  }
  Serial.println(F("SD OK!"));

 // drawBitmaps_other();
 
 rtc.begin();
  // When time needs to be re-set on a previously configured device, the
  // 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));

} // End Setup loop

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

    hh=now.hour(),DEC;
   mm=now.minute(),DEC;

  if (hh >=13){ // keep to twelve hour time
    hh=hh-12;
    }

    tm1637.display(0,hh/10);     // hour
    tm1637.display(1,hh%10);    //
    tm1637.display(2,mm/10);    // minutes
    tm1637.display(3,mm%10);    // 

    
 if (now.second()%2 ==0){   // blink the colon
            tm1637.point(POINT_ON);
            } else {
            tm1637.point(POINT_OFF);
            }


} // end loop

I don't know what "the old" version of the library is. If it is old you should provide a link or the
*.h and the *.cpp file.

somewhere inside the TM1637-library must be defined the on/off-pattern for each digit.
You would have to add a "digit" with all segments switched off or using a "character"-digit like "C" and define all segements being off.

or to change the logic if the hour is smaller than 10 start with "second" digit.

The new version of the TM1637Display.h-library has a method clear that works this way

void TM1637Display::clear()
{
uint8_t data[] = { 0, 0, 0, 0 };
setSegments(data);
}
all four segments are set to zero. A leading "space" means to set
data[0] = 0; to keep all segements switched off

best regards Stefan

The Avishorp library (and others) have a leading zero print function. Just use one of them.
https://github.com/avishorp/TM1637
or use a library that overloads the print method and print a C string constructed with sprintf().
https://github.com/maxint-rd/TM16xx

By 'old', I meant the original library as there are newer TM1637 library options these days. But, I get a compile conflict with the TM1637Display.h and the GxEPD2 library (to display bmps off an SD card to ePaper display). Both libraries use similar command calls as in: display.XXX and I think it buggers up the two libraries. Catch my drift? I could post the error perhaps.. but TM1637.h uses: tm1637.display(XXX) commands and doesn't cause a conflict with GxEPD2 library. I need either a way to clear the display or write a blank digit.

I'll check out those Avishorp options, but I did try sending a '99' to see of it would blank but that didn't work.

No it does not bugger up the code.
You use the functions with a preceeding instance-name

tm1637.display

The part "tm1637" of the function call ensures 101% that the right "display" function is used.
That is the reason why you have to write
tm1637.display(...
instead of just "display(.."

If you post the compiler-error-messages as a code-section the experienced users here can point you to a problem.
So give it a try. And if a compiler-error occurs click on copy to cliboard-button and then paste the whole compiler-messages into a code-section.

best regards Stefan

Then you screwed up.

@anon57585045
@StefanL38

Can you recommend a decent resource for gaining the basics in Arduino coding? Are you fellows coming from a background in C/C+? I looking for something a little more than Simon Monks books. This process is hackneyed and I end up getting carved for posting questions which are probably pedestrian.

my main background is pascal/delphi
a lot of things are all common in programming languages like delphi/C++/python/java etc. Though there are differencies.

I'm coding with C++/Arduino now for 1.5 years.
I haven't read any book from Simon Monk. So I don't know how "basic" they are

I haven't read much on this website but it loks like a decent ressource
https://www.learncpp.com/

the very very basics are covered here

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. This course goes not as deep as using multiple libaries and what naming conventions should be used. So do a crossreading of a chapter you are interested in.

best regards Stefan

@argg

Just sent a '99' - I get a funny character like an 'h' with a flag.
tried sending a '999' - I get a, "0".

The line I send is, for example:
tm1637.display(0,999);

This gives me an '8':
tm1637.display(0,"99");

Now if the display has been off and I don't run anything to position 0, it stays blank. But if I cycle numbers that are 3 digits (Pos 1,2,3) and 4 digits (Pos 0,1,2,3) then the digit remains from the last display of four digits.

What am I doing wrong then?

(Thanks Stefan! Appreciate your help!)

You're not reading the documentation. Edit - or the example sketches that come with the library.

Hello

Why use an old version? Just update to latest version.

I am using the Grove 4-digit display library, TM1637.h. There are three example sketches: Clock Display, Number Flow and Stopwatch. The first two sketches show NOTHING about casting a blank digit. The third example sketch doesn't appear to show either but I can't run the damn thing because of a compile error - enclosed. I am using this library for reasons above.

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

C:\Users\cdrei\Documents\Arduino\libraries\Grove_4-Digit_Display\examples\Stopwatch\Stopwatch.ino: In function 'void stopwatchStart()':

Stopwatch:119:20: error: 'unsigned char TimerOne::clockSelectBits' is private within this context

   TCCR1B |= Timer1.clockSelectBits;

                    ^~~~~~~~~~~~~~~

In file included from C:\Users\cdrei\Documents\Arduino\libraries\Grove_4-Digit_Display\examples\Stopwatch\Stopwatch.ino:33:0:

C:\Users\cdrei\Documents\Arduino\libraries\TimerOne/TimerOne.h:157:26: note: declared private here

     static unsigned char clockSelectBits;

                          ^~~~~~~~~~~~~~~

exit status 1

'unsigned char TimerOne::clockSelectBits' is private within this context

Invalid library found in C:\Program Files (x86)\Arduino\libraries\Arduino: no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\Arduino

Invalid library found in C:\Program Files (x86)\Arduino\libraries\Tone32: no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\Tone32



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

type or paste code here

Looking at the library, the clearDisplay function is the following:

void TM1637::clearDisplay(void)
{
  display(0x00,0x7f);
  display(0x01,0x7f);
  display(0x02,0x7f);
  display(0x03,0x7f);
}

That gives you the individual function calls to blank each digit, so something like this:

  if ((hh / 10) == 0) {
    tm1627.display(0, 0x7F);
  } else {
    tm1637.display(0, hh / 10);  // hour
  }
  tm1637.display(1, hh % 10); //
  tm1637.display(2, mm / 10); // minutes
  tm1637.display(3, mm % 10); //

The library is a bit odd, it defines the patterns for the hexidecimal digits 0-9 and A-F, which correspond to the numbers 0 through 15. Anything outside that range, except for 0x7F, will produce random results because the number is used as an index into an array of patterns for each individual digit. The library specifically checks for 0x7F and instead of looking up the pattern in the array directly sets the pattern to all segments off.

Nevermind- disregard. I see the example, 'TM1637test'. It has the TM1637.h library. sigh

@david_2018: Thank you my man! That's the kind of help a decent forum should exemplify! Cheers to @steffanL38 too.

I'll give that a try - a big help finally!

Oh, I get it. Yes, some people would rather have a fish than to learn how to fish.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.