-1

I have a problem with lcd, I have NUCLEO64 L746RG , I have Lcd Display and I2C connected to it. When I verify code it gives me and long error and I can not find the solution or cause of this error:

In file included from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h:149,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/stm32/stm32_def.h:48,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/stm32/clock.h:19,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/wiring_time.h:23,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/wiring.h:38,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/Arduino.h:36,
                 from C:\Users\User\AppData\Local\Temp\arduino-sketch-B028C48DF91C28F6EAA5B0CE34D27EE2\sketch\Displaylcd1.ino.cpp:1:
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:29: error: expected identifier before '(' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                              ~            ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ~             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:29: error: expected class-name before '(' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:29: error: expected '{' before '(' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                              ~            ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ~             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\Documents\Arduino\Displaylcd1\Displaylcd1.ino:2:22: error: variable 'LiquidCrystal_I2C lcd' has initializer but incomplete type
    2 | LiquidCrystal_I2C lcd(0x27,16,2);  /*I2C scanned address defined + I2C screen size*/
      |                      ^
Multiple libraries were found for "LiquidCrystal_I2C.h"
  Used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal
  Not used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal_I2C
exit status 1

Compilation error: variable 'LiquidCrystal_I2C lcd' has initializer but incomplete type

This is my code:

#include <LiquidCrystal_I2C.h>  /*include LCD I2C Library*/
LiquidCrystal_I2C lcd(0x27,16,2);  /*I2C scanned address defined + I2C screen size*/
void setup() {
  lcd.init();  /*LCD display initialized*/
  lcd.clear();     /*Clear LCD Display*/
  lcd.backlight();      /*Turn ON LCD Backlight*/
  lcd.setCursor(2,0);   /*Set cursor to Row 1*/
  lcd.print("I2C LCD Nano"); /*print text on LCD*/
  lcd.setCursor(2,1);   /*set cursor on row 2*/
  lcd.print("Linuxhint.com"); /*print message on LCD*/
}
void loop() {
}

I do not know why, I am not including anything else so why is it giving me this error?

PLEASE HELP, I AM WORKING ON IT for 8 hours AN I STILL COULD NOT FIGURE OUT WHAT IS THE PROBLEM, PLease help

2
  • 2
    WHY ARE YOU SHOUTING?
    – VE7JRO
    Feb 6, 2023 at 19:30
  • please format the error log same as code
    – jsotola
    Feb 6, 2023 at 19:52

1 Answer 1

1

Normally I wouldn't answer this, but the error is not exactly in your code but (seemingly at least) in two common things in the Arduino ecosystem.

Roughly speaking, the library you're trying to use is incompatible with the STM32 board support you're using.

The error message sort of tells this. It may help to read it backwards:

<sketchbook>\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~

So, it is in your installed LiquidCrystal library trying to process the definition of the LCD class, and having a problem with LCD, or rather in expansion of macro 'LCD'. So, there's macro called LCD that it's trying to expand at that point, which should be a red flag.

The top part is where the compiler proper is having issues with the macro expansion where it causes a more fundamental error, error: expected identifier before '(' token This is because it is trying to insert the macro definition directly into where it has found it resulting in this code effective after preprocessing:

class ((LCD_TypeDef *) LCD_BASE) : public Print

which is gibberish. It's pointing to the first open parenthesis there and saying expected identifier, the identifier being the class name it expected to see, not this cast and other stuff that follows. Whoever wrote your LiquidCrystal library did not expect LCD to already be defined as something via macro. This is one of a number of reasons why macros are hated.

The bulk of this is indicating the how the macro got to where it came from to where it wound up. The macro started in stm32l4xx.h in CMSIS and wound it's way into the LiquidCrystal header through Arduino.h and everything in between:

In file included from <Arduino15>\<STM32boardSupport>\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h:149,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/stm32/stm32_def.h:48,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/stm32/clock.h:19,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/wiring_time.h:23,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/wiring.h:38,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/Arduino.h:36,
                 from <Temp>\arduino-sketch-B028C48DF91C28F6EAA5B0CE34D27EE2\sketch\Displaylcd1.ino.cpp:1:

To oversimply a bit CMSIS is the semi-standard header files that ARM chip makers are supposed to provide that among other things define hardware registers. Although I haven't investigated it, it seems likely that whatever chip you're using has a built in LCD driver, and so there are things, macros namely, that have "LCD" in the name. Unfortunately for you, one just called LCD.

You could try renaming all of the uses all of the uses of LCD within the LiquidCrystal library that you have to some other name. Or you could try inserting #undef LCD after the include of Arduino.h in the LCD.h header in an attempt to undefined the macro so that the LCD in the class definition is not expanded. But, I would be looking for different versions of the library and making sure the library is even the one you think it is, because everyone and their dog seems to have made some library called LiquidCrystal at some point or another. It would be a pity if you went through all trouble to find out you weren't even looking at the right library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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