10

I would like to buy an LCD screen fom Arduino to display some results from a web http call; the Web API returns a JSON text encoded in UTF-8.

I've read that ICU is the way to go to handle Unicode in C/C++ programs for Arduino.

My questions:
Will I be able to display UTF-8 characters to this kind of screen?
Are there (affordable) character LCD screens able to display UTF-8 characters?

systempuntoout
  • 545
  • 3
  • 5
  • 12
  • 3
    Are we talkign about a graphical display or a segmented character display? On a segmented display, you can't obviously display anythign that does not fit the segment pattern. For "western" non-ascii uses, you can probably fall back to the base (non-accented etc.) character. For other scripts you are most likely out of luck. – drxzcl Apr 29 '11 at 10:26

2 Answers2

7

I'm not that much familiar with Arduino, but let's look at it from the LCD perspective.

Virtually all popular character LCDs use HD44780 controller these days (that's what LiquidCrystal library supports). This controller doesn't support UTF-8 directly, each character is represented by a single byte.

Thus you need to convert UTF-8 to 8-bit characters manually. The controller has a built-in character generator with 208 5x8 and 32 5x10 characters, plus up to 8 user-defined characters (see createChar). You need to map every input character to one of the predefined/custom characters - obviously you can only display a subset of UTF8 characters, you need to decide which characters you want/can to display.

The conversion itself should be pretty straightforward - you just need to iterate over the UTF8 string, mapping every character to a single byte. Most likely you'll want to use a lookup tables to keep it simple. Let me know if this needs further explanation.

Code Painters
  • 1,070
  • 9
  • 12
  • thank you; do you think this kind of [Tft graphical display](http://www.watterott.com/en/Arduino-S65-Shield) could offer a better unicode support? – systempuntoout Apr 29 '11 at 13:05
  • 1
    This is a graphics display, as far as I can see, so it can display pretty much anything you want. The library provided provides functions to paint text as well, but again it supports 8-bit characters only. So, with this display you either need to the same sort of conversion as described above and use the library as is, or you have to modify the library to support UTF8. Keep in mind, that using a graphics display will make your code bigger - you need extra library, font, etc. But at least you have full control of the available character set - the font is part of the software. – Code Painters Apr 29 '11 at 13:22
4

Unicode is complicated and big, in its entirety it is too big for an Arduino. In the current version there are in total over 100000 characters, including cuneiform, hieroglyphics, Klingon, and not to mention many thousands of chinese characters.

So if you really want to show some Unicode characters on an Arduino:

  • Get a graphic display. The one you mention is a character display, it can only show a mostly fixed set of 256 characters.

  • Define a small subset of characters you want to handle. There are some predefined subsets, for example the Multilingual European Subsets look nice.

  • Get some fonts and strip them down to the set you need. Note that even displaying can be much more complicated than what you are used to from ASCII, due to combining characters, bidirectional writing and such. Best is probably to stick to latin characters without any combining accents. Cyrillic and greek should be ok, too, as should anything that is a simple left-to-right sequence of characters.

  • Maybe you could use some external memory to store the fonts.

Then there's a whole lot of other topics you probably don't need, for example sorting and searching, see the Unicode standard and its annexes (it's big!).

Forget ICU, it needs megabytes of memory.

starblue
  • 6,462
  • 2
  • 21
  • 35