My problem is getting my custom character to work with serial input messages. I can easily make the display show my custom character when i tell it lcd.write(0);
But how will i make it write my character by sending some text to it?
If i write 0 in the serial, it will still just display a 0 on the display.
I want to for example be able to write heart, or just type 0 and have it displaying my icon (which obviously is a heart).
Here is my code
#include <LiquidCrystal.h>
int potPin = 0;
float temperature = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte heart[8] = {
B00000,
B01010,
B11111,
B11111,
B01110,
B00100,
B00000,
};
void setup(){
lcd.createChar(0, heart);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
lcd.setCursor(0, 0); // top left
lcd.clear();
// wait a bit for the entire message to arrive
delay(100);
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());}}
else
{
lcd.setCursor(0, 1); // top left
int span = 20;
int aRead = 0;
for (int i = 0; i < span; i++) {
aRead = aRead+analogRead(potPin);
}
aRead = aRead / 20;
temperature = ((100*1.1*aRead)/1024)*5;
delay(500);
lcd.print("Temp:");
lcd.print(temperature);
lcd.print("c");
}
}
(please ignore the random remains of comments, and the temperature part (unless the temperature part could possibly have an impact on my problem))
I want to for example be able to write heart, or just type 0 and have it displaying my icon (which obviously is a heart).
When you type a character on the keyboard the ASCII code corresponding to that character is sent to the LCD. So when you type the number '0' its ASCII code, which is 0x30 is sent to the LCD. What you really want to send is ASCII code 0x00 which you may be able to generate by typing [CTRL]@ or [CTRL]`.
You may also have more luck by putting your character at CGRAM location 0x01 (lcd.createChar(1, heart);) and then using [CTRL]A or [CTRL]a.
I had already thought of this, but didn't know how to send the right message. Also i can't seem to create the required symbol or thing by holding ctrl. I have an European (danish to be exact) keyboard. Also it's a laptop. Any other way to do it?
Edit:
I see what you mean, i tried with pyserial instead, and managed to make it work. Thanks! But still I'd like to know if there's an alternative way to do it.
Pretty much. I had to do some fiddling around to figure out how the switch command worked, but got it working. Except it's so slow, that i can see the characters being written. I guess i can figure out how to fix that myself. Thanks to you two!
Also i can't seem to create the required symbol or thing by holding ctrl. I have an European (danish to be exact) keyboard.
That is why I suggested using [CTRL]A etc. I had trouble finding the others on a US keyboard. The @ is an uppercase 2 and the ` is a lower case tilde (~) just below our [ESC] key.
Any other way to do it?
Yes. On a full size keyboard you can generate any ASCII character by pressing and holding the [ALT] key while entering the three digit decimal version of the ASCII code on the numeric keypad. The character appears when you release the [ALT] key. This won't work using the regular horizontal row of number keys.
I just tried it on a laptop and it seems to work using the embedded keypad along with the [ALT] and [FUNCTION] keys.
Pretty much. I had to do some fiddling around to figure out how the switch command worked, but got it working. Except it's so slow, that i can see the characters being written. I guess i can figure out how to fix that myself. Thanks to you two!
Well you should be able to do it with a lookup table which is probably faster but I can't really help you on that as I have never coded one