Convert hex to ascii numerals

I am trying to take in a scoreboard signal and convert the hex values to ascii numerals to display on a video display using an Arduino Uno. The picture below shows a table of which hex values translates to which numerals. For example, for a 20:00 clock the values coming in from the scoreboard controller would be DB BF BF BF and I need to convert it to 2000.

Here is a sample packet of the scoreboard data.

Can someone help me with the code for converting this?

What is the H segment - the colon?

1 Like

an ASCII table describes the value for characters, but the values you've posted suggest these are the values for a 7-segment display where the h-segment is commonly the decimal point.

but your values don't make sense as 7-segment values. while 2 segments are on for '1', 0x06, and 3 for '7', 0x07, none should be on for zero, but you have 0x3f

ASCII digits state with a value of 0x30 for zero. so "2000" is 0x32, 0x30, 0x30, 0x30. the value for ':" is 0x3A

1 Like

If I understand you correctly, you're trying to say that the data coming down is already translated to bit-per-segment for the digits of the display. If that's not it, please try to re-explain.

1 Like

I think you screwed up the example, because if the first two characters should be 1, then they should be 0x86, not 0xBF? The rest is off, as well.

1 Like

If I'm right so far, then this is a simple lookup table, OR, a very straightforward switch..case structure. Look at the Switch construct here:

I suggest you take a try at it, see what you can do, come back and post what you've got if your stuck.

1 Like

I suggest you spend some time studying number bases, this link will help: Number Bases The machine works in binary and your code defines the meaning of numbers, they can be whatever you want. Also look at the possibility your 1s and 0s are inverted. Post a link to the technical information on the score board, that will help us help you and possibly save weeks of time.

Yes, the data coming down is already translated to bit-per-segment. The older dot digit scoreboards used the H segment and the newer bar digit scoreboards only use 7 segments so sometimes they will use the H segment for something like a possession or bonus arrow. You are correct about the example they gave me. They should be 0-7 and not 1-8 on the numerals.

I'll take a look at this and see what I can figure out. Thanks!

Here's a start. Once you have a character in a variable,

bool special;
uint8_t var;
//get your character into var
switch (var) {
  case '0xBF':
    val = 0x30;
    special = true;
break;
case '0x3F':
    val = 0x30;
    special = false;
    break;
  //and so on
case label2:
    // statements
    break;
  default:
    // statements
    break;
}
//now you have val for your number, and special flags whether the bit was set, whatever it means.

Typed here in the forum, so you can expect errors. Good Luck!

You could also strip the high bit from the var first, of course, which will simplify your switch...case.
something like

special = (var&0x80)?1:0;

will leave special with a 0 or 1 value.
Then,
switch(var&0x7f) {

should allow you to use only the one column of values from your table.

YMMV.

I will give these a try. Thank you!

it seems the "scoreboard signal" is unique to some venders scoreboard, actually encoding the digits for that venders hardware

it would make more sense for the cmd to provide data in ASCII and the display software translates the ASCII into whatever encoding is necessary for the hardware. of course it's simple if the display hardware accepts ASCII

nonetheless, look this over

output:

    0xBF 31 1
    0xBF 31 1
    0x86 32 2
    0x86 32 2
    0xDB 33 3
    0xDB 33 3
    0xCF 34 4
    0xCF 34 4
    0xE6 35 5
    0xE6 35 5
    0xED 36 6
    0xED 36 6
    0x87 38 8
    0x87 38 8
    0xFF 39 9
    0xFF 39 9

char s [90];

// -----------------------------------------------------------------------------
const byte codeTbl [] = {
    0x3f, 0x06, 0x5b, 0x4f, 0x66,  0x6d, 0x7d, 0x07, 0x7f, 0x67, 0x00 };
const byte asciiTbl [] = {
    '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ' };
const int Ncodes = sizeof(codeTbl);

byte
translate (
    const byte code )
{
    for (int n = 0; n < Ncodes; n++)
        if (codeTbl [n] == (code & 0x7f))
            return asciiTbl [n];

    return 0;
}

// -----------------------------------------------------------------------------
const byte testData [] = {
    0x55, 0xaa, 0x01, 0x11,   0x05, 0xea, 0x22, 0xbf,
    0xbf, 0x86, 0x86, 0xdb,   0xdb, 0xcf, 0xcf, 0xe6,
    0xe6, 0xed, 0xed, 0x87,   0x87, 0xff, 0xff, 0x4e };
const int Ndata = sizeof(testData);

void
setup (void)
{
    Serial.begin (9600);

    for (int n = 0; n < Ndata; n++)  {
        char asc = translate (testData [n]);
        if (0 != asc)  {
            sprintf (s, "    0x%02X %02x %c", testData [n], asc, asc);
            Serial.println (s);
        }
    }
    Serial.println ();
}

void
loop (void)
{
}

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