Problem with Simulink/coder to use LCD 1602 display

22 ビュー (過去 30 日間)
Riccardo Scorretti
Riccardo Scorretti 2024 年 1 月 9 日
回答済み: Riccardo Scorretti 2024 年 1 月 9 日
Hi there,
I'm trying to write a Simulink block to use with Arduino an LCD 1602 driven through the I2C port. What I would like to obtain is to be able to display some text on the LCD display connected to my Arduino Uno:
I have already written a custom block to drive with Arduino the internal LED, and it works fine (see internal_led_custom_block.zip).
I wanted to use the same approach to write a driver for the LCD 1602 display, but I am struggling to let the coder to compile my .cpp program. In particular I get the following error (and may others...) which is generated by the file:
In file included from /home/scorretti/Documents/MATLAB/SupportPackages/R2023a/3P.instrset/arduinoide.instrset/arduino-1.8.19/hardware/arduino/avr/cores/arduino/Print.h:27:0,
from /home/scorretti/Documents/MATLAB/programs/Arduino/lcd_1602_i2c/libraries/LiquidCrystal_I2C.h:6,
from /home/scorretti/Documents/MATLAB/programs/Arduino/lcd_1602_i2c/include/lcd1602.h:6,
from /home/scorretti/Documents/MATLAB/programs/Arduino/lcd_1602_i2c/demo_lcd_1602_ert_rtw/demo_lcd_1602.h:27,
from /home/scorretti/Documents/MATLAB/programs/Arduino/lcd_1602_i2c/demo_lcd_1602_ert_rtw/demo_lcd_1602_data.c:20:
/home/scorretti/Documents/MATLAB/SupportPackages/R2023a/3P.instrset/arduinoide.instrset/arduino-1.8.19/hardware/arduino/avr/cores/arduino/Printable.h:25:1: error: unknown type name 'class'; did you mean 'labs'?
class Print;
^~~~~
Up to my understanding, the problem is that the compiler is trying to compile the file Print.h like if it were written in C instead of C++, and I cannot figure out why and how to fix this.
It is not possible to configure the project so as to use C++
My C++ code (lcd1602.cpp) is basically a copy/paste from an Arduino sketch (Sketch_1_1_Display_the_string_on_LCD1602.ino) which uses the same library, but compiles and runs fine.
Similar topics / examples may be:
The last question seems really close to the problem I'm facing, but I could not solve it as well.
Any help is appreciated.
R.S.

採用された回答

Riccardo Scorretti
Riccardo Scorretti 2024 年 1 月 9 日
Actually I solved myself the problem. In case it may be useful to someone:
  • problem: the file LiquidCrystal_I2C.h was included from lcd1602.h.
  • solution: this file is included from lcd1602.cpp, and the file LiquidCrystal_I2C.cpp has to be added to the list of files to be compiled (see the method updateBuildInfo)
Surely this is not the most elegant method, but it seems to work. The fixed program and a demonstration Simulink project are available (I apologize for inelegant and/or uncorrect features of my model and programs).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by