ASCII to 6-bit lookup table?

Hi,

I've got a NYSE LED ticker that I finally figured out how to write characters to. It uses a 6-bit character code at 134.5 bits per second. I haven't figured out how to make Serial write to it, but I can bit-bang it.

I need help understanding how to convert ASCII characters to the character codes. Do I need a lookup table or what, and what should that look like.

Here is the table for the characters:

0x00		Undef
0x10		T
0x20		Figure D
0x30		1/8

0x01		E
0x11		Z
0x21		5
0x31		7/8

0x02		Letter Dot
0x12		L
0x22		C
0x32		S/S

0x03		A
0x13		W
0x23		1
0x33		1/2

0x04		Pr
0x14		H
0x24		Figure Dot
0x34  		8

0x05		S  
0x15		Y
0x25		S
0x35		3/4

0x06		I
0x16		P
0x26		9
0x36		S/T

0x07		U
0x17		Q
0x27		Spare 1/
0x37		1/4

0x08		WI
0x18		O
0x28		0     
0x38		Spare Figure Dot

0x09		D
0x19		B
0x29		4
0x39		2

0x0A		R
0x1A		G
0x2A		End Announcement Char
0x3A7

0x0B		J
0x1B		&
0x2B		Begin Announcement Char
0x3BB

0x0C		N
0x1C		M
0x2C		Space 
0x3C		$

0x0D		F
0x1D		X
0x2D		6
0x3D		5/8

0x0E		C
0x1E		V
0x2E		3
0x3E		3/8

0x0F		K
0x1F		R/T
0x2F		Spare Figure Dot
0x3F		Undef

And here is what my sketch for HELLO WORLD looks like:

int interval = 7;
int charDelay = 1;

char myText[]={0x14, 0x01, 0x12, 0x12, 0x18, 0x2C, 0x13, 0x18, 0x0A, 0x12, 0x09, 0x2C};

void setup() {
  pinMode(1, OUTPUT);
}

void loop(){
   for (int i = 0; i < 12; i ++){
     displayChar(myText[i]);
   }
}

void displayChar(byte charToDisplay){
  startBit();
    for (byte i = 0; i < 6; i ++){
      byte myBit = bitRead(charToDisplay, i); // the letter C 0r 001110  
      digitalWrite(1, myBit);
      delay(interval);
    }
    stopBit();
}

void stopBit(){            // two intervals of stop bit
  digitalWrite(1, LOW);
  delay(interval);
  delay(interval);
  digitalWrite(1, HIGH);
}

void startBit(){         // one interval for start bit
  digitalWrite(1, LOW); 
  delay(interval);
  digitalWrite(1, HIGH);
}

I plan to use a computer to send serial data to the ticker over an HC-05 bluetooth serial module from maybe a Raspberry Pi or other computer. Maybe I should do the data conversion on the sending side? Any pointers for doing that in Python also appreciated.

Thanks,

Jimmy

If you can find the logic for the conversion, you do not need a lookup table. Else you need one.

I would use two lookup tables. One for the alphabetic chars and one for the numerics. There aren't enough punctuation symbols to warrant a lookup table.

char alpha_6bit[26] = {
	0x03, //A
	0x19, //B
	// Fill in the rest of these
	...
	0x15, //Y
	0x11, //Z
};

char num_6bit[10] = {
	0x28 //0
	// Fill in the rest of these
	...
	0x26 //9
};

// Translate the ASCII character c to a 6-bit code.
// If the character is not found, return zero.
char ASCII_6bits(char c)
{
	c = toupper(c);
	if((c >= 'A') && (c <= 'Z'))return alpha_6bit[c - 'A']);
	if((c >= '0') && (c <= '9'))return num_6bit[c - '0']);
	// Handle the remaining punctuation characters
	if(c == ' ')return 0x2C;
	if(c == '

Pete)return 0x3C;
if(c == '&')return 0x1B;
return 0;
}


Pete

Thanks for the info, Pete. Can you show an example of how you access the array in the case you show? If I want to get 'A' (0x03), how do I reference the index? Do I just count because I know 'A' is 0 and 'B' is 1?

Or maybe subtract 0x41 to turn ASCII "A" into "0" for the index?

I was looking at the python side and found the Dict structure, which makes the conversion somewhat easy.

myChars = {	'N/A': 0x00,
          	'T':0x10,
          	'FIG DOT':0x20,
           	'1/8':0x30,
           	'E':0x01 ,
           	'Z':0x11 ,
           	'5':0x21 ,
           	'7/8': 0x31,
           	'LET DOT':0x02,
           	'L':0x12 ,
           	'C':0x22,
           	'S/S':     0x32,
           	'A':0x03,
		'W':0x13 ,
		'1':0x23,
		'1/2':0x33,
		'Pr':0x04,
		'H':0x14,
		'FIG DOT':0x24,
  		'8':0x34 }

and then I can do something like:

print hex(myChars['T'])

to get 0x10

Thanks for looking.

The ASCII_6bits function does the translation for you. Just call it for each character. For example:

Serial.println(ASCII_6bits(' '),HEX);

will print 2C.

Pete

Thanks Pete. I didn't see the ASCII_6bits(), I didn't scroll the block far enough!

Thanks.

Jimmy

Thanks so much for this help Pete! It was perfect and my stock ticker is ticking once again!

Karma and many thanks!