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

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.

Yes it does. And this really doesn't have to do with Arduino or the IDE.
However, the way the avr-gcc AVR libC was implemented, there are multiple versions of xxprintf() functions and by default the linker links in a version that does not support floating point formatting to save space.
You can change this by modifying the linker rules in the platform.txt file.
You just change the linker command options to tell it to link in the floating point version. See the avr libC documentation for the appropriate command options.
Just be aware that if you do this, you will add about 2k or so of code that will be pulled in regardless of whether you use floating point formatting or not whenever you use a xxprintf() function.

--- bill

It's getting a little too complicated for me bill.
My conclusion for any one who struggles to get a degree symbol is try the different character addresses
223 0xDF 0xF7 and the different styles of writing the code ((char)223); etc. It seems that different LCDs use different addresses But you will find the right one with help from this forum. I'll keep trying to get that cute little octagonal. Also if your short of space you can actually fit both the degree and a smaller c or f into one segment.
My Lcd is now showing 21/04/2016
16.50*C 05:12:50 I started off badly by using the wrong codes with the wrong libraries but managed to hack a code together which now has my RTC3231 and 16x2 LCD using the I2C to displaying Date, Temp & Time. The next step is to figure out how to switch some lights on and off at different times. I'll let my head cool down before starting on that one.

"It seems that different LCDs use different addresses But you will find the right one . . ." by starting with the datasheet for your controller and following the technique explained in post #3.

Don

Thanks Don, done it got the degree character I wanted it looks better than character 223. I created a custom character 0x6, 0x9, 0x9, 0x6, 0x0, 0x0, 0x0, with an address of 0

One thing is puzzling me how has michvhf got 0xF7 (247) to look anything like a degree sign? is it something I need to puzzle about?
Karma to you

It just depends on which particular built-in Font ROM you have in your LCD module.

Every 16x2 or 20x4 that I have ever bought has got the standard "Japanese" character set in 128-255 (ROM Code A00).
It seems unfortunate that there are so many empty locations.

If you look at the HD44780 data sheet, you can see the extended-Latin (ROM Code A02). I guess that Russians might get Cyrillic characters. Likewise Arabic, Greek, Chinese, ... OTOH, you probably have to pay through the nose for the less common ROMs.

The A02 ROM looks like 0xB0 would be a reasonable degree symbol. 0xDF looks like a "Beta".
Nowadays, you might just as will use custom Fonts with a small GLCD.

David.

I've used the LCD character displays and successfully displayed the degree character. I created a string variable that I then used wherever I needed it:

 //***special degree symbol
String degreeChar = String(char(223));// degree symbol needed for display
      }

Additionally, if you want to see what shows up on your display as a function of the ascii character, try this code snippet:

     for(int i = 0;i < 256; ++i){
        Serial.print(i);
        Serial.print(" : ");
        Serial.println(char(i)); // so you can see the special character in your serial display
        lcd.setCursor(0,0);
        lcd.print(i);
        lcd.setCursor(5,0);
        lcd.print(char(i)); // this will print the special character to the lcd
        delay(250); // so you have time to look at the display
        lcd.clear(); 
      }

This will also give you an idea of the difference between what you see on the serial monitor and on the character LCD. Also, as was said previously there are a number of symbols built into the ROM of these displays, as well as being able to create your own custom symbol.

Have searched the Degree Symbol for M5Stack and have nothing found. So I have written this code and found that it is char(247). Perhaps it is useful for somebody.

#include <M5Stack.h>
void setup() {
 // put your setup code here, to run once:
 // initialize the M5Stack object
   M5.begin();
}
void loop() {
   M5.Lcd.setCursor(10, 10) ;
   M5.Lcd.setTextColor(WHITE);
   M5.Lcd.setTextSize(8);

     for( int i=0; i<256; i++) {
        M5.Lcd.setCursor(30, 10);
        M5.Lcd.setTextColor(WHITE);
        M5.Lcd.print(i);  M5.Lcd.print(""); M5.Lcd.println(char(i));             
        delay(1000);
        M5.Lcd.setCursor(30, 10);
        M5.Lcd.setTextColor(BLACK);
        M5.Lcd.print(i);  M5.Lcd.print(""); M5.Lcd.println(char(i));
   }
}

If you wish to have it as single char to save space on your tiny LCD you try this (degree goes before 'C'):

byte celsius[8] = {
  0b01000,
  0b10100,
  0b01000,
  0b00111,
  0b01000,
  0b01000,
  0b01000,
  0b00111
};

You will get:

 *
* *
 *
  ***
 *
 *
 *
  ***

and print this like in the example by MaverickAlex:

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.

#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);
}