Simulink S-function Serial communication problem

4 visualizaciones (últimos 30 días)
mohsbshir shir
mohsbshir shir el 2 de Abr. de 2023
Respondida: Aravind el 25 de Jun. de 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.

Respuestas (1)

Aravind
Aravind el 25 de Jun. de 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!

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by