Go Down

Topic: C° - How to get a degree sign on a text LCD screen? (Read 12184 times) previous topic - next topic

VT91

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°

Code: [Select]
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.

MaverickAlex

#1
Apr 10, 2016, 05:26 am Last Edit: Apr 10, 2016, 05:32 am by MaverickAlex
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.

Code: [Select]
#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);
}

david_prentice

You should not get any Syntax errors.
Code: [Select]

  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.

floresta

Quote
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


david_prentice

#4
Apr 10, 2016, 03:43 pm Last Edit: Apr 10, 2016, 03:44 pm by david_prentice
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.

david_prentice

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.

OldSteve

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:-
Code: [Select]
Serial.print((char)0xB0);
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

VT91

Thank you. That was easy.
Code: [Select]
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.

DaveEvans

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

KrisKasprzak

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
Thanks,

Kris

DAVIDLIPTROTT

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

OldSteve

#11
Apr 20, 2016, 03:21 pm Last Edit: Apr 20, 2016, 03:22 pm by OldSteve
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++:-
Code: [Select]
(char)0xB0 // regular C cast syntaxas well as this format:-
Code: [Select]
char(0xB0) // char operator
He said:-
Quote
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.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

david_prentice

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.

Paul__B

Meanwhile it looks as if the message that prompted my reply has disappeared !
You can't trust anything these days!

DAVIDLIPTROTT

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

Go Up