16X2 i2c lcd

조회 수: 12 (최근 30일)
mohammed sajm alsaeedi
mohammed sajm alsaeedi 2021년 3월 16일
답변: Aravind 2025년 6월 25일
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
Abdelkarem
Abdelkarem 2022년 6월 27일
Hi! Mr.Alsaeedi
i'm facing the same probleme did you find the solution ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Aravind
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:
  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!

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by