Simple KEY wirting Issue with KEYPAD on TM1637

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A15, A14, A13, A12}; 
byte colPins[COLS] = {A11, A10, A9, A8}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

#include <TM1637Display.h>
#define CLK 3
#define DIO 2
TM1637Display display = TM1637Display (CLK, DIO);

int count;

void setup(){
  lcd.init();
  lcd.backlight();
  display.setBrightness(4); // activate display
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  if (customKey){
    Serial.println(customKey);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
    count = atoi(customKey);
    display.showNumberDec(count);
  }
}

Unable to write on TM1637 display

Its showing a ZER0 all the time with any key pressed

atoi() works with c-strings (null terminated char array), not char.
If customKey is a number, you can use count = customKey - '0'; note that is the number zero inside single quotes.

O Yeah !!!! That is working with numeric area only

and what if I want to include spcl character keys and alphabetic keys ???

I mean only A B C D

not # or * :grimacing:

I don't think the TM637 library has a built-in method of displaying characters, you will have to encode the character into the appropriate LED segments then pass that to the library. The TMS1637Test example sketch from the library shows an example of that.

I see
Ok le me check with that one !!!

Sir do you have any idea how to add 1N4148 diode in device library of WOKWI ???

Please comment !

I don't see any diodes in the parts menu on WOKWI, someone more familiar with the simulator may be able to help.

Ya !!!

Well this is code for TM1637 Test

#include <Arduino.h>
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3

// The amount of time (in milliseconds) between tests
#define TEST_DELAY   2000

const uint8_t SEG_DONE[] = {
	SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,           // d
	SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
	SEG_C | SEG_E | SEG_G,                           // n
	SEG_A | SEG_D | SEG_E | SEG_F | SEG_G            // E
	};

TM1637Display display(CLK, DIO);

void setup()
{
}

void loop()
{
  int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
  display.setBrightness(0x0f);

  // All segments on
  display.setSegments(data);
  delay(TEST_DELAY);

  // Selectively set different digits
  data[0] = display.encodeDigit(0);
  data[1] = display.encodeDigit(1);
  data[2] = display.encodeDigit(2);
  data[3] = display.encodeDigit(3);
  display.setSegments(data);
  delay(TEST_DELAY);

  /*
  for(k = 3; k >= 0; k--) {
	display.setSegments(data, 1, k);
	delay(TEST_DELAY);
	}
  */

  display.clear();
  display.setSegments(data+2, 2, 2);
  delay(TEST_DELAY);

  display.clear();
  display.setSegments(data+2, 2, 1);
  delay(TEST_DELAY);

  display.clear();
  display.setSegments(data+1, 3, 1);
  delay(TEST_DELAY);


  // Show decimal numbers with/without leading zeros
  display.showNumberDec(0, false); // Expect: ___0
  delay(TEST_DELAY);
  display.showNumberDec(0, true);  // Expect: 0000
  delay(TEST_DELAY);
	display.showNumberDec(1, false); // Expect: ___1
	delay(TEST_DELAY);
  display.showNumberDec(1, true);  // Expect: 0001
  delay(TEST_DELAY);
  display.showNumberDec(301, false); // Expect: _301
  delay(TEST_DELAY);
  display.showNumberDec(301, true); // Expect: 0301
  delay(TEST_DELAY);
  display.clear();
  display.showNumberDec(14, false, 2, 1); // Expect: _14_
  delay(TEST_DELAY);
  display.clear();
  display.showNumberDec(4, true, 2, 2);  // Expect: 04__
  delay(TEST_DELAY);
  display.showNumberDec(-1, false);  // Expect: __-1
  delay(TEST_DELAY);
  display.showNumberDec(-12);        // Expect: _-12
  delay(TEST_DELAY);
  display.showNumberDec(-999);       // Expect: -999
  delay(TEST_DELAY);
  display.clear();
  display.showNumberDec(-5, false, 3, 0); // Expect: _-5_
  delay(TEST_DELAY);
  display.showNumberHexEx(0xf1af);        // Expect: f1Af
  delay(TEST_DELAY);
  display.showNumberHexEx(0x2c);          // Expect: __2C
  delay(TEST_DELAY);
  display.showNumberHexEx(0xd1, 0, true); // Expect: 00d1
  delay(TEST_DELAY);
  display.clear();
  display.showNumberHexEx(0xd1, 0, true, 2); // Expect: d1__
  delay(TEST_DELAY);
  
	// Run through all the dots
	for(k=0; k <= 4; k++) {
		display.showNumberDecEx(0, (0x80 >> k), true);
		delay(TEST_DELAY);
	}

  // Brightness Test
  for(k = 0; k < 4; k++)
	data[k] = 0xff;
  for(k = 0; k < 7; k++) {
    display.setBrightness(k);
    display.setSegments(data);
    delay(TEST_DELAY);
  }
  
  // On/Off test
  for(k = 0; k < 4; k++) {
    display.setBrightness(7, false);  // Turn off
    display.setSegments(data);
    delay(TEST_DELAY);
    display.setBrightness(7, true); // Turn on
    display.setSegments(data);
    delay(TEST_DELAY);  
  }

 
  // Done!
  display.setSegments(SEG_DONE);

  while(1);
}

