I2C Library for Hobby Components SmartLCD (HCMODU0122)

Useful guides, libraries, and example sketches to support our Arduino based products.
andrew
Site Admin
Posts: 1457
Joined: Sun Aug 05, 2012 4:15 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by andrew » Fri Feb 10, 2023 3:08 pm

is it possible to write to more displays in one code?
You can do this by creating two instances of the library and then assigning a different I2C address to each instance. Here is an example of how to do it:

  1. #include "SmartLCDI2C.h"      //Include the SmartLCD I2C Library
  2.  
  3. #define I2C_ADD1 0x27         //I2C address of SmartLCD 1
  4. #define I2C_ADD2 0x28         //I2C address of SmartLCD 2
  5.  
  6. // Create two instances of the library (SmartLCD1 & SmartLCD2)
  7. // and assign them different addresses
  8. SmartLCD SmartLCD1(I2C_ADD1);
  9. SmartLCD SmartLCD2(I2C_ADD2);
  10.  
  11.  
  12. void setup()
  13. {
  14.   // Initialise both instances of the library
  15.   SmartLCD1.init();
  16.   SmartLCD2.init();
  17.  
  18.   // Clear both screens
  19.   SmartLCD1.Clear();
  20.   SmartLCD2.Clear();
  21. }
  22.  
  23.  
  24. void loop()                
  25. {
  26.   // Print something to each screen
  27.   SmartLCD1.Print("Hello");
  28.   SmartLCD2.Print("World !");
  29.  
  30.   while(1);
  31. }
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by RogerL » Sun Feb 09, 2025 8:39 pm

Hi Andrew. I am trying to use one of the HCMODU0262 displays in I2C mode with an ESP32 C3 board. I realise that the display is 5V, so I was planning to use level shifters to boost the I2C signals. However, when I try and compile the simple Hello World! code provided in the forum topic for the display, I get errors:

C:\Data\Roger_Hobby\Control_Systems\Arduino\libraries\SmartLCD\SmartLCDI2C.cpp:164:6: error: default argument given for parameter 2 of 'void SmartLCD::Print(float, uint8_t)' [-fpermissive]
164 | void SmartLCD::Print(float val, uint8_t dp = 0)
| ^~~~~~~~
In file included from C:\Data\Roger_Hobby\Control_Systems\Arduino\libraries\SmartLCD\SmartLCDI2C.cpp:44:
C:\Data\Roger_Hobby\Control_Systems\Arduino\libraries\SmartLCD\SmartLCDI2C.h:96:14: note: previous specification in 'void SmartLCD::Print(float, uint8_t)' here
96 | void Print(float val, uint8_t dp = 0);
| ^~~~~
exit status 1
Error compiling for board XIAO_ESP32C3.

I also tried compiling the code for an Arduino Uno and that works fine, but it doesn't compile for a Lolin D32. I realise that the library was written for AVR Arduinos, but can you suggest a fix for these ESP32 compilation problems? Or would I be better off using a different display in this case?

andrew
Site Admin
Posts: 1457
Joined: Sun Aug 05, 2012 4:15 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by andrew » Mon Feb 10, 2025 8:51 am

Hi Roger, it should work for ESP32. I'll take a look at it but in the short term can you give the following a try:

Open up the SmartLCDI2C.cpp library file in a text editor located at:

C:\Data\Roger_Hobby\Control_Systems\Arduino\libraries\SmartLCD\SmartLCDI2C.cpp


Find the following line on line 164:

  1. void SmartLCD::Print(float val, uint8_t dp = 0)

change it to this:

  1. void SmartLCD::Print(float val, uint8_t dp)

That should fix the error.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by RogerL » Mon Feb 10, 2025 8:11 pm

Hi Andrew. Yes that works. Thanks. Level shifters definitely required though.

andrew
Site Admin
Posts: 1457
Joined: Sun Aug 05, 2012 4:15 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by andrew » Tue Feb 11, 2025 9:42 am

Thanks for confirming. I'll try and get a fixed version of the library uploaded today but I expect it to work fine with your ESP32 after that fix.

Level shifters definitely required though.
Yep, I don't know if your ESP32 is 5V tolerant on its I2C pins but I would suspect that it's not. So that would be the safe thing to do.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by RogerL » Tue Feb 11, 2025 8:28 pm

Without the level shifters I was able to write text to the screen from the ESP32C3, but commands to clear screen, control backlight etc. didn't work. Everything worked fine with level shifters on the two I2C lines.

andrew
Site Admin
Posts: 1457
Joined: Sun Aug 05, 2012 4:15 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by andrew » Wed Feb 12, 2025 11:36 am

Without the level shifters I was able to write text to the screen from the ESP32C3, but commands to clear screen, control backlight etc. didn't work. Everything worked fine with level shifters on the two I2C lines.
Weird, but I guess it must just be on the edge of working/not working.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by RogerL » Thu Feb 13, 2025 5:16 pm

The manual for the SmartLCD quotes "Digital input pins high level voltage" as 0.7 x Vdd, so around 3.5V. 3.3V is therefore borderline logic high.

andrew
Site Admin
Posts: 1457
Joined: Sun Aug 05, 2012 4:15 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by andrew » Fri Feb 14, 2025 10:19 am

That’s a very good point.

To clarify, what I meant by weird was the fact that some commands were working and some not. I’d expect all or nothing. As I say, it's probably on the edge and maybe those commands cause the display to use more current than the others. I'm just guessing though.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Arduino”