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.
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.
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)
/* ============================================
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);
}
}
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 I need the pi symbol and ohms symbol, it’s really annoying trying to figure out how to find the number i need
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.
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.
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?
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 [
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.
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
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.