gavinlyonsrepo / TM1638plus

An Arduino library to drive TM1638 seven segment modules.
https://gavinlyonsrepo.github.io/
GNU General Public License v3.0
79 stars 25 forks source link

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

Closed austinroolon closed 1 year ago

austinroolon commented 1 year ago

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

gavinlyonsrepo commented 1 year ago

Hi

Do you have a full schematic? Why did you wire like this? Have you built a PCB?

For the first issue the SEG pin see notes, We need to swap the segments around from 12345678 to 67812345 If you look in notes section Note A there already is a parameter that can be set to swap it from 12345678 to 56781234 so we need to set this "swap_nibbles" to True next we need to change 56781234 to 67812345 we can do this by modifying the DisplaySegments method as so

edit see below

I look at the GRX pins next...

gavinlyonsrepo commented 1 year ago

Modifying the DisplaySegments method as so and be sure to set swap_nibbles to true in constructor. I think this will work not sure, difficult to test without hardware.

void TM1638plus_Model2::DisplaySegments(byte segment, byte digit)
{

   if (_SWAP_NIBBLES == true)
   {
      uint8_t upper , lower = 0;
      uint8_t storeMSBBit = 0;
      lower = (digit) & 0x0F;  // select lower nibble
      upper =  (digit >> 4) & 0X0F; //select upper nibble
      digit = lower << 4 | upper;
      // seg
      storeMSBBit = digit & 0x80; //  for 56781234 stores 5  value
      digit = digit  << 1 ;     // "6781234 "
      digit = digit | (storeMSBBit >> 7); // "67812345"
   }
      if (segment == 7) // DPgfedcba // if DP set to a
         segment = 0;  
       else
          segment++; // add 1 to anything else
  segment = (segment<<1);
  sendCommand(TM_WRITE_LOC);
  digitalWrite(_STROBE_IO, LOW);
  sendData(TM_SEG_ADR | segment);
  sendData(digit);
  digitalWrite(_STROBE_IO, HIGH);
}
austinroolon commented 1 year ago

Thank you. I know It is hard to do it without hardware environment. What I did: I had SWAP_NIBBLES set TRUE I replaced whole "void TM1638plus_Model2::DisplaySegments(byte segment, byte digit)..." with above in TM1638plus_Model2.cpp file To be sure I copied the file in local folder and in main sketch (your demo) changed:

include "src/TM1638plus_Model2.h"

I use your TM1638plus_TEST_Model2.ino - Only case 1 selected reduced to:

tm.DisplayDecNumNibble(1234 , 5678, 0, true, TMAlignTextLeft); // "00210178"

delay(myTestDelay);

The result is not as we expected (12345678 on display) It displays from left (active segments on display): number 5 segments de number 6 with dot (dp) segments e, d, c (small u letter)

segments f,g,e,,c,a, dp (small letter h with a segment and dot) segments e,f,a,c, dp segments a,f,e,c,dp ( big G without d segment) segments a,f,e,d,c

gavinlyonsrepo commented 1 year ago

Hi

I think before we make any more code changes. I need to be sure we are on same page.

Can I see the full schematic? PCB ? What seven segment display are you using, datasheet , number?

regards

austinroolon commented 1 year ago

There was an error in in my LED datasheet. Number of segments were ok, but numbers of digits are different. Schematic is the same as on TM1638 datasheet v 1.3, page 6, fig. 2. I attached this fragment of datasheet with my connections between TM1638 and 2x4 digit LED display. The order of segments were ok : SEGMENTS in LED A B C D E F G dp, respectively TM GRID: 8 1 2 3 4 5 6 7 Correct order of digits are: 45678123 As I wrote in post before, I expected display 12345678 on LED due to sketch, but result was different. I counted number of active (displayed) segments and they are 52736545 so I supposed it could be digits 21876543 (digit 3 and 5 uses both 5 active segments) when we change GRID(TM)<->ABCDEFGdp(LED) order in sketch. IMO for example DP is swaped with G. Connection 320048724_878908816793662_3773500067789974744_n

gavinlyonsrepo commented 1 year ago

Hi

We need to change the GR lines from

GR NORMAL segment new
GR1 a b
GR2 b c
GR3 c d
GR4 d e
GR5 e f
GR6 f g
GR7 g dp
GR8 dp a

Or change pgfedcba to apgfedcb

So starting from scratch(original code). Two steps

  1. Step one In file TM1638plus_common.h change

    define TM_DOT_MASK_DEC 0x40

  2. Step Two change the font to this