What things we can derive from here ??

#include <Arduino.h>
#include <TM1637Display.h>
#define CLK 2
#define DIO 3
 
const uint8_t SEG_DONE[] = {
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_C | SEG_G, // A
  SEG_F | SEG_E | SEG_D | SEG_C | SEG_G,  // b
  SEG_E | SEG_F | SEG_G | SEG_B | SEG_C,  // h
  SEG_B | SEG_C            // I
  };
 
TM1637Display display(CLK, DIO);
 
void setup()
{
}
 
void loop()
{
  display.setBrightness(0x0f);
  display.setSegments(SEG_DONE);
}

Simple setSegment may work but need a convertor again I think !!

Sir I tried with this one

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A15, A14, A13, A12}; 
byte colPins[COLS] = {A11, A10, A9, A8}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

#include <TM1637Display.h>
#define CLK 3
#define DIO 2
TM1637Display display = TM1637Display (CLK, DIO);

int count;

const uint8_t SEG_Aonly[] = {
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_C | SEG_G // A
  };

void setup(){
  lcd.init();
  lcd.backlight();
  display.setBrightness(4); // activate display
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  if (customKey){
    Serial.println(customKey);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
    // count = atoi(customKey);
    count = customKey - '0';
    display.showNumberDec(count);
  }
  if(customKey=='A')
  {
    display.setSegments(SEG_Aonly);
  }
}

For key 'A' its working fine but displaying the letter A at very left side first digit or say on 1000's place of TM1637 display

How to get it shift onto very right side ?????

Sir any update ??

Sorry, had something I needed to do here.

You can specify which specific digits to update in the setSegments() function.

void loop(){
  char customKey = customKeypad.getKey();
  if (customKey){
    Serial.println(customKey);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
    // count = atoi(customKey);
    if ((customKey >= '0') && (customKey <= '9')){
      count = customKey - '0';
      display.showNumberDec(count);
    }
  }
  if(customKey=='A')
  {
    display.setSegments(SEG_Aonly, 1, 3);
  }
}

You give setSegments() the array, the number of digits to update, and the starting digit (digits are numbered from 0 through 3 starting from the left).

Unfortunately there is not a lot of documentation for the TMS1637 library, most of the documentation is in the comments of the TMS1637Display.h file.

Ya Sir now got the point !!

On the basis of this I learned a bit

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#include <Keypad.h>

const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A15, A14, A13, A12}; 
byte colPins[COLS] = {A11, A10, A9, A8}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

#include <TM1637Display.h>
#define CLK 3
#define DIO 2
TM1637Display display = TM1637Display (CLK, DIO);

int count;

const uint8_t SEG_Aonly[] = {
  SEG_E | SEG_F | SEG_A | SEG_B | SEG_C | SEG_G // A
  };
const uint8_t SEG_Bonly[] = {
  SEG_E | SEG_D | SEG_F | SEG_C | SEG_G // B
  };
const uint8_t SEG_Conly[] = {
  SEG_A | SEG_D | SEG_E | SEG_F  // C
  };
const uint8_t SEG_Donly[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G // D
  };

void setup(){
  lcd.init();
  lcd.backlight();
  display.setBrightness(4); // activate display
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
   if ((customKey >= '0') && (customKey <= '9')){
    Serial.println(customKey);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
    // count = atoi(customKey);
    count = customKey - '0';
    display.showNumberDec(count);
  }
  if(customKey=='A')
  {
    display.setSegments(SEG_Aonly, 1, 3);
    // 3 HERE DECIDES 4TH POSIITOIN
    //2 FOR 3RD POSITION
    //1 FOR FOURTH POSITION 
    //0 FOR FIRST POSITION
    lcd.setCursor(1, 1);
    lcd.print(customKey);
  }
  if(customKey=='B')
  {
    display.setSegments(SEG_Bonly, 1, 3);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
  }
  if(customKey=='C')
  {
    display.setSegments(SEG_Conly, 1, 3);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
  }
  if(customKey=='D')
  {
    display.setSegments(SEG_Donly, 1, 3);
    lcd.setCursor(1, 1);
    lcd.print(customKey);
  }
}

Positions can be alter !!!

this one under setup to clear the display

display.setBrightness(4); // activate display
  display.clear(); // Strictly Required

is important one as introducing other component definitions may vary the position

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.