Simulink S-function Serial communication problem

2 visualizzazioni (ultimi 30 giorni)
mohsbshir shir
mohsbshir shir il 2 Apr 2023
Risposto: Aravind il 25 Giu 2025
Hello
I've used arduino code to recieve data using serial communication between arduino mega on port one and IMU (WT61C1)
the data is recieved and displayed on the serial monitor of the Arduino IDE.
Now when I try to impliment this code on an S-function (normally as I do with othe codes that work fine this way)
the model is builded and run but disply only zeros always no matter what I change.
Can I know what's wrong with it, the code is typically the same I only moved the serial event function Up to declare it
before it's being used, and removed the serial.begin and serial.print commands as we don't use them.
I also tried to capture the header of the data frame using serial recieve block and serial decoder as senn on the image but have no luck either.

Risposte (1)

Aravind
Aravind il 25 Giu 2025
From the code and files you've shared, it seems that you've included Arduino-specific libraries such as "Wire.h". These libraries are not available in Simulink, which is why the S-function is unable to compile, resulting in the error you're encountering.
To communicate with the IMU using Arduino, the best approach is to use the "IO Device Builder" app, which is part of the "Simulink Support Package for Arduino Hardware". This app enables you to incorporate custom or third-party C/C++ source files as a System object, which then appears as a block in Simulink.
By using the "IO Device Builder" app, you can create a block that communicates with the IMU using "Wire.h" and other Arduino-specific libraries.
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 query!

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by