Jump to content

Help with 7 Segment Display code


rocketeer

Recommended Posts

I recently bought a bunch of HT16K33 7 segment displays. Four digits each. It has 4 pins-VCC, ground, and D and C. I googled for examples of how to use them in dcs bios. Some used sevenseg.h, some HT16K33.h, some adafruit display etc. I installed the libraries and code but couldn't compile. I followed the example of sevenseg and my display lit up but couldn't figure the dcs bios code.

Please someone provide example for 7 segment code for tacan, ILS, or VHF/UHF etc? I got all input code for the A10 working but output is totally new to me.

 

 

IMG_6670.jpg

Link to comment
Share on other sites

Your display is of the I2C type. That means, the four wires are C (clock or SCL), D (data or SDA), VCC (supply voltage) and GND (ground).

SDA and SCL are to be connected to the Arduino's I2C bus. For the Uno and Nano these are pins A4 and A5.

I'm afraid you have to read more about the used libraries, as most people here seem to use another chip (Max7219) and therefore different libraries.

 

Regards, Vinc


Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

By "I followed the example of sevenseg and my display lit up", do you mean the display showed the numbers test patterns?

If it doesn't, you should try to get that working first.

If it does, leave the wiring for the display as-is and try t
his code.
It should display the Airspeed in knots on the display:

/*
  Tell DCS-BIOS to use a serial connection and use interrupt-driven
  communication. The main program will be interrupted to prioritize
  processing incoming data.
  
  This should work on any Arduino that has an ATMega328 controller
  (Uno, Pro Mini, many others).
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

/* paste code snippets from the reference documentation here */

void onIasUsIntChange(unsigned int newValue) {
    matrix.println(newValue);
    matrix.writeDisplay();
}
DcsBios::IntegerBuffer iasUsIntBuffer(0x042e, 0xffff, 0, onIasUsIntChange);



void setup() {
  DcsBios::setup();

    matrix.begin(0x70);
}

void loop() {
  DcsBios::loop();
}

The number comes from the Common Data, so it should work with any DCS-BIOS supported aircraft.

Link to comment
Share on other sites

On 10/17/2021 at 1:35 AM, Vinc_Vega said:

Your display is of the I2C type. That means, the four wires are C (clock or SCL), D (data or SDA), VCC (supply voltage) and GND (ground).

SDA and SCL are to be connected to the Arduino's I2C bus. For the Uno and Nano these are pins A4 and A5.

I'm afraid you have to read more about the used libraries, as most people here seem to use another chip (Max7219) and therefore different libraries.

 

Regards, Vinc

 

Yes Vinc I now realized it’s different than the max 7219, but this is adafruit which should be quite common too. On the mega it’s pin 20 and 21.

 

if I were to use the max7219, can you provide some example of the code in the A10C? Whether for the radios or tacan or ILS etc?

Link to comment
Share on other sites

On 10/17/2021 at 6:51 AM, No1sonuk said:

By "I followed the example of sevenseg and my display lit up", do you mean the display showed the numbers test patterns?

If it doesn't, you should try to get that working first.

If it does, leave the wiring for the display as-is and try t
his code.
It should display the Airspeed in knots on the display:

/*
  Tell DCS-BIOS to use a serial connection and use interrupt-driven
  communication. The main program will be interrupted to prioritize
  processing incoming data.
  
  This should work on any Arduino that has an ATMega328 controller
  (Uno, Pro Mini, many others).
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

/* paste code snippets from the reference documentation here */

void onIasUsIntChange(unsigned int newValue) {
    matrix.println(newValue);
    matrix.writeDisplay();
}
DcsBios::IntegerBuffer iasUsIntBuffer(0x042e, 0xffff, 0, onIasUsIntChange);



void setup() {
  DcsBios::setup();

    matrix.begin(0x70);
}

void loop() {
  DcsBios::loop();
}

The number comes from the Common Data, so it should work with any DCS-BIOS supported aircraft.

NO1sonuk, I tried all the examples in example library. The 4 digit 7 segment display lit up each time. But when I used your code nothing happens. Maybe because there is no expected digital IAS, only for servo IAS?

I saw something has example for alphanumeric HT16K33, 14 segment for the A10 Tacan. I also have one of these. Again I tried the examples and it lit up, showing that i wired it correctly. But again when I ran it in the sim it did not light up at all.

I know this HT16K33 is not as common as the max7219, but I’ve heard of the adafruit brand before and my impression is that it is not that uncommon.

Is there no one else using this 7 segment display for the A10 to help? I studied the keywords in the library and tried editing and compiling the code many times. Yet to figure out enough to make it work. I didn’t expect it to this difficult.

Link to comment
Share on other sites

24 minutes ago, rocketeer said:

NO1sonuk, I tried all the examples in example library. The 4 digit 7 segment display lit up each time. But when I used your code nothing happens. Maybe because there is no expected digital IAS, only for servo IAS?

I tried that on the P-51D AND the A-10C before I posted it.  It worked on both.
The Common Data has integer output for a few of the numbers such as airspeed, course and altitude. 


Which version of DCS-BIOS are you using, and are you sure it was actually connected to the arduino?

It really isn't difficult to get it going.
The reason it took me so long to respond yesterday was I saw it after Vince had already responded and I had to do some shopping, then solder a pin header to one of my spare displays, wire it up, write the code, test it in two aircraft and post it.


This works for me in both the "Hub" AND "Flightpanels" forks of DCS-BIOS to display the ILS frequency of the A-10C.
 

/*
  Tell DCS-BIOS to use a serial connection and use interrupt-driven
  communication. The main program will be interrupted to prioritize
  processing incoming data.
  
  This should work on any Arduino that has an ATMega328 controller
  (Uno, Pro Mini, many others).
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

float ILS_Freq ;

/* paste code snippets from the reference documentation here */

