Announcement

Collapse
No announcement yet.

Displaying custom fonts from Arduino

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying custom fonts from Arduino

    Hopefully someone can supply a bit of sample code to get me over my problem of not being able to display custom fonts using serial commands from an Arduino.
    I would have thought that host sample code would have been provided in the application notes, but alas, that is not the case.

    I followed the procedures in App Note 89 and all worked pretty much as detailed. I was able to successfully display the custom font on the screen using Serial Commander.
    However... when I try to display the fonts using the Arduino I am having no joy.

    The screen I have is the Gen4-uLCD-35DCT-CLB
    The font files on the uSD card are named Fonts.d01 and Fonts.g01
    The uSD was successfully mounted using the Arduino.
    If it is of any use, the response when using Serial Commander was (ACK 16072 0x3EC8) when loading this custom font.

    I have declared
    word hFont1;

    Setup() contains:
    hFont1 = Display.file_LoadImageControl("Fonts.d01", "Fonts.g01", 1);

    Loop() contains:
    Display.txt_FontID(hFont1) ;
    Display.txt_FGcolour(WHITE) ;
    Display.txt_BGcolour(BLACK) ;
    Display.gfx_MoveTo(50 , 100) ;
    Display.putstr("Test") ;
    delay(1000);


    What am I missing?
    Last edited by SkiFreak; 2 weeks ago.

  • #2
    Hey guys...
    Surely someone from 4D can put together a sample .ino file that shows everything that is required to load a custom font.
    I have definitely wondered why these not included in the Application Notes, as it would make the learning curve much easier if they were.

    Comment


    • #3
      Good day!

      The appnote you mentioned was meant to be a general discussion for adding fonts in an SPE display. It uses the Serial Commander tool to demonstrate the process. This is so developers are not restricted by simply following a library.

      Since you have tried using the Serial Commander and it worked, then your code should simply match this process.

      However, based on your discussion, there doesn't seem anything wrong with your code.

      Can you tell us exactly what happens? Does anything print at all and simply using incorrect font? or is there nothing printed?

      It might help us if you could provide your project for us to further investigate.

      Here's a sample snippet of using fonts:

      Code:
      Serial.begin(115200) ; // serial to USB port
      
      pinMode(RESETLINE, OUTPUT); // Display reset pin
      digitalWrite(RESETLINE, 1); // Reset Display, using shield
      delay(100); // wait for it to be recognised
      digitalWrite(RESETLINE, 0); // Release Display Reset, using shield
      delay(3000) ; // give display time to startup
      
      // now start display as Serial lines should have 'stabilised'
      DisplaySerial.begin(9600) ; // Hardware serial to Display, same as SPE on display is set to
      Display.TimeLimit4D = 5000 ; // 5 second timeout on all commands
      Display.Callback4D = mycallback ;
      
      Display.gfx_ScreenMode(PORTRAIT) ; // change manually if orientation change
      Display.putstr("Mounting...\n");
      if (!(Display.file_Mount()))
      {
        while (!(Display.file_Mount()))
        {
          Display.putstr("Drive not mounted...");
          delay(200);
          Display.gfx_Cls();
          delay(200);
        }
      }
      hFont1 = Display.file_LoadImageControl("Fonts.d01", "Fonts.g01", 1); // Open handle to access uSD fonts, uncomment if required and change nn to font number
      //hstrings = Display.file_Open("Fonts.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
      hndl = Display.file_LoadImageControl("Fonts.dat", "Fonts.gci", 1);
      
      // put your setup code here, to run once:
      Display.gfx_RectangleFilled(16, 28, 215, 227, BLACK);
      Display.txt_FontID(hFont1) ; // Font index correct at time of code generation
      Display.txt_FGcolour(WHITE) ;
      Display.txt_BGcolour(BLACK) ;
      Display.gfx_MoveTo(16 , 28) ;
      Display.putstr("Your text goes here") ;
      Best Regards,
      Juniel Cruz

      Comment


      • #4
        Thanks for the response Juniel.
        Why your code works and mine does not is something I will have to look into further. Very weird!

        This is your code, slightly modified, which does work.
        Code:
        #define DisplaySerial Serial // Using Hardware Serial
        
        #include "Diablo_Serial_4DLib.h"
        #include "Diablo_Const4D.h"
        
        Diablo_Serial_4DLib Display(&DisplaySerial);
        
        #define RESETLINE 4
        
        word hndl;
        word hFont1;
        word hFont2;
        word hFont3;
        
        void setup(){
        Serial.begin(115200) ; // serial to USB port
        
        pinMode(RESETLINE, OUTPUT); // Display reset pin
        digitalWrite(RESETLINE, 1); // Reset Display, using shield
        delay(100); // wait for it to be recognised
        digitalWrite(RESETLINE, 0); // Release Display Reset, using shield
        delay(3000) ; // give display time to startup
        
        // now start display as Serial lines should have 'stabilised'
        DisplaySerial.begin(9600) ; // Hardware serial to Display, same as SPE on display is set to
        Display.TimeLimit4D = 5000 ; // 5 second timeout on all commands
        //Display.Callback4D = mycallback ;
        
        Display.gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
        Display.putstr("Mounting...\n");
        if (!(Display.file_Mount()))
        {
        while (!(Display.file_Mount()))
        {
        Display.putstr("Drive not mounted...");
        delay(200);
        Display.gfx_Cls();
        delay(200);
        }
        }
        hFont1 = Display.file_LoadImageControl("Fonts.d01", "Fonts.g01", 1); // Open handle to access uSD fonts
        hFont2 = Display.file_LoadImageControl("Fonts.d02", "Fonts.g02", 1); // Open handle to access uSD fonts
        hFont3 = Display.file_LoadImageControl("Fonts.d03", "Fonts.g03", 1); // Open handle to access uSD fonts
        //hstrings = Display.file_Open("Fonts.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
        //hndl = Display.file_LoadImageControl("Fonts.dat", "Fonts.gci", 1);
        
        // put your setup code here, to run once:
        Display.gfx_RectangleFilled(16, 28, 215, 227, BLACK);
        
        Display.txt_FGcolour(WHITE) ;
        Display.txt_BGcolour(BLACK) ;
        Display.gfx_MoveTo(16 , 28) ;
        
        Display.txt_FontID(hFont3) ; // Font index
        Display.putstr("Verdana 36pt Bold\n") ;
        
        Display.txt_FontID(hFont2) ; // Font index
        Display.putstr("Verdana 20pt Bold\n") ;
        
        Display.txt_FontID(hFont1) ; // Font index
        Display.putstr("Verdana 16pt Bold\n") ;
        
        }
        
        void loop(){
        }
        For my own enlightenment...
        When would I use the following lines?
        Code:
        //hstrings = Display.file_Open("Fonts.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
        hndl = Display.file_LoadImageControl("Fonts.dat", "Fonts.gci", 1);
        The file Fonts.txf does exist on the uSD card. It is 3kb in size, but if I open it in a text editor (EditPlus) it appears to be empty.
        The files Fonts.dat and Fonts.cgi do not exist on the uSD card, or in the ViSi project.

        Comment


        • #5
          I'm glad the snippet worked for you with minimal modifications.

          Code:
          //hstrings = Display.file_Open("Fonts.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
          hndl = Display.file_LoadImageControl("Fonts.dat", "Fonts.gci", 1);
          The first line can be used to access the text file which contains predefined text set for the Strings widget. This file wont contain anything if the initial text set is blank.
          The next line would be to access a graphics file built by Workshop4 for GCI widgets. The file will pnly be generated if required.

          Best Regards,
          Juniel Cruz

          Comment

          Working...
          X