Hobby Components 1602 SmartLCD (HCMODU0122)

LCD, TFT, OLED, LED modules
andrew
Site Admin
Posts: 791
Joined: Sun Aug 05, 2012 4:15 pm

Re: Hobby Components 1602 SmartLCD (HCMODU0122)

Post by andrew » Fri Jun 22, 2018 1:08 pm

This is one of the common sources of confusion when first learning to program in C++. This is because there are two common methods to handle strings which can at first sight look similar to each other but are in fact different and not directly interchangeable. The first type is a C++ String (note the capital) object. This is the type that you are using in your sketch and it's actually a class (think of it like and Arduino library) that each time you create a string your actually creating an instance (a copy of the library) which has a number of member functions and properties associated with it. These then handle the string for you in the background. However, the print function is expecting a different type of string called character string which is just an array of characters with a null terminating byte at the end of it.

The former makes handling strings easier as its handling manipulation (concatenation, comparison, copying, etc) for you in the background. However the disadvantage is that this method is memory intensive. This is not a problem with programming in C++ on a PC with gigs of memory, but on a tiny microcontroller every byte of RAM is important. This is also why the library, being written for Arduinos with small amounts of memory, only makes use of character arrays which using the bare minimum of memory. The option is then there to add your own conversion function if memory isn't an issue in your sketch.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply