B4R Library TM1637 - 4 digits display

SS-2016-06-09_17.16.21.jpg


Based on this open source project: https://github.com/avishorp/TM1637

Timer example:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private tm As TM1637Display
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   tm.Initialize(2, 3)
   timer1.Initialize("timer1_Tick", 1000)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   tm.ShowNumberDec2(Millis / 1000, True, 4, 0)
End Sub

Connections:
CLK - 2 (can be changed)
DIO - 3 (can be changed)
VCC - 5v
GND - Ground

V1.20 (updated by rwblinn): https://www.b4x.com/android/forum/threads/tm1637-4-digits-display.67733/#post-477687
 

Attachments

  • rTM1637.zip
    6 KB · Views: 701
Last edited:

rwblinn

Well-Known Member
Licensed User
Longtime User
Library updated to v1.20.
It allows to set the display brightness or turn the display on / off.

B4X:
' Set the brightness between 0 (low) - 7 (high)
Private Brightness As Int = 3
tm.SetBrightness(Brightness, True)

' Turn the display OFF
tm.SetBrightness(Brightness, False)

' Turn the display ON
tm.SetBrightness(Brightness, True)
 

Attachments

  • rTM1637-1.2.zip
    6.6 KB · Views: 641

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi. Is this for arduino only or it also work for esp8266?
In addition to an Arduino, tested successfully below snippet with an ESP8266 NodeMCU 1.0 (ESP-12E Module).

Wiring
TM1637 (DFRobot) = ESP8266 NodeMCU 1.0

CLK = Pin D2 GPIO4
DIO = Pin D5 GPIO14
GND = Pin GND
VCC = Pin 3V3

Snippet Blinking Number:
Sub Process_Globals
    Public serialLine As Serial
    Private tmDisplay As TM1637Display
    Private PINCLK As Byte = 4        'GPIO4 = Pin D2
    Private PINDIO As Byte = 14        'GPIO14 = Pin D5
    Private BRIGHTNESS As Byte = 7
    Private timerBlinking As Timer
    Private TIMERBLINKING_INTERVAL As ULong = 2000
    Private displayOn As Boolean = False
End Sub

Private Sub AppStart
    serialLine.Initialize(115200)
    tmDisplay.Initialize(PINCLK, PINDIO)
    timerBlinking.Initialize("TimerBlinking_Tick", TIMERBLINKING_INTERVAL)
    timerBlinking.Enabled = True
    TimerBlinking_Tick
End Sub

Sub TimerBlinking_Tick
    displayOn = Not(displayOn)
    tmDisplay.SetBrightness(BRIGHTNESS, displayOn)
    If displayOn Then
        Dim numberValue As Int = Rnd(0,99)
        tmDisplay.ShowNumberDec2(numberValue, False, 2, 2)
    Else
        tmDisplay.ShowNumberDec2(0, False, 2, 2)
    End If
End Sub
 

giggetto71

Active Member
Licensed User
Longtime User
HI guys. I am struggling with the dots. I tried two different modules one very small with apparently only the column dots and that one I can activate the dots. the other module is bigger and has the 4 decimal dots and the ":" column between the 2nd and the 3rd digit. with this module I was hoping to be able to activate the decimal dots
I tried to activate the small dots but even if I tried all the possible masks, the only dots I can activate are the ":" in the middle. even if I call the "ShowNumberDec3" with the 0xFF parameter which I was expecting to activate all the 4 small dots plus the column. any ides?
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,
try following masks:
0.000 = 0x80
00.00 = 0x40
000.0 = 0x20
0.0.0.0 = 0x10

Unfortunate, I do not have a TM1637 with dots or dots+colon, only a TM1637 with single colon (3642BH), but have tested on a TM1638, which has two TM1637 with dots (3641AH). The code used for the TM1638 (Library rTM1638):
B4X:
'Display the dots from right to left (d=Dot): 0d1d2d3d 4d5d6d7d
'Define the dots from right to left
Dim DOTS() As Byte = Array As Byte (0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80)
Dim i As Int
For i = 0 To DOTS.Length - 1
   'Log("Dot ",i,"=", DOTS(i))
   tm.SetDisplayToDecNumber(99999999, DOTS(i), False)
   Delay(2000)
Next
 

giggetto71

Active Member
Licensed User
Longtime User
sorry for late reply. still fighting with the dots..they just won't switch on regardless the dot mask..only the ":" seems to work..
 
Top