Hi everyone,
I am developing a simple display to show data such as speed, battery voltage, battery current and power controller temperature for an electric car for my grandchildren (total overkill I know, but it's about the learning and the journey rather than the true need).
I am using a SainSmart Mega2560, shield and 3.2" TFT display (SSD1289). I have loaded Henning Karlsen's UTFT and ITDB02_Touch libraries along with the UTFT_DLB library. I am using the 'standard' (?!) IDE (loaded in January 2015) and AVRISP mkII programmer.
I have a working display using fixed width fonts (specifically arial_bold.c and GroteskBold32x64.c) from RinkyDinky. The font files are loaded in the sketch folder.
At this point everything works as required/intended. However, the display would look so much better if it used variable width characters.
I have tried to use several TTF files and run several examples using TTFs. I have tried modifying the headers of the font files and the declarations in the main sketch to match the fixed font formats and, similarly, using guidance from other threads to try to get the right syntax. All without success. From the error messages/codes I get when trying to compile, the problem generally seems to be in declaring the font files as a 'const' variable to be compatible with PROGMEM.
I have read many threads on several forums concerning this issue. Some thread outcomes seem to suggest there is a resolution, but without posting the final means used to solve the problem! Other threads seem inconclusive.
To try to isolate the problem I have written a test sketch (called "TTF_Trial") using a fixed width font (GroteskBold32x64) which displays a variable value in alternate colours on successive loop cycles. This complies and works fine (no variable width characters used). I then introduced the TTF (DejaVuSans24) which errors on the definition of the TTF variable in the font (DejaVuSans24.c) file.
My main sketch file code is here:
// ITDB02_Touch_ButtonTest (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a quick demo of how create and use buttons.
//
// This program requires the ITDB02_Graph library (8bit mode)
// or ITDB02_Graph16 (16bit mode).
//
// It is assumed that the ITDB02 module is connected to a
// ITDB02 Shield, a ITDB02 Mega Shield or that you know how
// to change the pin numbers in the setup.
//
// Remember to change the next line if you are using as 16bit module!
//#include <UTFT.h>
#include <UTFT_DLB.h>
#include <ITDB02_Touch.h>
// Declare which fonts we will be using
extern uint8_t GroteskBold32x64[];
extern uint8_t DejaVuSans24[];
UTFT_DLB myGLCD(SSD1289, 38, 39, 40, 41);//UTFT_DLB
ITDB02_Touch myTouch(6, 5, 4, 3, 2);
float spd=2.8;
boolean State;
void setup()
{
// Initial setup
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(GroteskBold32x64);
myGLCD.setBackColor(0, 0, 255);
}
void loop()
{
if (State == true)
{
State = !State;
myGLCD.setFont(GroteskBold32x64);
myGLCD.setColor(255, 0, 0);
myGLCD.printNumF(spd,1, 15,87);
myGLCD.setFont(GroteskBold32x64);
myGLCD.setColor(255, 0, 0);
myGLCD.printNumF(spd,1, 150,87);
}
else
{
State = !State;
myGLCD.setFont(DejaVuSans24);
myGLCD.setColor(0, 255, 0);
myGLCD.printNumF(spd,1, 15,87);
myGLCD.setFont(GroteskBold32x64);
myGLCD.setColor(0, 255, 0);
myGLCD.printNumF(spd,1, 150,87);
}
delay(500);
}
The header of the DejaVuSans24.c font file and the initial character data only is here:
// This comes with no warranty, implied or otherwise
// This data structure was designed to support Proportional fonts
// on Arduinos. It can however handle any ttf font that has been converted
// using the conversion program. These could be fixed width or proportional
// fonts. Individual characters do not have to be multiples of 8 bits wide.
// Any width is fine and does not need to be fixed.
// The data bits are packed to minimize data requirements, but the tradeoff
// is that a header is required per character.
// DejaVuSans.c
// Point Size : 24
// Memory usage : 2724 bytes
// # characters : 95
// Header Format (to make Arduino UTFT Compatible):
// ------------------------------------------------
// Character Width (Used as a marker to indicate use this format. i.e.: = 0x00)
// Character Height
// First Character (Reserved. 0x00)
// Number Of Characters (Reserved. 0x00)
#include <avr/pgmspace.h>
const uint8_t DejaVuSans24[] PROGMEM =
{
0x00, 0x17, 0x00, 0x00,
// ' '
0x20,0x13,0x00,0x00,0x00,0x08,
// '!'
0x21,0x01,0x02,0x12,0x04,0x0A,
0xFF,0xFF,0xFF,0x03,0xF0,
// '"'
0x22,0x01,0x06,0x07,0x02,0x0B,
0xCF,0x3C,0xF3,0xCF,0x3C,0xC0,
// '#'
0x23,0x01,0x10,0x12,0x02,0x14,
0x03,0x08,0x03,0x18,0x03,0x18,0x03,0x18,0x02,0x18,0x7F,0xFF,0x7F,0xFF,0x06,0x30,0x04,0x30,0x0C,0x20,0x0C,0x60,0xFF,0xFE,0xFF,0xFE,0x18,0x40,0x18,0xC0,0x18,0xC0,0x18,0xC0,0x10,0xC0,
// '
And the error report is here:
DejaVuSans24.c:26: error: variable 'DejaVuSans24' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
uint8_t DejaVuSans24[] PROGMEM =
^
In reviewing this before posting, I realized I had missed "requires the ITDB02_Graph library" instruction in the original Henning Karlsen sketch I used as a sketch model, so I downloaded the 8-bit version and included it in the main sketch (not shown in the code sample above). This does not compile either, but the error report now says:
In file included from C:\Users\Martin\Martin stuff\Arduino\Sketches\TTF_Trial\TTF_Trial.ino:18:0:
C:\Users\Martin\Martin stuff\Arduino\libraries\ITDB02_Graph/ITDB02_Graph.h:75:8: error: redefinition of 'struct _current_font'
struct _current_font
^
In file included from C:\Users\Martin\Martin stuff\Arduino\Sketches\TTF_Trial\TTF_Trial.ino:15:0:
C:\Users\Martin\Martin stuff\Arduino\libraries\UTFT/UTFT.h:188:8: error: previous definition of 'struct _current_font'
struct _current_font
^
This my first post to any forum so please forgive any failure of protocol.
Any assistance would be greatly appreciated.
Regards,
Martin
And the error report is here:
§DISCOURSE_HOISTED_CODE_2§
In reviewing this before posting, I realized I had missed "requires the ITDB02_Graph library" instruction in the original Henning Karlsen sketch I used as a sketch model, so I downloaded the 8-bit version and included it in the main sketch (not shown in the code sample above). This does not compile either, but the error report now says:
§DISCOURSE_HOISTED_CODE_3§
This my first post to any forum so please forgive any failure of protocol.
Any assistance would be greatly appreciated.
Regards,
Martin