Giter Club home page Giter Club logo

tm1638plus's Introduction

Website Rss Donate

TM1638plus

Table of contents

Overview

  • Name: TM1638plus
  • Description:

An Arduino library to display data on a 8-digit TM1638 seven segment module's. This library supports all 3 of the known models on market. see Model type section below

  • Main Author: Gavin Lyons.

Installation

The library is included in the official Arduino library manger and the optimum way to install it is using the library manager which can be opened by the manage libraries option in Arduino IDE. Search "tm1638" in search bar of library manager to find it.

See link below for instruction for this and for the other methods too.

Installing Additional Arduino Libraries guide

Software

The API (application programming interface) html documentation is at link. Hosted on github pages and generated by Doxygen software. Here the user will find lots of information on files, functions & data types.

Software API Url Link

Connections

Connections to MCU:

* GPIO = STB = Strobe
* GPIO  = CLK  = Clock
* GPIO = DIO = Data input / output
* GND
* VCC 

Model Types

This library supports three variants of the TM1638, which for purposes of this documentation, will be named Model 1 ,Model 2 and Model 3. Pictured left to right.

 module pics

Model Name PCB Labels LEDs Push buttons
Model 1 TM1638 LED & KEY 8 red only 8
Model 2 TM1638 KEYS, QYF 0 16
Model 3 TM1638 V1.3 or LKM1638 8 bi color, red or green 8

Model One

TM1638 Module 8 Push buttons 8 LEDS (LED & KEY)

 module

 sch

This variant consist of an 8-digit seven segment display with decimal points, 8 Leds and 8 Push buttons. Two 4 digit 3461AS-1 (.34 inch, 4 digit ,common Cathode, decimal point, RED) are used in this module giving a total of 8 digits. A TM1638 controller chip drives the unit. The unit is marked (LED & KEY).

The library support ASCII ,text ,Hex and allows for setting individual segments, and the decimal point of segment. User may have to "debounce" the button read method depending on application. debouncing left out to minimise library size. Example files show some methods to do this. User can Adjust brightness of module. Support 8 degree brightness adjustment. It is possible to manually set segments to create custom patterns without reference to the ASCII font.

Model Two

TM1638 Module 16 Push buttons (16 KEY) (QYF).

 module

 sch

They consist of an 8-digit seven segment display with decimal points, and 16 Push buttons.Two 4 digit 3461BS-1 (.34 inch, 4 digit ,common Anode, decimal point, RED)are used in this module giving a total of 8 digits. A TM1638 controller chip drives the unit. NB : If your display shows "56781234" for "12345678" see Notes section. Note 1.

User may want to "debounce" button's read method depending on application. See TM1638plus_ADC_TEST_Model2.ino for debounce button example. Two different functions to read buttons. Raw ASCII data can be printed without reference to font file.

Model Three

There are different PCB's of these modules on market, This library was tested on no 3 below. I think this software will work for all of them and the differences in PCB are related to connectors, layout and component placement. This module is a variant of Model 1. The differences are the LEDs are bigger and bi-color both red and green, The seven segment display is larger and extra connectors are added for Daisy chaining. Two 4 digit KYX-5461AS-7.3 (.54 inch, 4 digit ,common cathode, decimal point, RED)are used in this module giving a total of 8 digits.

  1. LKM1638 v1.1
  2. LKM1638 v1.2
  3. TM1638 V1.3

 module

Model 3 LED Functions

The code is the same as model 1 and there is one unique model 3 example file. setLED and setLEDs functions behaviour is the only difference in code base between 1 and 3. SetLED: The difference is when you call the setLED function you pass the following to get LEDs to change colour. For more detailed information on functions see commented headers in header file(.h).

Model setLED Value result
1 & 3 0 LED off
3 1 Led green on
3 2 LED red on
1 1 LED on

SetLEDs: When you pass call the setLEDs function you can pass a word pattern where upper byte is turns LEDs green on and lower byte turns LEDs red on . Model one ignores lower byte, Set to 0x00 always.

  1. Model 3 setLEDs(word) = 0xGGRR
  2. Model 1 setLEDs(word) = 0xRR00

