Printing Symbols to LCD screen

Hello

I am looking for some help with a college LAB we have to print 3 symbols onto the LCD screen using ascii numbers so for example i got that 91 is the number for the micro (u) symbol I'm not sure about the code to use it will only print 91 on the LCD screen not the u? I will post the code below to see if anyone can help. I would really appreciate it.

#include <LiquidCrystal.h>

// Initialize the LCD screen
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // Set up the LCD screen
  lcd.begin(16, 2);
}

void loop() {
  // Clear the LCD screen
  lcd.clear();

  // Print ASCII characters

 lcd.print(91);
  lcd.print("Farad,");
  delay(1000);
}
void printBinaryCharacter(char character) {
  String binaryString;


  }

The standard LCDs support 8 custom characters. You choose the bits to display, and it is easy to include the mu symbol. Some LCD character generators can be found on line to help with the design.

This guide explains everything: Character I2C LCD with Arduino Tutorial (8 Examples)

Scroll down to the custom character example.

1 Like

Have you looked at using user defined characters with the LCD ?

You cannot directly create say character 91 as mu but a little manipulation could overcome that

Which 3 ASCII character numbers do you need to print ?

ASCII 91 is the left bracket '['.
You can check the character set for your LCD to see if it contains the symbol you want, otherwise ypu will need to create a custom character.

HD44780s can have one of two different character sets; European or Asian.

LCDs_12_CharSet_01-584x339-1

Depending on your LCD, its code will be

  • 0b11100100 = 228dec or 0xE4HEX (left table)
  • 0b10110101= 181dec (right table)

So you can print the symbol 'µ' with lcd.print((char) 0b11100100); or with lcd.print((char) 0b10110101); if you want the binary notation or just lcd.print((char) 228); or with lcd.print((char) 181); if you want to use the decimal notation.

here is a small wokwi code with a rotary encoder that shows all the 255 codes on the lcd as your turn the knob. (µ is 228 for the wokwi simulation)

click to see the code
/* ============================================
  code is placed under the MIT license
  Copyright (c) 2024 J-M-L
  For the Arduino Forum : https://forum.arduino.cc/u/j-m-l

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
  ===============================================
*/

#include <Wire.h>
#include <hd44780.h>                        // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h>  // i2c expander i/o class header
#include <Encoder.h>                        // https://www.pjrc.com/teensy/td_libs_Encoder.html

const byte encoderCLKPin = 2;
const byte encoderDTPin = 3;
Encoder encoder(encoderDTPin, encoderCLKPin);
long encoderPosition = 0;

const uint8_t nbCols = 16;
const uint8_t nbRows = 2;
hd44780_I2Cexp lcd;

bool encoderChanged() {
  long newPosition = encoder.read() >> 2; // divide by 4 as the rotary sends 4 ticks per click
  if (newPosition != encoderPosition) {
    encoderPosition = newPosition;
    return true;
  }
  return false;
}

void encoder0() {
  encoder.write(encoder.read() & 0b11); // keep the sub ticks
  encoderPosition = 0;
}

void encoder255() {
  long newPos = (0xFFL << 2) | (encoder.read() & 0b11L); // // keep the sub ticks
  encoder.write(newPos);
  encoderPosition = 255;
}

void showCode(uint8_t number) {
  lcd.setCursor(8, 0);
  if (number < 10) lcd.write('0');
  lcd.print(number, HEX);
  lcd.setCursor(14, 0);
  lcd.write((char) number);
}

void setup() {
  Serial.begin(115200);

  int result = lcd.begin(nbCols, nbRows);
  if (result) {
    Serial.print("LCD initialization failed: ");
    Serial.println(result);
    hd44780::fatalError(result);
  }
  lcd.clear();
  lcd.print("byte: 0x00 -> ");
  showCode(encoderPosition);
}

void loop() {
  if (encoderChanged()) {
    if (encoderPosition > 255) encoder0();
    else if (encoderPosition < 0) encoder255();
    showCode(encoderPosition);
  }
}
1 Like

Hi @emmac91 ,

this link may be of assistance:

https://docs.wokwi.com/parts/wokwi-lcd1602

Scroll down to the ASCII character table.

For micro you will find char(228). With

  lcd.print(char(228));
  lcd.print("Farad,");

you usually will get this

image

