Uncategorized

MicroPython TM1637

MicroPython TM1637

A MicroPython library for quad 7-segment LED display modules using the TM1637 LED driver.

For example, the Grove – 4 Digit Display module

demo

Examples

Copy the file to your device, using ampy, webrepl or compiling and deploying. eg.

$ ampy put tm1637.py

Basic usage

import tm1637
from machine import Pin
tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4))

# all LEDS on "88:88"
tm.write([127, 255, 127, 127])

# all LEDS off
tm.write([0, 0, 0, 0])

# show "0123"
tm.write([63, 6, 91, 79])

# show "COOL"
tm.write([0b00111001, 0b00111111, 0b00111111, 0b00111000])

# show "HELP"
tm.show('help')

# display "dEAd", "bEEF"
tm.hex(0xdead)
tm.hex(0xbeef)

# show "12:59"
tm.numbers(12, 59)

# show "-123"
tm.number(-123)

# show temperature '24*C'
tm.temperature(24)

For more detailed examples, see tm1637_test.py

Seven Segment Font

They are called 7-segment displays as there are 7 LEDs for each digit (segment). One byte (7 lower bits) for each segment. The 8th bit (MSB) is for the colon and only on the 2nd segment.

      A
     ---
  F |   | B   *
     -G-      H (on 2nd segment)
  E |   | C   *
     ---
      D

  HGFEDCBA
0b01101101 = 0x6D = 109 = show "5"

DisplayBinHexDec
00b001111110x3F63
10b000001100x066
20b010110110x5B91
30b010011110x4F79
40b011001100x66102
50b011011010x6D109
60b011111010x7D125
70b000001110x077
80b011111110x7F127
90b011011110x6F111
A0b011101110x77119
b0b011111000x7C124
C0b001110010x3957
d0b010111100x5E94
E0b011110010x79121
F0b011100010x71113
G0b001111010x3D61
H0b011101100x76118
I0b000001100x066
J0b000111100x1E30
K0b011101100x76118
L0b001110000x3856
M0b010101010x5585
n0b010101000x5484
O0b001111110x3F63
P0b011100110x73115
q0b011001110x67103
r0b010100000x5080
S0b011011010x6D109
t0b011110000x78120
U0b001111100x3E62
v0b000111000x1C28
W0b001010100x2A42
X0b011101100x76118
y0b011011100x6E110
Z0b010110110x5B91
blank0b000000000x000
0b010000000x4064
*0b011000110x6399

Methods

Get or set brightness.

brightness(val=None)

Write one or more segments at a given offset.

write(segments, pos=0)

Convert a single hex digit (0x00-0x0f) to a segment.

encode_digit(digit)

Convert a string to a list of segments.

encode_string(string)

Convert a single character to a segment.

encode_char(char)

Display a number in hexadecimal format 0000 through FFFF.

hex(val)

Display a number -999 through 9999, right aligned.

number(num)

Display 2 independent numbers on either side of the (optional) colon, with leading zeros.

numbers(num1, num2, colon=True)

Display a temperature -9 through 99 followed by degrees C.

temperature(num)

Show a string on the display. Shorthand for write(encode_string()). Limited to first 4 characters.

show(string, colon=False)

Display a string on the display, scrolling from the right to left, speed adjustable. String starts off-screen and scrolls until off-screen at 4 FPS by default.

scroll(string, delay=250)

Parts

Connections

WeMos D1 Mini4 Digit Display
D1 (GPIO5)CLK
D2 (GPIO4)DIO
3V3 (or 5V)VCC
GGND

Links

License

Licensed under the MIT License.

Categories: Uncategorized

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.