Tested

  • Tested on following MCU & Development platforms.
  • Examples files are set up for Arduino UNO & NANO v3.
  • File GPIO_OTHER_MCUs.txt in extra folder gives pins tested for other MCU.
  1. Arduino UNO & NANO v3 .
  2. ATtiny85 .
  3. ESP32.
  4. STM32 STM32F103C8T6 "the blue pill".
  5. ESP8266.
  6. Teensy 4.0. (may not work at highest frequency see note #2 in notes section)

Notes

  1. Swapped data on Display issue on some Model 2 modules
  2. Anomaly's on High frequency micro-controllers.
  3. Driving multiple displays.
  4. Detecting multiple buttons pressed together.

Note 1 : Swapped display Issue: Model 2 only

For Some users using this library the nibbles in information display byte where swapped around. This is because there are different versions of modules on market with different wiring. See issue #3 on github called Swapped display :: "12345678" becomes "56781234". If you test library and you see this issue, in order to fix this when you declare the Object, set the fourth parameter "swap_nibbles" to True, The default is false.

PCB Model noted Label Operation Object constructor 4th parameter
QYF-TM1638 default operation false
QYF-TM1638 -Ver 1.0 Swapped display Fix true

Note 2 : High frequency micro-controllers.

This library uses a software SPI-like protocol and may not work fully on micro-controllers running at a very high frequency, without some adjustments to timing. It is a SPI-like interface with a single bidirectional data wire DIO. The TM1638 is basically a slow SPI device (< 500kHz) in DIO mode. The clock uses the equivalent of SPI mode 3 (normally high, clocks data on the rising edge). The problem is that the native Arduino shiftIn()/shiftOut() wire functions are simply too fast for this device (technically the clock signalling for the TM1638 is inverted but as it triggers on a rising edge still it is tolerant of that). To make this work with fast devices, the shift clocking is slowed with a small delay (on the order of a microsecond).

HighFreqshiftin function:

As of version 1.6 a new parameter (_HIGH_FREQ) has been introduced to constructor it is false by default. Set to true for high frequency MCU ~> 100Mhz. This should fix the issue of HF MCU not reading buttons correctly(ESP-Xs). The High_Freq parameter causes a custom shift-in function to be used. The delay in this function is fixed at 1 uS, it can be changed manually by adjusted the defines in common header file.

The Teensy results have been sent in by email, I don't have these MCU's them at time of writing.

IC frequency Status
ATtiny85 1Mhz internal Working
Arduino UNO 16 MHz Working
Arduino Nano 16 MHz Working
STM32 "blue pill" STM32F103C8T6 72Mhz Working
ESP8266 160Mhz Working
ESP 32 240 MHz Working, with high_freq set to true
Teensy 4.0 150Mhz Working model 1, no Data rest of models
Teensy 4.0 396Mhz Not working on m1 pre v1.6, no data after, no Data rest of models

Note 3 : Driving multiple displays.

It is possible to drive multiple modules. Share the DIO and CLK lines and use a unique STB line for each device. see issue number 10 at github for example code.

Note 4 : Detecting multiple buttons pressed together.

Model 1 and Model 3 CAN detect multiple buttons pressed.

Model 2 has two different functions:

  1. ReadKey16 returns a byte with decimal value 1-16 this function cannot detect multiple buttons pressed.

  2. ReadKey16Two returns a 16 bit integer where each bit corresponds to the 16 switch's. However due to the wiring of the module, see SG-X lines on schematic, Pressing Certain combinations of buttons will cause the data on Seven Segments to change. So the simultaneous use of multiple key presses and the seven segments display is problematic. See issue 12 on github for more details.

tm1638plus's People

Contributors

centic9 avatar gabormay avatar gavinlyonsrepo avatar hastypete avatar wunderbaum 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tm1638plus's Issues

Bug: Assignment instead of comparison in If

Assignment instead of comparison in else if.

if (TextAlignment == TMAlignTextLeft)
{
strcat(TextDisplay ,TextLeft); // %-4X
}else if ( TextAlignment = TMAlignTextRight)
{
strcat(TextDisplay ,TextRight); // %4X
}

Should be:

if (TextAlignment == TMAlignTextLeft) 
{ 
     strcat(TextDisplay, TextLeft);  // %-4X 
} else if ( TextAlignment == TMAlignTextRight) 
{ 
     strcat(TextDisplay, TextRight); // %4X 
} 

not working on ESP32, answer

sorry I don't know how to react on an issue, but I found a working solution (the main problem is the function shiftIn which shoudl be delayed)

uint8_t shiftInX(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
uint8_t value = 0;
uint8_t i;

for(i = 0; i < 8; ++i) {
    //digitalWrite(clockPin, HIGH);
    if(bitOrder == LSBFIRST)
        value |= digitalRead(dataPin) << i;
    else
        value |= digitalRead(dataPin) << (7 - i);
    digitalWrite(clockPin, HIGH);

delayMicroseconds(1);
digitalWrite(clockPin, LOW);
delayMicroseconds(1);
}
//Serial.println ( "*********************");
return value;
}

uint8_t TM1638plus::readButtons()
{
uint8_t buttons = 0;
digitalWrite(_CLOCK_IO, LOW); //SM
digitalWrite(_STROBE_IO, LOW);
delayMicroseconds(1);
shiftOut(_DATA_IO, _CLOCK_IO, LSBFIRST, BUTTONS_MODE);
pinMode(_DATA_IO, INPUT);

for (uint8_t i = 0; i < 4; i++)
{
uint8_t v = shiftInX(_DATA_IO, _CLOCK_IO, LSBFIRST) << i;
buttons |= v;
}

pinMode(_DATA_IO, OUTPUT);
digitalWrite(_STROBE_IO, HIGH);
return buttons;
}

displayHex fix

displayHex(16) should show zero, but shows 1
(since of course '0' comes after 'F')
That way no matter what number you send, you will see the lower nibble correctly.

Add example of two Type 1 modules

Hi, could you add an example how to drive two type1 modules?
As I understood CLK and DIO can be shared for both modules and one module need a seperate line for STB and the second modules a own line as well.

buttons not working on ESP32

when I compile standard for the ESP32, display seems to work well, but only button 1 is detected. For this test I use the example TM1638plus_Test.
It seems to be some problem with the CPU frequency, because
standard cpu = 240 MHz, only button 1
compile for cpu = 80 MHz, button 1,2,3,4 are detected, button 6 sometimes

Common Anode like type2, but different connections - what to change.

I build my own display led based on TM1638 common anode LED (like type 2) but my own, different connections to pins GRID and SEGMENT. Tell my please what and where I have to change to correctly display digits/letters /order.
I use your TM1638plus_Model2 library (thank you!)
My connections:
SEG PIN (TM1638)-LED NUMBER (COMMON ANODE PIN) (from left):
SEG#1-LED6, #2-7, #3-8, #4 -1, #5-2, #6-3, #7-4, #8-5

GRID PIN (TM1638)-LED SEGMENT (CATHODEs):
GRID#1-b, #2-c, #3-d, #4-e, #5-f, #6-g, #7-dp, #8-a

displayText may try to write past the display buffer

There is no guard in displayText against writing past the display size. This is problematic when one has to deal with arbitrary text, where dots can appear at random places. (My use case was to display morse code).

In these cases, it's difficult to figure out how much of the display the text will actually cover on the display. An easy way to work around that is to add some extra spaces at the end of the text but then you run the risk of writing past the display size.

Feature request: Multiple button pressed

Hello,
thanks alot for adding my simple mqtt-example.
Is it possible in any way to detect multiple buttons pressed at the same time? Like 1+2 is pressed simultaneously.

V1.6.0 - readButtons() not working

Using "Model 1". When I update from V1.5.0 to 1.6.0 (or 1.7.0) the "readButtons()" method returns 0xff with no buttons pressed (previously worked fine). I have tried providing the additional constructor parameter (false) but that made no difference. Same code, same hardware. Change back to V1.5.0. and all is good again.

Seems odd in that if this is a real issue I would have thought it would have been noticed by now - so have I not spotted something in the upgrade path I should have done?

Swapped display

Hi to everyone,
with Model 2 Library why 8 digit display is 4 digit swapped?
For example
tm.DisplayStr(" helloU2", 0);
show
"loU2 hel"
or
tm.DisplayDecNum(5, 1 << 6);
show
"000500.00"

Thank you
Max

ADC_TEST for Model1 ?

Hello, is there any ability to read ADC or some values directly to display for Model1 ?

Thanks.

High speed buttons error

The first button press cannot be detected when using high speed devices.
Fixed by moving last delayMicroseconds(1); to start of for loop in
TM1638plus_common::HighFreqshiftin

PS: the TM1638 works fine on 3.3V no need for voltage level shift

Communication with TM1638 randomly broken.

I have a problem with the communication between arduino mega and TM1638 model1 breaking down. Only a new initialization of the TM1638 will help. I assume it's some kind of interference. Do you know where the problem could be?

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.