Smaller 4x5 font for 'sideways' NeoPixel 40

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
AeroBoy
 
Posts: 1
Joined: Mon Aug 25, 2014 6:32 am

Smaller 4x5 font for 'sideways' NeoPixel 40

Post by AeroBoy »

Hi there!

I'd like to understand how I can use my own 4x5 font data with a 5x8 neopixel array. I've done some work making the characters, padding them with zeros, inserting them into the 5x7 font data file, and displaying them on the LED array. I can do this without any problems. The problem is that I'd like to be able to construct a string and then display it without a large gap between characters, whithout having to move the cursor left one position after displaying each character.

I'm trying to upcycle an old clock radio into an LED clock using 2 of the 5x8 neopixel boards, and an Arduino Pro Mini. The shape of the old clock radio that I wish to use is such that the NeoPixels will have to be mounted 'sideways' with a total of 5 horizontal lines, each containing 16 LEDs (when the two neopixel boards are placed side by side).

I'm trying to create my own font table with numbers (and some other characters) that are 5 bits tall and 4 bits wide. Whenever I try to make my own font that isn't 5 bits wide (ie a different width from the font data is stored in glcdfont.c) I have the problem that the matrix does not display what I hope. Here are exerts from the two font data files. First the glcdfont.c file, and then my own:

Code: Select all

//exert from gcldfont.c lines 62 - 71
//bytes 240 - 289 of font
//characters 0 - 9
.....	0x3E, 0x51, 0x49, 0x45, 0x3E,
	0x00, 0x42, 0x7F, 0x40, 0x00,
	0x72, 0x49, 0x49, 0x49, 0x46,
	0x21, 0x41, 0x49, 0x4D, 0x33,
	0x18, 0x14, 0x12, 0x7F, 0x10,
	0x27, 0x45, 0x45, 0x45, 0x39,
	0x3C, 0x4A, 0x49, 0x49, 0x31,
	0x41, 0x21, 0x11, 0x09, 0x07,
	0x36, 0x49, 0x49, 0x49, 0x36,
	0x46, 0x49, 0x49, 0x29, 0x1E, .....
In case anyone is reading this who doesn't understand what this data means. Each of these '0x##' represents a number in hexadecimal. 0x indicates that the number is expressed in hex, and the ## is the hex number itself. A two digit hex number encodes a byte of binary data - which is a sequence of eight 1s or 0s. The 0x3E term encodes the binary data 01111110, which is the left hand column of the zero character. Note that the data reads up the way, so the first 0 in this binary data is the bottom left corner of the zero character. The second column of the zero character is 0x51, which encodes 10100001.

Code: Select all

//exert from Aeroboyfont.c lines 62 - 71
//bytes 188 - 227 of font
//characters 0 - 9
.....	0x0E,0x11,0x11,0x0E, //0
	0x00,0x12,0x1F,0x10, //1
	0x12,0x09,0x15,0x12, //2
	0x05,0x07,0x07,0x03, //3
	0x0F,0x08,0x1C,0x08, //4
	0x17,0x15,0x15,0x09, //5
	0x0E,0x15,0x15,0x08, //6
	0x01,0x19,0x05,0x02, //7
	0x0A,0x15,0x15,0x0A, //8
	0x02,0x15,0x15,0x0A, //9 .....
When I include my font file in place of the glcdfont file (modifying line 35 of Adafruit_GFX.cpp) and run the following arduino sketch (based on the matrixtest example), nothing happens - all the LEDs remain in darkness. If I add an additional column of 0x00 to the right side of each line in the data, then my characters are displayed, but there is a large gap between characters.

(When I run this sketch with the original font definition and include statement in Adafruit_GFX.cpp I see the to 5x5 area of the full 5x7 numeric characters being displayed in order from 0 to 9).

Code: Select all

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
 #define PSTR // Make Arduino Due happy
#endif

#define PIN 2

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 5, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);

const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(10);
  matrix.setTextColor(colors[0]);
  matrix.fillScreen(0);
  delay(2000);
}

void loop() {
 for(int i=0; i<=9; i++) {
  matrix.fillScreen(0);
  matrix.setCursor(0, 0);
  matrix.print(String(i));
  matrix.show();
  delay(1000);
 }
}
I know I could alter the original font data file with my own characters (I have tried this, padding them with an extra column of 0x00 on the right hand side - and it seems to work fine), and move the cursor to the left one LED each time I print a character... But I would like to understand how I can modify the code so that I can simply use matrix.print with a smaller font... As long as its not insanely complicated(!)

I assume there is a mapping / calculation called by matrix.print that returns the correct bytes of font data given an ascii character code - and its this mapping that I need to modify in order to implement my smaller font... Is this correct? I have looked through the code but cannot find anything obvious. Can you point me in the right direction please?

Thanks in advance.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Smaller 4x5 font for 'sideways' NeoPixel 40

Post by adafruit_support_rick »

The AdafruitGFX::drawChar function is hardcoded for a 6x8 character space. You'll have to modify drawChar to change the hardcoded constants.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”