Hello.
I am new with electronics (as you may find out for yourself after reading this). However, my problem is whenever I tell my LCD panel to change its message, it instead displays weird characters (like below).
When I first start up the arduino uno, It will display a clear message but any message given to this first message is displayed as weird characters. I have also noticed it fails to clear the screen properly if told to do so. Im 99% certain its my coding as when I run the example "hello world" sketch it runs fine.
Please excuse my messy/poor coding, I am only learning
Perhaps someone could guide me to what I have done wrong? I have spent alot of time changing and tweaking the code having little or no effect.
Thanks a mill!
Before command sent to change message:
After command sent to change message:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//int ledOnline = 13;
const int ledTbl = 7;
const int ledAck = 6;
const int ledFire = 13;
int buttonAck = 0;
int buttonDrill = 0;
int buttonReset = 0;
int fireZoneone = 0;
int troubleOn = 0;
int sysReset = 0;
int inPin = 10; // choose the input pin (for a pushbutton)
int pinSpeaker = 9;
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
int val = 0; // variable for reading the pin status
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup() {
Serial.begin(9600);
//pinMode(ledOnline, OUTPUT);
pinMode(ledTbl, OUTPUT);
pinMode(ledAck, OUTPUT);
pinMode(ledFire, OUTPUT);
pinMode(pinSpeaker, OUTPUT);
pinMode(inPin, INPUT); // declare pushbutton as input
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("SYS CALIBRATING");
lcd.setCursor(0, 1);
lcd.print("Please Wait...");
delay(1000);
lcd.clear();
}
void loop() {
int sensorValue = analogRead(A0);
int sensorDetect = analogRead(A1);
if(sensorValue >= 310 && sensorValue <= 350){
buttonAck = HIGH;
buttonDrill = LOW;
buttonReset = LOW;
}
if(sensorValue >= 900 && sensorValue <= 930){
buttonAck = LOW;
buttonDrill = HIGH;
buttonReset = LOW;
}
if(sensorValue >= 2 && sensorValue <= 6){
buttonAck = LOW;
buttonDrill = LOW;
buttonReset = HIGH;
}
if(sensorValue == 0){
buttonAck = LOW;
buttonDrill = LOW;
buttonReset = LOW;
}
if(sensorDetect >= 1 && sensorDetect <= 50){
}
if(sensorDetect == 0){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sys Status: TBL");
lcd.setCursor(0, 1);
lcd.print(" ZONE 1 TROUBLE");
digitalWrite(ledTbl, HIGH);
resetTone(400, 1500);
delay(5000);
}
Serial.print("Val: ");
Serial.print(sensorValue);
Serial.println();
Serial.print("Ack: ");
Serial.print(buttonAck);
Serial.println();
Serial.print("Drill: ");
Serial.print(buttonDrill);
Serial.println();
Serial.print("Reset: ");
Serial.print(buttonReset);
Serial.println();
reading = buttonAck;
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
Serial.println();
Serial.print("Reading: ");
Serial.print(reading);
Serial.println();
Serial.print("previous: ");
Serial.print(previous);
Serial.println();
Serial.print("State: ");
Serial.print(state);
Serial.println();
digitalWrite(ledAck, state);
previous = reading;
// if (buttonAck == HIGH) { // check if the input is HIGH (button released)
// digitalWrite(ledAck, HIGH); // turn LED OFF
// }
// else {
// digitalWrite(ledAck, LOW); // turn LED ON
// }
if (buttonReset == HIGH) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SYSTEM RESETTING");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(" PLEASE WAIT. ");
sysReset = 1;
state = LOW;
// check if the input is HIGH (button released)
digitalWrite(ledTbl, HIGH); // turn LED OFF
digitalWrite(ledAck, HIGH); // turn LED OFF
digitalWrite(ledFire, HIGH); // turn LED OFF
resetTone(750, 1400);
delay(500);
digitalWrite(ledTbl, LOW); // turn LED OFF
digitalWrite(ledAck, LOW); // turn LED OFF
digitalWrite(ledFire, LOW); // turn LED OFF
sysReset = 0;
fireZoneone = 0;
troubleOn == 0;
lcd.clear();
}
if(fireZoneone == 0 && troubleOn == 0 && sysReset == 0){
lcd.setCursor(0, 0);
lcd.print(" Sys Status: OK");
lcd.setCursor(0, 1);
lcd.print(" Online");
lcd.noCursor();
}
}
void resetTone(long duration, int freq) {
duration *= 3000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
while (elapsed_time < duration) {
digitalWrite(pinSpeaker,HIGH);
delayMicroseconds(period / 2);
digitalWrite(pinSpeaker, LOW);
delayMicroseconds(period / 2);
elapsed_time += (period);
}
}