If you want to check it easily just have a look at this sketch and modify it to your needs:

/*
  Forum: https://forum.arduino.cc/t/printing-symbols-to-lcd-screen/1235998
  Wokwi: https://wokwi.com/projects/392443755178679297

*/

#include <LiquidCrystal.h>

// Initialize the LCD screen
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // Set up the LCD screen
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print(cMicro());
  lcd.print("Farad,");
  delay(1000);
}

void loop() {
}

char cMicro(){
  return char(228);
}

See on Wokwi: https://wokwi.com/projects/392443755178679297

I am just using this char cMicro() function because it makes it easier to read the code ...

Or - even easier -

const char myMicro {228};
lcd.print(myMicro);
1 Like

Trop vite pour moi ... :wink:

Your topic has been moved. Please do not post in "Uncategorized"; see the sticly topics in Uncategorized - Arduino Forum.

I need 91 for mu, I’m not sure now as I’ve looked online again and another spread sheet had mu as 200 and something :unamused: I need the pi symbol and ohms symbol, it’s really annoying trying to figure out how to find the number i need

Regards
Emma

Thank you I will try this in the morning and let you know if it works and I’ll check out the link :slightly_smiling_face:

:slightly_smiling_face:Thank you

you must take in consideration two things:

  • the encoding of the character on your platform
  • the encoding of the character in the LCD ROM.

The encoding of your platform might be:
In ASCII the 91 belongs to [
In Windows-1252 and ISO-8859-1 the µ is 181
In CP437 the µ is 230

If you use characters in your Arduino Source code it is encoded as UTF-8.
In UTF-8 the µ is a TWO BYTE character encoded as 0xc2 0xB5 (194 181).
When you use the common LiquidCristal library and you do a "lcd.print("µ") you will get in fact two symbols on the LCD.

In the other there is the LCD ROM Character set - @J-M-L has already posted it.
When you take the very common HD44780 A00 character set, you will need to write following "numbers" to the LCD to get the special characters:

µ is 228 (0xE4) in the LCD Rom A00
pi is 247 (0xF7) in the LCD Rom A00
omega is 244 (0xF4) in the LCD Rom A00

test it on your own:

This means you have to map special characters to find the right character in the LCD Character ROM.

My LCD library supports printing of such UTF-8 characters
https://werner.rothschopf.net/202009_arduino_liquid_crystal_intro.htm
so if you just need an easy access to a lot of symbols on the LCD, you might give it a try.

Now back to your

please explain where do you get this 91 from?
As mentioned above, 91 is usually a [ so I wonder in which usecase you need to translate this into a µ. And further more - how you will receive the omega and the pi.

1 Like

Thank you so much this worked for me, But how did you get the numbers 228 for mu and 247 for Pi etc? I googled loads of different charts and even for windows and they all showed up different symbols when I put in the number beside them?

Thank you again
Regards
Emma

I worked out the 91 from the binary numbers I cant remember exactly how now but it was a chart i had found online and yes when I put it into the code it was [ :sweat_smile:

read all links we have provided you carefully.

You will find the LCD character table in the HD44780 datasheet, in the post from J-M-L and on my page
https://werner.rothschopf.net/202009_arduino_liquid_crystal_intro.htm

Numbers are given in binary and/or hex.
The mu is 0xE4 (E from the top, 4 from the column) --> 228
The pi is 0xF7 --> 247

@J-M-L has given the example in binary in his post. the 4 left bits come from the top row, the 4 right bits come from the column. Put them together and you get the same figure.

1 Like

look at the table I gave you previously
a905b5e384bc95d658e4d3aa9df6fc7e7c372b81

each character in the table is at an intersection and you see the bit pattern for the line or column at the top or left side.

For 'µ' on the left you see xxxx0100et on the top you see 1110 (I added the Colors to make it clearer). So you replace the xxxx by 1110 and you get the value of that byte 0b11100100 and this is the base 2 notation (binary). If you convert that to decimal you get 228

same would go for PI. I let you do the maths

a905b5e384bc95d658e4d3aa9df6fc7e7c372b81

1 Like

Yes thank you I get it now, I was doing something different that id seen online going from right to left like by 2, 4, 8, 16 etc. wasn't adding up I should have used the 2^0 and so on that what we were taught to do. :slightly_smiling_face:

the joy of base 2 :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.