Not an error per say, but in my project’s Blynk LCD display, there is what appears to be a question mark inside a black diamond. I’ve noticed that this character is not always there. Does anybody have a clue what it is and why it might be there?
That diamond + ? is usualy a replacement for an invalid character.
How is your LCD setup? What are you writing to it
Test something, first save your sketch at Arduino IDE and resent to ESP.
Does this solve the problem?
And please let me / us know…
Here’s the first half of the funtion. The remainder is a bunch of if tests.
void timeRoutine()
{
DateTime now = RTC.now(); // reads time at beginning of loop
byte twelveHour = now.hour() - 12; // Variable used to display 13+ hours in 12 hour format
byte zeroHour = 12; // Variable use to convert "0" zero hour to display it as 12:00+
byte displayHour;
byte MIN = now.minute();
byte SEC = now.second();
char* meridian;
if (now.hour() == 0) // First we test if the hour reads "0"
{
displayHour = zeroHour;
meridian = "AM";
}
else if (now.hour() >= 13) // if no, Second we test if the hour reads "13 or more"
{
displayHour = twelveHour;
meridian = "PM";
}
else
{
displayHour = now.hour();
meridian = "AM";
}
char timeStamp[11];
char dateStamp[11];
sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
sprintf(dateStamp, "%02d/%02d/%04d", now.month(), now.day(), now.year());
String ts;
String ds;
ts = timeStamp;
ds = dateStamp;
lcdA.clear(); //Advanced Mode
lcdA.print(3, 0, ts); //Advanced Mode
lcdA.print(3, 1, ds); //Advanced Mode
Serial.println(ts);
Serial.print(ds);
@myggle from your code it should be the meridian that is giving you the invalid character (?) but as you have now.hour() covered at 0, >=13 and in between (with “AM” or “PM”) I can’t see why you would get the invalid character.
Maybe you have some code elsewhere that is writing to the lcd after the meridian.
Do you ever see the invalid character in the Serial Monitor? Do remember though Serial Monitor isn’t identical to the LCD.
Regrettably, the hardware is at another location so I am unable to connect my PC to it. Also, there is no other code that utilizes the LCD, I just wanted it for the time and date stamps from my RTC.
@myggle I use a slightly different time system but I have incorporated your code into one of my projects but I’m not seeing the invalid character. I am only displaying the top line of the LCD i.e. timeStamp and not dateStamp.
When you say the invalid character is not always there how frequently does it appear?
Every few minutes, hours, days, certain times of the day etc?
Once the invalid character appears how long does it stay for, seconds, minutes etc?
Are you 100% sure you don’t have any LCD code elsewhere in your sketch?
I will keep it running here and let you know if ? appears, but I’m not expecting it to.
I am very certain there is no other LCD code as I wrote the sketch and all of the functions. Regarding when the character appears, I will need to wait a few hours to verify, but I’m guessing that it only occurs during AM I think. Because all of the desired data is displayed, I don’t really view this as a problem, but wanted to ask about that added character.
My hardware is a DS3231 Chronodot RTC on a Freetronics Ethermega.
My C++ understanding is limited, and I am not sure I quite understand the reasoning for making a variable a pointer with the * but as it is related to the last characters printed before the �, have you tried just char meridian;
If memory serves me right, I think when I was trying to write this function with Blynk last year, I likely tried to use char w/o the pointer, but I can’t be sure. I will order another rtc tonight as I wanted another anyways, and recreate my project with my other Arduino. If anyone has similar hardware and can test my function w/o the pointer on char, I’d love to know the results.
I think giving 11 bytes for those strings is not enough. Give them 16 - don’t be so greedy
Did it help?
I won’t be able to test it for a few days.
Edit - do u think the displayed text will remain centered?
That one I can answer definitively… Yes, if you space out your string content correctly.
You precisely place your starting characters and line placement, based on the preceding numbers in your LCD.print command.
lcdA.print(3, 0, ts); // Start printing from the 4th character position (3) on 1st line (0)
lcdA.print(3, 1, ds); // Start printing from the 4th character position (3) on 2nd line (1)
Assigning extra string buffer will not affect character count (unless you don’t provide enough, then I think you truncate the string).
You might want to read this thread on StackOverflow from someone who was having junk characters appended to the end of his output when using sprintf:
Pete.
Well… at least there is no more � Switch to military time and all is good!
Military time… Love it lol.
You mean rest of the world time
As it turns out, adding the extra bytes to buffer fixed the minor issue. I spent a few days trying to find another way for medidian to equal AM or PM, but never succeeded. The screenshot is mostly for amusement, but clearly the Blynk app did not like what I tried there, but once I reverted the code back to char* meridian, and gave the string buffers [16], the question mark character disappeared and displays time perfectly.
byte twelveHour = now.hour() - 12; // Variable used to display 13+ hours in 12 hour format
byte zeroHour = 12; // Variable use to convert "0" zero hour to display it as 12:00+
byte displayHour;
byte MIN = now.minute();
byte SEC = now.second();
char* meridian;
if (now.hour() == 0) // First we test if the hour reads "0"
{
displayHour = zeroHour;
meridian = "AM";
}
else if (now.hour() >= 13) // if no, Second we test if the hour reads "13 or more"
{
displayHour = twelveHour;
meridian = "PM";
}
else
{
displayHour = now.hour();
meridian = "AM";
}
char timeStamp[16];
char dateStamp[16];
sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
sprintf(dateStamp, "%02d/%02d/%04d", now.month(), now.day(), now.year());
String ts;
String ds;
ts = timeStamp;
ds = dateStamp;
lcdA.clear(); //Advanced Mode
lcdA.print(3, 0, ts); //Advanced Mode
lcdA.print(3, 1, ds); //Advanced Mode
The amusing picture;