Go Down

Topic: Interfacing Arduino with Simulink and embedded M Code (Read 1 time) previous topic - next topic


I have a simulink model where I want to use an ultrasonic sensor for feedback in my control loop. I tried using only simulink blocks found here: http://www.mathworks.com/matlabcentral/fileexchange/35639 . However, it turns out that changing the pin mode from an output to an input is not supported at this time. So my next approach was to use a Matlab function block and encode the logic for the sensor there. I downloaded the support package found here: http://www.mathworks.com/academia/arduino-software/arduino-matlab.html and I tried converting the C code for the ultrasonic sensor found here: http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor into Matlab code using the provided functions. My code works fine as a standalone M script with the server program running on the Arduino. However when I use it as a function in Simulink, it no longer works. I get errors such as the delete function not working because destructors are not supported by the code generator. Does anyone have an arduino.m file I can use that is compatible with the simulink code generator? Thank you.


Hi, I am using an ultrasonic sensor HC-SR04 which has the ping pin separated but i wasn`t able to time the returned echo or even pinging the sensor. (in simulink) how did you manage that?
if your issue is only in separating the pins you can try connecting 2 pins to the ping pin. one to read and one to ping. and add a resistor to the read pin so it won`t short circuit and burn (if it has no internal resistors, i`m not sure at that).

In addition as a fellow matlab user do you have an idea how to read sensors using I2C protocol via simulink?

Go Up