A quick question to more experienced users about displays and characters.
So I did a bit of research about how to clear unwanted characters from displays using the lcd.print (" ") command and also how to put <, >, or = values in as a threshold, and even a timer to do a display clear.
My code is a sensor measurement where my floats calculations are any where from 1-100 (with two decimal points). I'm trying to avoid the flickering display with my code looping, but as the value increases and then decreases, there is that persistent character or two that remain as the value decreases. For now, I put a five second time in that clears specific characters, but I'm not happy.
Two questions;
-
do all types of displays hold the character until it is overwritten? Or do some displays function differently with better libraries? Right now, I'm using the 16x2 that came with my beginners kit.
-
since my sensor values go up and down and I want to use an if statement for threshold character removal, should I build all of them in at same point in code. Meaning if the value is less than XXX, print character x, x (" ") and then another if for less than XX and so on? I just want to put them in the correct spot in my code.
Thank you
I quite didn't get your problem.
You started saying your lcd flickers (meaning there are rapid and continuous changes in brightness and contrast... possibly being nothing but a simple problem of refreshing or clearing) but then it looks like your characters are printed over the old ones, showing some parts of the old character (possibly being a simple problem of overprinting).
Please post a simple version of your code (and also a pic of your lcd), so we can understand.
...
there is that persistent character or two that remain as the value decreases
Do you use formatted print? Like:
"1234"
" 11"
You have to overwrite unwanted relict with spaces.
- Yes, it should do it this way.
- Formatted output is easy solution like with sprintf to some buffer then to LCD.
Thank you for the replies.
When I wrote flickering, it is not due to backlight or hardware issues. I should have stated display characters are blinking based on the loop repeating itself and delay times.
Here is a section of my code which displays the results from the float calculation:
if (ACbutton == 0) {
if (sensorVal2 > 110) { // if sensorVal2 is greater than 110 from A/D converter then display the following
float watts = ((sq((sensorVal / 1024.0) * 5.0)) / 8); //ADC conversion, sq of volts and divide by 8(ohms). 20.0 is just a value to make test #s large enough
lcd.setCursor(0, 0); // set cursor to top display line, character 0
lcd.print("Watts @ 8 Ohms "); // print text 'Watts @ 8 Ohms'
lcd.setCursor(0, 1); // move the cursor to the second line, character 1
lcd.print(watts); // print calculated value from [float] watts
The code works and displays properly, but as the numeric value from the float increases and then decreases, the numbers remain from the larger 3 digit value (100.xx) or 2 digit value (10.xx).
I have read about the sprintf, but have quite grasped the buffer assignment concept. Some more reading is ahead for me. Do I need a separate buffer for each float [my code has 3 floats calculating at the same time]?
I read this website article about sprintf: sprintf | Liudr's Blog
Any other suggestions for reading?
Thanks.
Any other suggestions for reading?
Check this out: A very persistant zero on my LCD display - Displays - Arduino Forum
Note that it includes a link to the website article that you mentioned, posted by the author of that article.
Don
Do sprintf and dtostrf require libraries?
I don't have my board with me at the moment, so I will have to wait a few days to experiment with code. I'm trying to research now so I can start coding when I return home.
Thanks
Follow up: The dtostrf function helped immensely with my LCD display number characters. Using the dtostrf allows the number to increase properly and then decrease without leaving 'stuck characters' until the display is cleared or overwritten.
Hopefully this helps others:
float watts = ((sq((sensor / 1024.0) * 5.0)) / x);
char power[10]; // defines the character called 'power' and the buffer size
dtostrf(watts, 6, 2, power); // decimal to string conversion of the float function called 'watts'
// (watts is function, 6 is size of characters[three before the decimal, decimal and two after the decimal], 2 is places after decimal point, power is the name for the string)
lcd.setCursor(1, 1); // move the cursor to the second line, character 1
lcd.print(power); // print dtostrf value named 'power'