====== 7-Segment LED Guide ======
Use the functions built into the ILOGICS Arduino SDK to control a 4-digit 7-segment display (FND) with a built-in TM1637 IC.
If you have not installed the SDK, install it from the [[https://www.ilogics.net/en-us/resources/downloads/software/3|ILOGICS Arduino SDK download page]]. MPINO STUDIO2 does not need this installation.
===== 1. Check your 7-segment LED =====
^ Clock type ^ Decimal point type ^
| {{:guide:seven_segment:revision3:clock_module.png?356|Clock-type TM1637 4-digit LED}} | {{:guide:seven_segment:revision3:decimal_module.png?378|Decimal-point-type TM1637 4-digit LED}} |
| Shows a **colon (:)** in the center | Shows **decimal points (.)** between digits |
| Individual decimal points cannot be controlled | For showing decimal points |
===== 2. Connect it to the product =====
Turn off the power to the product and the module before connecting.
The example below connects a 7-segment display (FND) to MPINO-8A4R-S with a Molex 4-pin (5264-04) cable. Cable colors may vary, so connect by pin name rather than by color.
{{ :en-us_guide:seven_segment:connection-desktop.png?1200 |MPINO-8A4R-S, Molex 4-pin 5264-04 cable, and TM1637 FND connection }}
{{ :en-us_guide:seven_segment:connection-mobile.png?640 |MPINO-8A4R-S, Molex 4-pin 5264-04 cable, and TM1637 FND connection }}
==== Wiring by product ====
The terminals below are for the first display, device 0. Open the product name to see every display up to the maximum.
^ Wiring diagram ^ Maximum displays ^ Connect LED CLK to ^ Connect LED DIO to ^ Cannot be used at the same time ^
| [[:en-us_guide:seven_segment:wiring_mpino_8a4r_s|MPINO-8A4R(T)-S]] | 2 | FND/ENCO CLK (D24) | FND/ENCO DIO (D25) | Encoder or interrupt input on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpino_8a4r_su|MPINO-8A4R-SU]] | 4 | FND/ENCO CLK (D24) | FND/ENCO DIO (D25) | Encoder or interrupt input on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpino_8a8r_s|MPINO-8A8R(T)-S]] | 4 | ENC/FND CLK (D24) | ENC/FND DIO (D25) | Encoder or interrupt input on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpino_16a16r|MPINO-16A16R]] | 2 | ENC/FND CLK (D24) | ENC/FND DIO (D25) | Encoder or interrupt input on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpino_8a8r|MPINO-8A8R]] | 3 | PWM7 (D7) | PWM8 (D8) | PWM output on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpino_16a8r|MPINO-16A8R]] | 2 | A(2) (Arduino A2) | A(3) (Arduino A3) | Analog input on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpino_16a8r8t|MPINO-16A8R8T]] | 2 | P(5) (Arduino D5) | P(2) (Arduino D2) | PWM output on the same terminals |
| [[:en-us_guide:seven_segment:wiring_mpaino|MPAINO-8A8R(T)]] | 1 | UART TXD (D14) | UART RXD (D15) | ''Serial3'' UART |
**MPINO-8A8T-S:** The standard board cannot drive a 7-segment display on the ENC/FND connector because of the 4.7 kΩ pull-downs on D24 and D25. With the 7-segment control option, we change them to 10 kΩ pull-ups. The PWM terminals are not affected, so the standard board can connect up to 3 displays.
**Other MPAINO models and K/K2 modules:** This guide currently covers one display on MPAINO-8A8R(T). For other MPAINO models, or to add displays through a K or K2 pulse output module, please contact us before connecting a 7-segment display.
===== 3. ILOGICS built-in functions =====
^ Function ^ What it does ^ Example ^
| [[:en-us_commands:reference:isegbegin|IsegBegin(clkPin, dioPin)]] | Sets the Arduino pins connected to the LED's CLK and DIO | ''IsegBegin(24, 25);'' |
| [[:en-us_commands:reference:isegbrightness|IsegBrightness(brightness)]] | Sets brightness (''0~7'', higher is brighter) | ''IsegBrightness(7);'' |
| [[:en-us_commands:reference:isegdecimal|IsegDecimal(number)]] | Shows an integer in decimal | ''IsegDecimal(123);'' |
| [[:en-us_commands:reference:iseghex|IsegHex(number)]] | Shows an integer in hexadecimal | ''IsegHex(0xABCD);'' |
| [[:en-us_commands:reference:isegclear|IsegClear()]] | Clears all four digits | ''IsegClear();'' |
| [[:en-us_commands:reference:isegwrite|IsegWrite(segments)]] | Shows segment values for each digit directly | See the ''123V'' example below |
| [[:en-us_commands:reference:isegencodedigit|IsegEncodeDigit(digit)]] | Converts one digit to a segment value | ''IsegEncodeDigit(1)'' |
''true'' from ''IsegBegin()'' means the settings you specified are valid. Use the return value of the communication function you call next to check whether the LED actually responds.
===== 4. Example: show 123 =====
This example connects one LED to the FND/ENCO connector of MPINO-8A4R(T)-S.\\
In Arduino IDE, enter the code in a new sketch, select the board and port, then run Verify (✓) → Upload (→).
void setup() {
IsegBegin(24, 25); // FND/ENCO: D24 → CLK, D25 → DIO
IsegBrightness(7); // Set LED brightness to 7
IsegDecimal(123); // Show 123
}
void loop() {
}
When the upload finishes, check that the LED shows **123**. The empty digit on the left stays blank.
==== Changing what is shown ====
Use **one of these calls at a time** in place of ''IsegDecimal(123);'' in the code above.
IsegDecimal(123, true); // Show 0123, including the leading zero
IsegDecimal(123, true, 2); // Show 01.23 on a decimal-point-type LED
IsegHex(0xABCD); // Show four hexadecimal digits
IsegClear(); // Clear all four digits
To show **123V**, use the code below in place of ''IsegDecimal(123);'' in ''setup()''. ''0x3E'' is the segment value for the letter V, made of segments F, E, D, C, and B.
uint8_t displayData[4] = {
IsegEncodeDigit(1),
IsegEncodeDigit(2),
IsegEncodeDigit(3),
0x3E
};
IsegWrite(displayData);
==== Using more than one display ====
To use several LEDs, give each one a device number. The device number is the fourth argument of ''IsegBegin()'' and the last argument of the display functions. If you omit it, the device number is ''0''. The functions accept device numbers ''0~6'', and the table above shows how many displays your product can connect. The product wiring pages list the pin settings for each device number. This example is for MPINO-8A4R(T)-S.
void setup() {
IsegBegin(24, 25, 100, 0); // Device 0: FND/ENCO
IsegBegin(21, 22, 100, 1); // Device 1: PWM
IsegBrightness(7, true, 0);
IsegBrightness(7, true, 1);
IsegDecimal(1234, false, 0, 4, 0, 0); // Show 1234 on device 0
IsegDecimal(5678, false, 0, 4, 0, 1); // Show 5678 on device 1
}
void loop() {
}
===== 5. If nothing is displayed =====
- Check that the **ILOGICS board** for your product and the COM port are selected in Arduino IDE.
- Check that the program calls ''IsegBegin()'' first, and that the number given to ''IsegDecimal()'' fits in four digits. On four digits, ''IsegDecimal()'' shows ''-999~9999''. A number outside the range is not shown, and the function returns ''false''.