Issue:
The LCD will show corruption only when the LCD is used while Serial1 is receiving/transmitting data and a timer is used to update the display. If the timer is disabled in setup() ( timerTick.start() ) and the seconds based check in main() is enabled - there is no corruption.
Serial data is from another module sending a char string of 40 chrs every 2 seconds.
Hardware:
- Xenon
- Ethernet Featherwing
- LCD 16x2 I2C addr 0x20
Code:
Using WEB IDE
Library LiquidCrystal_I2C_Spark.h v1.1.0 (selected from library list)
#include "LiquidCrystal_I2C_Spark.h"
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t clockFace[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};
// LiquidCrystal_I2C lcd;
LiquidCrystal_I2C lcd(0x20, 16, 2);
int lastSecond = 0;
const int timerTickPeriod = 1000;
Timer timerTick( timerTickPeriod , displayTime);
void displayChrCodes(void) {
uint8_t i = 0;
lcd.setCursor(0,1);
lcd.write(i);
// for (int j = 0; j < 16; j++) {
// lcd.write(i + j);
// }
}
void displayTime(void)
{
Serial.println(Time.timeStr());
lcd.home();
lcd.print("LCD test");
lcd.setCursor(8,0);
lcd.print(Time.hour() < 10 ? " " : "");
lcd.print(Time.hour());
lcd.print( Time.second() % 2 ? ":" : " ");
lcd.print(Time.minute() < 10 ? "0": "");
lcd.print(Time.minute());
lcd.print( Time.second() % 2 ? " " : ":");
lcd.print(Time.second() < 10 ? "0": "");
lcd.print(Time.second());
}
void setup(void)
{
Serial.begin(115200);
Serial1.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.createChar(0, bell);
lcd.createChar(1, note);
lcd.createChar(2, clockFace);
lcd.createChar(3, heart);
lcd.createChar(4, duck);
lcd.createChar(5, check);
lcd.createChar(6, cross);
lcd.createChar(7, retarrow);
timerTick.start();
}
void loop(void)
{
// if (Time.second() != lastSecond)
// {
// displayTime();
// }
if (Serial1.available()) {
char inChar = Serial1.read();
Serial.print(inChar);
Serial1.print(inChar);
displayChrCodes();
}
}