TM1637 6 digit - works - more or less - Small tweak would be great

Let Sim Innovations know about your Air Manager experience and let us know about your dream feature addition

Moderators: russ, Ralph

Message
Author
User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

TM1637 6 digit - works - more or less - Small tweak would be great

#1 Post by jph »

Hi guys,
The superb TM1637 display modules are now everywhere with 6 digits. as in - https://www.aliexpress.com/item/1005001 ... 1802vvix7J
Plentiful, loads of colour options, very well made and cheap. They also work on 3.3 OR 5V with no changes.

They DO work with the 1637 routine built into AM even though it is supposedly 4 digits maximum. Using a 6 digit module the only small issue is that the order of the displays is reversed on each 3 digit block as in the following where the number 123456 was sent and 321654 is displayed.
image.png
It would be really great if you can make this work this @Corjan . They are really neat displays. I can of course reverse the digits in AM in LUA prior to sending but it would be excellent if it wasn't needed. ALL the 6 digit displays being sold are of this type. They use a single TM1637 and they use 2 x 3 digit displays to form the block of 6.
Pretty please ? :D

Sample code and actual output

Code: Select all

-- Bind to the Arduino UNO on channel A.
-- hw_id 1 = TM1637 data pin  (ARDUINO_UNO_A_D4 in this example)
-- hw_id 2 = TM1637 clock pin  (ARDUINO_UNO_A_D5 in this example)
display_chr_id = hw_chr_display_add("TM1637", 6, "ARDUINO_UNO_A_D4", "ARDUINO_UNO_A_D5")
hw_chr_display_set_brightness(display_chr_id, 0.5)
-- Set text "123456"
hw_chr_display_set_text(display_chr_id, "123456")
-- Actual value displayed is 321654
-- Notes: Display module link - https://www.aliexpress.com/item/1005001570737985.html?spm=a2g0o.order_list.0.0.21ef1802vvix7J
-- Joe (@JPH)
Output is as in the above image.
Changing the code in AM to -

Code: Select all

hw_chr_display_set_text(display_chr_id, "321654")
produces the 'correct' 123456 output.
Decimal points work as they should on the numerical value as it is written so no problems there at all.

Thanks
Joe
Joe. CISSP, MSc.

User avatar
Ralph
Posts: 7867
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#2 Post by Ralph »

We don't have any 6 digit displays here I believe. But Corjan will be out of the office until October, so it would have to wait for a while...

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#3 Post by jph »

Ralph wrote: Thu Jun 30, 2022 1:40 pm We don't have any 6 digit displays here I believe. But Corjan will be out of the office until October, so it would have to wait for a while...
Not a problem,
Do you want me to pop a display in the post to you ? - I have a bag of them.
Joe. CISSP, MSc.

User avatar
Ralph
Posts: 7867
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#4 Post by Ralph »

If you have some spares then that would be great.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#5 Post by jph »

No problem at all Ralph.
I will pop one in the post on Monday.
Joe
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4671
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#6 Post by Keith Baxter »

jph wrote: Thu Jun 30, 2022 5:13 pm No problem at all Ralph.
I will pop one in the post on Monday.
Joe
Only one. :D

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#7 Post by jph »

Keith Baxter wrote: Thu Jun 30, 2022 6:39 pm
jph wrote: Thu Jun 30, 2022 5:13 pm No problem at all Ralph.
I will pop one in the post on Monday.
Joe
Only one. :D

Keith
:lol: hello brother, yes, one very special one for Ralph. I have a bag full but they are a mixture of red and white units both 4 and 6 digits. I have a spare white 6 digit one though.

Have actually ordered a batch of 50 x 0.3 inch white 6 block units directly from the manufacturer in China as they arent available on AliX. The ones on the boards in the image are 0.36 inch and wider spaced so much larger. The 0.3 narrow space are not cheap but first class quailty and correct digit spacing. These are the proper size for the MCP. They are 6 block 7 seg units only though. 14 pin, no driver ic or board. Common Anode so will work wth a 1637. Will have some sets available should anyone want any. Also having some sample orange units made and sent in same batch for pedestal module displays. They are a nice dark orange custom unit. I will order a full batch of the orange units if they look the part which they should.
Joe
Joe. CISSP, MSc.

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#8 Post by SimPassion »

Hi @Ralph and @Corjan, did you already made the testing and incorporate fix in 4.2 Beta or 4.1.6 ?

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#9 Post by SimPassion »

Made the testing today, so really waiting for more than 4 digits handling

until fixed, the TM1637 6 x digits works like this, as mentioned by Joe :

Code: Select all

--====================================================================================
--								CHECK PURPOSE
--====================================================================================

-- Create a new Max7219 based character display
display_chr_id = hw_chr_display_add("TM1637 Testing", "TM1637", 6)

-- Set text "1234"
hw_chr_display_set_text(display_chr_id,"210543")
image.png

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: TM1637 6 digit - works - more or less - Small tweak would be great

#10 Post by jph »

Hi Gilles, @Ralph definitely got the display as we talked about in in an email on another subject.
Meanwhile, here is a routine to reverse the digits. With a decimal point it is easier to convert to an integer and then add it back (the DP) before sending to the display.

Code: Select all

-- Function to reverse a string for TM1637

function reverseString(str)
    return string.reverse(str)
end

-- Function to reverse the first and second halves of a 6-digit number
function reverseHalves(number)
    local strNumber = tostring(number)
    local length = string.len(strNumber)
    
    -- Ensure the input is a 6-digit number
    if length == 6 then
        local firstHalf = string.sub(strNumber, 1, 3)
        local secondHalf = string.sub(strNumber, 4, 6)
        
        local reversedFirstHalf = reverseString(firstHalf)
        local reversedSecondHalf = reverseString(secondHalf)
        
        local result = reversedFirstHalf .. reversedSecondHalf
        
        return tonumber(result)
    else
        return nil  -- Invalid input
    end
end

-- Example usage
local inputNumber = 123456
local reversedNumber = reverseHalves(inputNumber)

if reversedNumber then
    print("Original number:", inputNumber)
    print("Reversed number:", reversedNumber)
else
    print("Invalid input. Please enter a 6-digit number.")
end
Joe and CGPT ;)
Joe. CISSP, MSc.

Post Reply