Trying to use an S- Function to run an LCD display with an I2C interface on Ardiuno

12 views (last 30 days)
I have been trying to interface my Arduino Mega2560 with a 20x4 LCD display. I need to connect it to other systems in Simulink so I read on a different forum one of the best ways to do this was through an S function block. I used the I2C LCD library from https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library to run my function on the Arduino IDE, so I am pretty sure the function is not the problem. One of the issues I cannot seem to solve is that the library for the I2C requires the Wire.h library and I have been unable to find a download for this.
The function in C++ I am trying to call in the S function is:
#include "DispFCN.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
char unit_string[10];
char Disp_string[50];
LiquidCrystal_I2C lcd(0x27, 20, 4);
void DispFCN(int dataWhole, int dataDeci, int unit_ID) {
// The First step is to identify the type of unit by its ID
if (unit_ID == 1) {
sprintf(unit_string, "m/s");
} // This ID denotes windspeed
else if (unit_ID == 2) {
sprintf(unit_string, "F");
} // This ID denotes Temperature in F
sprintf(Disp_string, "%d.%d %s", A, B, unit_string);
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("Wind Velocity:");
lcd.setCursor(1, 1);
lcd.print(Disp_string);
}
Below is the way that I setup the S function:
The procedure that I was following to build the S function is based off of what was recommended in: https://www.youtube.com/watch?v=L86n9wZZz-g
I have a number of thoughts as to why it is not working, but the error from Simulink seems to imply that I need a version of Wire.h for the I2C LCD library to work, but I cannot find a copy of the Wire.h file to give to Matlab, so I am not sure what I need to do to get the S function to work.

Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!