const PROGMEM unsigned char SevenSeg[] = { 0x00,
0x43,
0x11,
0x3f,
0xb6,
0x69,
0x23,
0x10,
0x94,
0x85,
0x90,
0x38,
0x08,
0x20,
0x40,
0x29,
0x9f,
0x03,
0xad,
0xa7,
0x33,
0xb6,
0xbe,
0x83,
0xbf,
0xb7,
0x84,
0x86,
0xb0,
0x24,
0xa1,
0xe9,
0xaf,
0xbb,
0x3e,
0x9c,
0x2f,
0xbc,
0xb8,
0x9e,
0x3b,
0x18,
0x0f,
0xba,
0x1c,
0x8a,
0x9b,
0x9f,
0xb9,
0xb5,
0x99,
0xb6,
0x3c,
0x1f,
0x1f,
0x15,
0x3b,
0x37,
0xad,
0x9c,
0x32,
0x87,
0x91,
0x04,
0x01,
0xaf,
0x3e,
0x2c,
0x2f,
0xbd,
0xb8,
0xb7,
0x3a,
0x08,
0x06,
0xba,
0x18,
0x0a,
0x2a,
0x2e,
0xb9,
0xb3,
0x28,
0xb6,
0x3c,
0x0e,
0x0e,
0x0a,
0x3b,
0x37,
0xad,
};

Regards

austinroolon commented 1 year ago

Thank you, but the problem still exists. (attachment) I try to understand your lib. I normal connection of TM with common cathode LED, section (under) defines chars. Each sign in line. It is easy to understand. But what is the role of this section in this case, where we swaped SEG pins with GRID due to different polarization LED?

const PROGMEM unsigned char SevenSeg[]

319238148_1221254315465875_3695361372684844601_n

gavinlyonsrepo commented 1 year ago

Hi

Did you remove the changes in third post before making the new changes in last post?

austinroolon commented 1 year ago

No, I did not. Restore original?

gavinlyonsrepo commented 1 year ago

Yes

austinroolon commented 1 year ago

It looks almost fine! Only the order is not correct. We have 18765432 . In my sketch swap_nibbles is still set true;

It is late, but truly speaking I don`t understand the role of definition of fonts in this case where we swaped GRID and SEG pins due to different polarization common anode LED. In common cathode it is obvious. So maybe another time please :) It is not urgent. As you noticed I use two 8 digits (2x4) displays connected to CLK and DATA line drived with two TM1638. The 3rd line is the line, I select the chip I want to send the string to display for. In my sketch I just change in the constructor object TM1638plus_Model2 tm STROBE_TM pin. I wondering about scrolling text through whole 16 digits ... So I need to understand your library good enough :) So far thank you a lot!

gavinlyonsrepo commented 1 year ago

Hi

Ok we have fixed the GRX lines now to fix the SGX lines

We need to replace method DisplaySegments in TM1638plus_Model2.cpp file with this.

void TM1638plus_Model2::DisplaySegments(byte segment, byte digit)
{
   if (_SWAP_NIBBLES == true)
   {
      uint8_t storeMSBBit = 0;
      uint8_t reversedDigit = 0;
      uint8_t upper , lower = 0;
      lower = (digit) & 0x0F;  // select lower nibble
      upper =  (digit >> 4) & 0X0F; //select upper nibble
      digit = lower << 4 | upper;

      // 18765432 
      storeMSBBit = digit & 0x80; //  for "18765432" stores 1 value
      digit = digit  << 1 ;     // "8765432_"
      digit = digit | (storeMSBBit >> 7); // "87654321"
      // reverse bits in byte "12345678"
      for (uint8_t  i = 0; i < 8; i++) 
      {
        if ((digit & (1 << i)))
            reversedDigit |= 1 << ((8 - 1) - i);
      }
      digit = reversedDigit ;
   }

  segment = (segment<<1);
  sendCommand(TM_WRITE_LOC);
  digitalWrite(_STROBE_IO, LOW);
  sendData(TM_SEG_ADR | segment);
  sendData(digit);
  digitalWrite(_STROBE_IO, HIGH);
}
austinroolon commented 1 year ago

Numbers look correct! (order too). Thank you! Some letters f.e. U is with dot. Will keyboard (micro switches) connected like attached link work fine with all made changes? https://github.com/gavinlyonsrepo/TM1638plus/blob/master/extra/images/tm16382.jpg

gavinlyonsrepo commented 1 year ago

Hi

So f + e + U appear as f. e. U. and everything else is good?

Yes the Key switches should work as normal.

As for your earlier question about why I changed the font and not code. I thought it was most efficient and simplest way to do it, to change from pgfedcba to apgfedcb This is code I used to re-order font you could also put this in code in the library code. instead. code gist link

austinroolon commented 1 year ago

I will check it tomorrow. I left. Thats good news about supporting keys in common anode wire with your library. Am I right, that keyboard status I should scan regularly in loop? I didn find any hardware interrupt pin. I run my light sketch on ESP32 so there is lot of time to do it, but it is not effective way to read keys.

austinroolon commented 1 year ago

Hi. I connected my microswitch array like schematic linked above. Two lines of 8 switches each connected to K1 first one, and K2 the second one. Every of 8 rows connected together in pairs and then to SEG1,SEG2..SEG8. I run test 1, 8, 9 (demo). Numbers are still displayed right, but keys test presents 0. I pressed each key separately. I tested if my connection are ok and switches work properly. They do. Hardware circuits are the same no matter common cathode or anode LEDs we use. EDIT it works fine . My fault. I added PULLUP in input mode DATA_IO in section TM1638plus_Model2::ReadKey16() in TM1638plus_Model2.cpp and it is ok. // Merry Christmas !