16X2 i2c lcd
5 次查看(过去 30 天)
显示 更早的评论
how to use i2c lcd on matlab/simulink ?
i want to display the hello world text and controling the cruser location from simulink
1st image shows the files in my working directory
--------------------------------------------
here is what i have wrote in the s-function
Data Properties -> inpute ports

both unint 8
Data Properties -> Outputs ports
none
Libraries -> includes
#ifndef MATLAB_MEX_FILE
#define ARDUINO 100
#include <Arduino.h>
#include "Wire.h"
#include "Wire.cpp"
#include "LiquidCrystal_I2C.h"
#include "LiquidCrystal_I2C.cpp"
LiquidCrystal_I2C lcd(0x27,16,2);
#endif
Outputs
#ifndef MATLAB_MEX_FILE
lcd.init();
lcd.init();
lcd.backlight();
lcd.setCursor(cruserX[0],cruserY[0]);
lcd.print("Hello, world!");
#endif
--------------------------------------------
i did add extern "C" befor void in the i2cLCD_wrapper.cpp file
and as u can see i changed its extension fron c to cpp
--------------------------------------------
this is how my s-function looks

--------------------------------------------
and the error file is also attached please have a look at it
1 个评论
回答(1 个)
Aravind
2025-6-25
From the code you have shared, it appears that you are using Arduino-specific libraries such as "Wire.h." The reason the S-function is not compiling is that these libraries are not available within Simulink.
To resolve this issue and control the LCD display using the Arduino-specific libraries, the recommended approach is to use the "IO Device Builder" app, which is part of the "Simulink Support Package for Arduino Hardware". This app allows you to include custom or third-party C/C++ source files as a System object, which then becomes available as a block in Simulink.
By using the "IO Device Builder" app, you can create a block that communicates with the LCD display using the Arduino-specific libraries. Once you deploy the model to the Arduino, it will run independently and display the desired text.
For more details on the "IO Device Builder" app, you can refer to the following documentation: https://www.mathworks.com/help/simulink/arduino-io-device-builder.html.
Additionally, here are a few tutorials to help you get started with the "IO Device Builder" app:
- Getting started - https://www.mathworks.com/help/simulink/supportpkg/arduino_ug/io-device-builder.html
- Interfacing DHT11 sensor with Arduino using IO Device Builder - https://www.mathworks.com/help/simulink/supportpkg/arduino_ref/dht11-relative-humidity-temperature-io-device-builder.html
- Interfacing ADXL343 sensor with Arduino - https://www.mathworks.com/help/simulink/supportpkg/arduino_ref/adxl343-read-acceleration-io-device-builder.html
I hope this resolves your issue!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!