Giter VIP home page Giter VIP logo

micropython-tm1637's Introduction

MicroPython TM1637

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

demo

Installation

Using mip via mpremote:

$ mpremote mip install github:mcauser/micropython-tm1637

Using mip directly on a WiFi capable board:

>>> import mip
>>> mip.install("github:mcauser/micropython-tm1637")

Manual installation:

Copy tm1637.py to the root directory of your device.

Examples

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"
Display Bin Hex Dec
0 0b00111111 0x3F 63
1 0b00000110 0x06 6
2 0b01011011 0x5B 91
3 0b01001111 0x4F 79
4 0b01100110 0x66 102
5 0b01101101 0x6D 109
6 0b01111101 0x7D 125
7 0b00000111 0x07 7
8 0b01111111 0x7F 127
9 0b01101111 0x6F 111
A 0b01110111 0x77 119
b 0b01111100 0x7C 124
C 0b00111001 0x39 57
d 0b01011110 0x5E 94
E 0b01111001 0x79 121
F 0b01110001 0x71 113
G 0b00111101 0x3D 61
H 0b01110110 0x76 118
I 0b00000110 0x06 6
J 0b00011110 0x1E 30
K 0b01110110 0x76 118
L 0b00111000 0x38 56
M 0b01010101 0x55 85
n 0b01010100 0x54 84
O 0b00111111 0x3F 63
P 0b01110011 0x73 115
q 0b01100111 0x67 103
r 0b01010000 0x50 80
S 0b01101101 0x6D 109
t 0b01111000 0x78 120
U 0b00111110 0x3E 62
v 0b00011100 0x1C 28
W 0b00101010 0x2A 42
X 0b01110110 0x76 118
y 0b01101110 0x6E 110
Z 0b01011011 0x5B 91
blank 0b00000000 0x00 0
- 0b01000000 0x40 64
* 0b01100011 0x63 99

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)

Modules

For example, the Grove - 4 Digit Display module

Connections

CLK and DIO are bit-banged. You can use any GPIO.

4 Digit Display TinyPICO Pi Pico WeMos D1 Mini
CLK IO18 IO27 D1 (GPIO5)
DIO IO23 IO26 D2 (GPIO4)
VCC 3V3 3V3 3V3/5V
GND GND GND G

Links

License

Licensed under the MIT License.

micropython-tm1637's People

Contributors

larsks avatar mcauser avatar thijstriemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

micropython-tm1637's Issues

Syntax Error for numbers function

Hey! Thanks for making this great utility.

I get ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 11, in <module>\r\n File "tm1637.py", line 129\r\nSyntaxError: invalid syntax\r\n')

when trying to call the numbers function.

'module' object has no attribute 'TM1637'

Hello,
I'm trying to use your code on a WEMOS D1 with MicroPython 1.9.4.
I can run the "import" commands for both, the tm1637 and the machine, but when I run the tm line, it fails with the following error:

import tm1637
from machine import Pin
tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4))
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'TM1637'

Could you please let me know on how to fix this?

Kind regards,
Alex

TM1637 init ValueError

Hi,

can you tell me what could be the problem behind this:

>>> import tm1637
>>> from machine import Pin 
>>> tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4)) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid argument(s) value

Tested on: MicroPython v1.9.4 on 2018-05-11; WiPy with CC3200

Why not use hardware I2C?

Hi there,
I looked at your source code and I wondered, is there any reason why you do not use a machine I2C API, for example the I2C class from MicroPython or smbus? Instead you are bit-banging in software.

Script hanging / freezing

Hello,
I was excperiencing some freezing / hanging behaviour with some tm1637 7-segment displays and this library on a Raspberry Pi Pico board.
I was able to fix it modifiyng your original library as follows:

  • replace all the "sleep_us" occurrencies with "time.sleep"

  • change the "TM1637_DELAY = const(10)" line with "TM1637_DELAY = const(0.00001)"

  • replace the "from time import sleep_us, sleep_ms" line to "import time"

  • I also changed the "sleep_ms(delay)" inside the scroll function with "time.sleep(delay)" and changed the original "delay=250" with "delay=0.250"

My script is now running since two days with no more freezings! I hope this helps.

Clear method

How do I clear the screen completely? Can you add a clear or reset method?

Eg. this shows 1OOL, 2OOL etc..

>>> t.show('COOL')
>>> import utime
>>> for x in range(1000):
...     t.show(str(x))
...     utime.sleep(0.4)

t.show('') doesn't seem to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.