13

I have a 16x2 LCD and I want to show a temperature: 23 ºC.

But the º symbol is not properly shown. It shows a strange character instead of the º symbol .

4 Answers 4

17

It depends on the exact model of LCD you are using. Or more exactly, on the Dot Matrix Liquid Crystal Display Controller/Driver, like the Hitachi HD44780U that is used in many 16x2 LCD.

For that driver, you have a table of native chars, like this:

LCD Character Set - source: mil.ufl.edu

In this table, the char "°" is at col 0b1101, row 1111, (0xDF, or 223). But, you have to cast that value to a char before displaying, otherwise you will get the value (223), not the symbol.

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd 
  lcd.backlight();
  lcd.print("temp 27");
  lcd.print((char) 223);
  lcd.print(" ");
  lcd.print(223);

}

void loop()
{
}
4
  • 4
    lcd.print() does indeed require a cast, but you could also lcd.write(0xdf). Unlike print(), which is mostly intended to format data as ASCII, the write() method is meant to send raw bytes. Commented Nov 20, 2017 at 18:32
  • How can I concatenate lcd.print("temp 27") and lcd.print((char) 223)? Something like this: lcd.print("temp 27" + (char) 223) Commented Nov 20, 2017 at 20:22
  • 2
    @Roby. Don't concatenate, just display/print every thing separately. That's the Arduino way.
    – user31481
    Commented Nov 20, 2017 at 20:41
  • 3
    You can also just do lcd.print("temp 27" "\xDF" "C") to show temp 27°C in one call.
    – gre_gor
    Commented Nov 21, 2017 at 1:12
5

Some displays have different characters above 128. It is best to make your own character.

That is what @dannyf ment with "CGRAM". The custom characters are stored in CGRAM. There is no need to read the datasheet though, because there is a function in the Arduino LiquidCrystal library for it.

Start here: Arduino CreateChar reference
There are even websites that help you to create the character: omerk and maxpromer.

0

Easy.

  1. Pull up the datasheet and pick the character that most resembles your symbol. Char 0b11011111 looks the best to me but 0b10110000 isn't bad.

  2. While you are in the datasheet, check out CGRAM.

0

do lcd.write(223); Transform the Decimal into an ASCII symbol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.