C° - How to get a degree sign on a text LCD screen?

I read this through:

http://forum.arduino.cc/index.php?topic=19002.0

and this: http://www.theasciicode.com.ar/extended-ascii-code/degree-symbol-ascii-code-248.html

and several more articles.

I don't know what it takes to type into the lcd.print( ); command to get it to print C°

lcd.print((char)223); THis line of code creates compiler syntax errors. It makes no sense to me either.

So as a quick answer without going in depth, how do I get Arduino to print me a nice circle above my C?

Thank you.

Have a look in the lcd library. You can create up to 8 custom characters. Each character segment consists of a 5 x 8 pixel square ( you can see them on your lcd screen)

There is example code there too.

Here’s one such example.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
//            lcd(RS,  E, d4, d5, d6, d7)
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// Creat a set of new characters

uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = {	0x1,0x1,0x5,0x9,0x1f,0x8,0x4};


byte smiley[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};

byte armsUp[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b10101,
  0b01110,
  0b00100,
  0b00100,
  0b01010
};

byte frownie[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b00000,
  0b01110,
  0b10001
};

void setup()
{

  lcd.begin(16,2);               // initialize the lcd 

  lcd.createChar (0, smiley);    // load character to the LCD
  lcd.createChar (1, armsUp);    // load character to the LCD
  lcd.createChar (2, frownie);   // load character to the LCD

  lcd.home ();                   // go home
  lcd.print("Hello, ARDUINO ");  
}

void loop()
{
  // Do a little animation by writing to the same location
  lcd.setCursor ( 14, 1 );
  lcd.print (char(2));
  delay (200);
  lcd.setCursor ( 14, 1 );
  lcd.print ( char(0));
  delay (200);
}

You should not get any Syntax errors.

  lcd.print((char)223);   //cast it to a char
  lcd.print((char)0xDF);  //cast it to a char
  lcd.print("\xDF");      //place single character in a string
  lcd.print(" \xDF" "C"); //embed it in a string

If you get any errors, please copy-paste the error line and post it here. Say which IDE version. Say which LiquidCrystal library.

David.

Have a look in the lcd library. You can create up to 8 custom characters.

Why use a custom character when the desired character already exists in the LCD controller ROM?

If you look at Table 4 of the HD44780 datasheet you will find the ° symbol in the bottom row near the right. At the top of the column are the top four binary values for the (extended) ASCII code 1101 and at the left end of the row are the lower four binary values of 1111.

Therefore the binary value of the extended ASCII code for the ° character is '11011111'. This easily converts to the hex value of 'DF' which is what David used in his example. I suppose it also converts to the decimal value of 223 but I can't comprehend why anyone would even try to do that.

Don

As far as I understand "\223" should be understood as char(223) by the C++ compiler. The compiler is quite happy with "\xDF" to specify char(223) And is probably fine with "\0367" which would be the Octal version of char(223)

However, when I tried "\223" the Compiler did not produce the degree symbol. Likewise, the compiler did not like "\xdfC" to produce a degree symbol followed by the letter C.

Hey-ho. It is simple enough to just cast the integer 223 as a char.

David.

Which compiler version gives this error? I used the v1.6.6 IDE on a Mega2560 target.

Surely the regular C cast syntax is perfectly legal in C++. At the same time, the char() operator works too in C++.

David.

david_prentice: Surely the regular C cast syntax is perfectly legal in C++.

Well it definitely is when printing to the serial monitor. In that case, this works fine for a degree symbol:-

Serial.print((char)0xB0);

Thank you. That was easy. lcd.print("C"); lcd.print(char(223)); worked.

Btw - is there a more efficient way to piggyback strings in a single lcd.print expression? & && , + didn't work.

VT91: Btw - is there a more efficient way to piggyback strings in a single lcd.print expression? & && , + didn't work.

Streaming

code and video showing measuring temp with a thermistor and sending the data to a 20 x 4 (with a cute degree symbol).

https://www.youtube.com/watch?v=5SWHgrh9P6c

Hope this helps.

Kris

I tried lcd.print((char)223); before and after lcd.print("C"); and they both worked

I tried lcd.print((char)0xB0); before the lcd.print("C"); and got -C

I tried lcd.print(char(223)); after the lcd.print("C"); and that also worked

DAVIDLIPTROTT: I tried lcd.print((char)0xB0); before the lcd.print("C"); and got -C

0xB0 wasn't expected to work with an LCD. I didn't have an LCD hooked up, so used the serial monitor. I was only affirming david_prentice's statement that this format worked in C++:-(char)0xB0 // regular C cast syntaxas well as this format:-char(0xB0) // char operator He said:-

Surely the regular C cast syntax is perfectly legal in C++. At the same time, the char() operator works too in C++.

The actual value was irrelevant. 0xB0 for the serial monitor, 0xDF for an LCD. Sorry if you thought I meant to use 0xB0 for the LCD. It wasn't my intent.

Someone had posted that their IDE/Compiler version only accepted char(0xDF) and not (char)0xDF.

I thought this odd, and queried it in message #5.

Meanwhile it looks as if the message that prompted my reply has disappeared !

David.

david_prentice:
Meanwhile it looks as if the message that prompted my reply has disappeared !

You can’t trust anything these days!

Checked em out lads your both right Oldsteve lcd.print((char)0xDF); that works david_prentice led.print(char(0xDF)); that works Karma to both of you

And on the lcd display that I have currently hooked up, the degree symbol is 0xF7. 0xDF gives me some strange character.

On the subject of piggybacking strings, you can always use sprintf(). eg:

char buf[80]; sprintf(buf,"The temperature is: %d %c",temperature, 0xDF); lcd.print(buf);

Strangely enough, on 1.6.7 the sprintf() function won't do floats. %f only gives a question mark. I haven't tried any other version.

michvhf: Strangely enough, on 1.6.7 the sprintf() function won't do floats. %f only gives a question mark. I haven't tried any other version.

Don't bother trying it with other versions - floats aren't automatically supported by Arduino for 'sprintf()', 'sprintf_P()' and other related functions. The best way around this is to use 'dtostrf()' -> dtostrf()

void setup()
{
    Serial.begin(115200);
    float pi = 3.14;
    char buffer[50];
    char piTemp[5];
    dtostrf(pi,5,2,piTemp);
    char firstString[] = "This is";
    sprintf_P(buffer,PSTR("%s 'pi': %s"),firstString,piTemp);
    Serial.println(buffer);
}

void loop(){}

Thanks! I wasn't aware of that one.

More intrigue! I tried 0xF7 and got a wierd symbol. I have looked at what other people have used and most don’t bother with the degree symbol. I have come to the conclution that the most professional looking symbol is a small octagonal in the right hand top corner (looks good) but this is a custom character. I have tried to include it in my code but I just keep getting a 0 so will have to be content with 223. I’m not sure why it won’t work for me but suspect that it is because I am using the I2C modual and the LCD chip needs to be programed before this is added. Anyhow its all interesting stuff

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte degees[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
};

void setup() {
lcd.createChar(0, degrees);
lcd.begin(16, 2);
lcd.write(byte(0));
}

void loop() {}

The way I found it is writing each ascii code to the screen.

for(ii=128;ii<255;ii++) {
sprintf(buf,"%d %c ",ii,char(ii));
lcd.print(buf);
}

Now it would only show about 20 or so at a time, so I looked at each one then redid the start of the loop with the next number of what was displayed last. 0xF7 was the degree sign on this display. No idea what it is on others I have here so it’s not the most portable way to do it.