16X2 i2c lcd

12 views (last 30 days)
mohammed sajm alsaeedi
mohammed sajm alsaeedi on 16 Mar 2021
Answered: Aravind on 25 Jun 2025
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 Comment
Abdelkarem
Abdelkarem on 27 Jun 2022
Hi! Mr.Alsaeedi
i'm facing the same probleme did you find the solution ?

Sign in to comment.

Answers (1)

Aravind
Aravind on 25 Jun 2025
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:
  1. Getting started - https://www.mathworks.com/help/simulink/supportpkg/arduino_ug/io-device-builder.html
  2. 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
  3. 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!

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!