Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - koc

Pages: 1
1
General Discussion / Can I use display.print for unicode characters?
« on: September 28, 2017, 01:58:54 PM »
I'm new to Arduino. Since I want to print some unicode characters on the screen I read some tutorials and source code. If I understood correctly, I should add some bitmap font into the font.h file.

In the font.h file, it said:
Quote
Generated by The Dot Factory, written by Eran Duchan, currently available at
http://www.eran.io/the-dot-factory-an-lcd-font-and-image-generator/
using the configuration xml included with this library. Just put the
configuration file in the same directory as the executable, and copy and paste
the output to the end of this file. Fonts that are not used are not included by
the compiler and do not take up any space on the microcontroller flash.

Therefore I downloaded  The Dot Factory. I generated some codes for one non-ascii characters, pasted it to the end of font.h but it won't show up. If I change nothing, but just the non-ascii character to the ascii character, it will work.

The non-ascii version of code is
Code: [Select]
/*
**  Font data for Arial 8pt
*/

/* Character bitmaps for Arial 8pt */
static const unsigned char PROGMEM arial_8ptBitmaps[] =
{
/* @0 '啊' (11 pixels wide) */
//   #########
//    #      #
//   #########
//           
// ###########
//   #   ##  #
//    ###  ###
//     ##### 
// #   #   # #
// ###########
//           #
0x08, 0x08, 0xAC, 0xEA, 0xAB, 0xAB, 0xAD, 0xAD, 0xAB, 0xAA, 0xEE,
0xC0, 0x40, 0x40, 0x40, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0x40, 0xE0,
};

/* Character descriptors for Arial 8pt */
/* { [Char width in bits], [Offset into arial_8ptCharBitmaps in bytes] } */
static const FONT_CHAR_INFO PROGMEM arial_8ptDescriptors[] =
{
{11, 0}, /* 啊 */
};

/* Font information for Arial 8pt */
static const FONT_INFO arial_8ptFontInfo =
{
11, /*  Character height */
21834, /*  Start character */
21834, /*  End character */
arial_8ptDescriptors, /*  Character descriptor array */
arial_8ptBitmaps, /*  Character bitmap array */
};


The ascii version of it is
Code: [Select]
/*
**  Font data for Arial 8pt
*/

/* Character bitmaps for Arial 8pt */
static const unsigned char PROGMEM arial_8ptBitmaps[] =
{
/* @0 'a' (5 pixels wide) */
//  ## #
// #  # #
// #  # #
//  # # #
// #####
0x68, 0x98, 0x88, 0x78, 0x88, 0x70,
};

/* Character descriptors for Arial 8pt */
/* { [Char width in bits], [Offset into arial_8ptCharBitmaps in bytes] } */
static const FONT_CHAR_INFO PROGMEM arial_8ptDescriptors[] =
{
{5, 0}, /* a */
};

/* Font information for Arial 8pt */
static const FONT_INFO arial_8ptFontInfo =
{
6, /*  Character height */
'a', /*  Start character */
'a', /*  End character */
arial_8ptDescriptors, /*  Character descriptor array */
arial_8ptBitmaps, /*  Character bitmap array */
};


The main process's code is
Code: [Select]
#include <Wire.h>
#include <SPI.h>
#include <TinyScreen.h>

TinyScreen display = TinyScreen(TinyScreenPlus);
void setup(void) {
  Wire.begin();//initialize I2C before we can initialize TinyScreen- not needed for TinyScreen+
  display.begin();
  display.setBrightness(10);
}

void loop() {
  display.clearScreen();
  display.setFont(arial_8ptFontInfo);
  display.setCursor(20,20);
  display.print("a"); // or display.print("啊")
}

Pages: 1
SMF spam blocked by CleanTalk