I have connected an 16x2 LCD to my Arduino. It shows my Room Temperature and Behind that variable is the string "Celcius". Everytime the temp is diffrent than shown on the screen it updates the screen by clearing the screen. Is there a way I could clear just a part of the screen? or is this technically impossible. Or is it a waste of code? :D

Thanks in Advance!



The easiest is to clear the entire screen (I'm sure there is a function for that).

What you also can do:

  • Create lines which are 16 characters wide and print them, so the old text is overwritten
  • More complicated: store the text that is written in two strings (one per line) and check where are not spaces, to overwrite it with spaces to clear.

You would have to do a performance/time check to see what works best.

If performance is not an issue (which I doubt), keep it simple and just overwrite the two lines (without a clear, assuming you call the clear function yourself).

Another solution is to keep the word Celcius always on the same location... this means you might have to change formatting:

  • _28.6 Celcius
  • __3.8 Celcius
  • _-12.3 Celcius

Where _ are spaces (so the word Celcius is always on the same location)

  • and about the LCD itself, is often refreshing and rewriting the same string, dangerous for its durability? Jun 20 '17 at 15:35
  • I doubt, an LCD display has diodes, the same diodes that can blink many times per second without deteriorating. Jun 20 '17 at 15:43
  • 1
    Sending "Celsius " with a trailing space or two would likely accommodate changes in the number width, but using a fixed-width number format with zero blanking and keeping the "Celsius" in a fixed position might be more pleasing - it's almost a matter of opinion. Jun 20 '17 at 21:08

There is only a function to clear the entire LCD display, and that is in most cases visible.

Clearing only a few characters is done by writing spaces to it. After that you can write the new temperature to that part of the display.

You could also create a fixed length format of the temperature and use spaces to fill the unused characters. Then you can use just one write to the display.

It begins by designing the layout of the text on the display. Then you know where everything will be and how many characters are needed for each value.

@MichelKeijzers, I'm aware that my answer is almost the same as yours, but your answer seems to be for clearing an entire line. I would write the word "Celsius" or "°C" to the screen just once, and only update the value of the temperature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.