void onIlsFrequencySChange(char* newValue) {
    /* your code here */
    ILS_Freq = atof(newValue);  // Convert the string value to a floating point number

    matrix.print(ILS_Freq);
    matrix.writeDisplay();
}

DcsBios::StringBuffer<6> ilsFrequencySBuffer(0x12d8, onIlsFrequencySChange);


void setup() {
  DcsBios::setup();

    matrix.begin(0x70);
}

void loop() {
  DcsBios::loop();
}

It rounds it to 4 digits, so you get 1 decimal point - "108.25" will display as "108.3".

If that doesn't work, you're doing something wrong.

Link to comment
Share on other sites

No1sonuk,

Thanks very much for sharing the code for ILS. It works. like you said, it shows 4 digits only. There is no space on the panel for 2x4 digits displays anyway. I think the way to show 5 digits is those tedious 5x1 displays.

I tested your IAS again. It still does not work for the A10C or A10C II. maybe it due to my dcs bios version? I'm using 0.7.41. I used manual install, not using the hub version, which stops working for all switches after 5 minutes every time. But it works on the P-51, and even on the F-18, though the digital display is about 10 knots lower than the hornet's speed on the HUD.

So these adafruit GFX and LEDbackpack libraries are the correct ones for my 7 seg display.

Do you mind sharing the code for the VHF, UHF, Tacan too? I know how to get all digital inputs working. And basic LED output too. But these 7 segment display have all kinds of string, char, float conversions from the examples i've seen for tacan and vhf. 

For the mega, the wire the SDA and SCL to pins 20 and 21. I don't specify pin numbers like those using the max7219. So for each mega it can only handle 4 digits? Like for VHF AM or FM we need 2x4 digits we will need 2 megas? or they can be daisy chained? wait, there is no space on the panel for 2x4 digits. Do you guys get those 6 digits display instead?

I see besides HT16K33, there is max7219 and TM1637 type of 7 segments. Looks like I not not only bought a less popular type, I bought them too big. My displays are 0.75" tall. I see there are 0.36" and 0.56" ones.

Which type and what size do you guys recommend for the VHF, UHF, TACAN etc? I know TACAN will need to be a 14 segment display.

 

 

Link to comment
Share on other sites

WRT the "Only one display per arduino":
No. I've made a project for another hobby that uses two on the same arduino I2C bus.  You can have up to 8.

On the back of the PCB, there are 3 pairs of "unused" solder pads close together.  Those can be used to change the I2C address of the display to one of 8 different numbers.

So the setup line changes from:
 

matrix.begin(0x70);

to:

matrix1.begin(0x70);
matrix2.begin(0x71);

 

Don't forget you'll need this with the includes:

Adafruit_7segment matrix1 = Adafruit_7segment();
Adafruit_7segment matrix2 = Adafruit_7segment();



Then, to write to the individual display, you add the number to the "matrix" identifier.

e.g.
 

    matrix.print(ILS_Freq);
    matrix.writeDisplay();

becomes

    matrix1.print(ILS_Freq);
    matrix1.writeDisplay();


And you'd use

    matrix2.print(VARIABLENAME);
    matrix2.writeDisplay();

for the second display

Take a look here:
https://learn.adafruit.com/adafruit-led-backpack/connecting-multiple-backpacks

The big issue you have to be careful of with those is the power used.  You should use an external 5V power supply if you're going to run more than one from one arduino - the arduino's power regulator may not be up to supplying that much power.

Adafruit says the 7-segment backpacks draw up to 160mA fully lit - IIRC, the Nano's regulator can supply a maximum of 800mA.
But you won't get the full 800mA as the actual number depends on the supply voltage and current.

You can use an external 5V supply in two ways:
1) Leave the 5V connection in place to the arduino and power the arduino from your separate PSU as well.
2) Power the arduino separately (e.g. from USB).  If you do this, disconnect the display 5V line from the arduino and connect it to the PSU. Leave the other three lines connected.
 


The 7219 displays are better for frequencies as they have 8 digits available, and more can be daisy-chained together if you want.

I've seen some mention of people using the 2x4-digit display boards for the interface, then splitting the LEDs off to more accurate locations than all in one row.

The problem with 7 segment displays is you can't reproduce every letter, so the TACAN ones with "X" won't reproduce.
For the TACAN, you might be better of trying a graphic OLED.

Link to comment
Share on other sites

  • 3 weeks later...

I think that he means, removing the seven segment LEDs from the PCB (desolder) and replacing them with the same size other color segments. Not changing the LEDs itselfs.

 

Regards, Vinc

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

10 hours ago, Vinc_Vega said:

I think that he means, removing the seven segment LEDs from the PCB (desolder) and replacing them with the same size other color segments. Not changing the LEDs itselfs.

Exactly this.

And if you need a different layout (spacing) of numbers, this is the way to achieve that.

Link to comment
Share on other sites

So you guys are saying get the max 7219 tube for its PCB sake. Then change the LEDs on top? Never thought of separating them. Good idea.

I see some type have removable pins thus no need to desolder, resolder. But to replace them with the right color 7 segments its asking to choose common cathode or anode. I suppose the max7219 tube would state which type it uses.

 

C8760489-A18E-4B54-A280-D1C2BC4CA799.jpeg

8A4ACAB2-A677-4BAB-B79A-98698E8E333D.jpeg


Edited by rocketeer
Link to comment
Share on other sites

thanks for being so quick to answer.

I don't see any vendor out there on amazon, ebay or aliexpress selling removable max7219 tube other than 8 digits. can't find 4 or 2 digit removable type.

those less than 8 digit use other types of chip, same with color. it sucks to have to search high and low to get the right number of digits and color.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...