The TM1637 7-segment display is usually associated with a 4-digit 7-segment display. These are quite simple to install (only require 2 pins on your microcontroller), easy to code, and a real blessing when displaying data like altitude, heading, etc.
This morning, I was asked how these displays work with 6 digits and if they are compatible with my connector. First of all, everything you can code is compatible with the connector (I'm still working on a way to make coffee when I land to prove this point). When I tried to develop some code, I noticed that the library that usually gets recommended differs quite a bit from the TM1637 libraries you're used to. That's why I decided to write this small post explaining my findings.
When it comes to displaying com frequencies, four digits just aren't going to cut it. There are several 8-digit displays available, or you could combine two 4-digit displays to create the illusion your display has 8 digits, but nothing beats having 6 characters to work with.
With the usual 4-digit displays, the code would look something like this:
cpp#include "TM1637.h" #include <BitsAndDroidsFlightConnector.h> BitsAndDroidsFlightConnector connector(false); // we define where the CLK and DIO pins are connected on the board #define CLKA 6//pins definitions for TM1637 and can be changed to other ports #define DIOA 7 TM1637 tm1637A(CLKA, DIOA); String activeCom =""; String oldCom =""; void setup() { //Open our Serial ports Serial.begin(115200); Serial.setTimeout(15); //Initiate our display tm1637A.set(BRIGHT_DARKEST); tm1637A.init(); } void loop() { connector.dataHandling(); activeCom = connector.getActiveCom1(); //if the active com has changed if(!oldCom.equals(activeCom)){ int lengthChars = connector.getActiveCom1().length() + 1; char charBuffer[lengthChars]; //Convert activecom1 String to char* connector.getActiveNav1().toCharArray(charBuffer, lengthChars); //Display the new frequency tm1637A.displaystr(charBuffer); } }
Or, in the case of data like the Altitude lock (since this isn't text or a decimal number), we could even shorten it to:
tm1637A.displayNum(connector.getApHeadingLock().toInt());
The library for the 6-digit display does some things differently, which me off at first. First, it doesn't have a displayStr(char*) function. Luckily for us, the coms frequencies look like "122.850". It may seem like a walk in the park, but when you're used to doing things a certain way, it took me way too much time to spot that "122.850" might as well be a decimal number 122,850 (sorry, American readers, we Europeans use the comma for decimals).
The code to display the active com would then become:
cpp#include <TM1637_6D.h> #define CLK 7 //pins definitions for TM1637 and can be changed to other ports #define DIO 6 TM1637_6D tm1637_6D(CLK,DIO); #include <BitsAndDroidsFlightConnector.h> BitsAndDroidsFlightConnector connector(false); // At the start the activeCom will be empty String activeCom =""; // So will be the old Active com String oldCom =""; void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.setTimeout(15); //Activate the tm1637 tm1637_6D.set(BRIGHT_DARKEST); tm1637_6D.init(); } void loop() { //This line will read the incomming com data connector.dataHandling(); //The activeCom will be set to a new value. if a change is detected the empty string will become 123.456 as an example. activeCom = connector.getActiveCom1(); //here we check if the line has changed so if the old com does not equal the new com do something if(!oldCom.equals(activeCom)){ //if the line has changed display the new ActiveCom this is to save resources since printing a new value can be an intesive task tm1637_6D.displayFloat(activeCom.toFloat()); //the value to check against (so the oldCom) will be set to the newCom so that in the next loop we check against the last updated value. oldCom = activeCom; } }
Integers work the same as you're used to with the regular 4-digit displays.
tm1637_6D.displayInteger(connector.getIndicatedAltitude.toInt(), true);
In the displayInteger function, you must pass a second parameter indicating whether the integer should be prefixed with 0s (i.e., 123 will become 000123 if set to true).
The last option would be to use the display function, which would look something like this:
cpp// Array for displaying digits, the first number in the array will be displayed on the right int8_t ListDisp[6] = {0,1,2,3,4,5}; // Array for displaying points, the first point in the array will be displayed on the right int8_t ListDispPoint[6] = {POINT_ON,POINT_OFF,POINT_OFF,POINT_OFF,POINT_OFF,POINT_OFF}; void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.setTimeout(15); //Activate the tm1637 tm1637_6D.set(BRIGHT_DARKEST); tm1637_6D.init(); } void loop() { tm1637_6D.display(ListDisp, ListDispPoint); }
This will print the content of the ListDisp array and place dots according to the ListDispPoint array. The display starts at the right, checking if POINT_OFF or POINT_ON is set for each possible dot present on display. The same goes for the numbers.
This code makes use of the Bits and Droids flight connector to connect to Microsoft flight simulator 2020.
It's important to select Active com 1, and the com port should be set to the com port your Arduino is connected to. In the case of an Arduino Uno, Mega, or Nano, a 10 Uf capacitor is required between the reset and ground pin.
If you ever encounter one of these displays and get stuck like I did, the code above will save you some time.
Thanks for reading, and I'll see you next time!