Change pin mode for Arduino in Simulink

9 views (last 30 days)
I'm trying to compile a Simulink program that uses a stateflow chart with an Arduino board as my target. I keep getting the error: "Both the 'Digital Output' block and the 'Digital Input' block use the pin number 7. Change the value of the parameter 'Pin number' on the 'Digital Output' block, or the value of the parameter 'Pin number' on the 'Digital Input' block so that the parameter conflict is resolved." However, I need to be able to change the pin mode in my application. A pulse has to be sent to the ultrasonic sensor and then it has to wait for a return pulse. I'm not sure how to change the pin mode in Simulink from output to input. Any help on this would be appreciated. Thanks.

Accepted Answer

Ryan G
Ryan G on 21 Sep 2012
What's going on is each pin can only do 1 thing, as pin 7 can ONLY be used for output or ONLY be used for input.
Looking at this ultrasound sensor and the code that follows, they are discretely switching the pin 7 later on. There is an answer here which says this cannot be done directly.
There are 2 options as I see it:
1) Instead of using the Simulink I/O blocks, you can write an s-function that will perform the digital i/o
2) Find a sensor that uses 2 pins instead of 1.
You should have the code for the digital I/O already (I think that's what's on the sensor link above) so all you would need to do is implement that via s-function.
  8 Comments
John
John on 28 Sep 2012
Thank you. That worked. By encapsulating all my m-code into a function and then using the coder.extrinsic command in an Matlab function simulink block, I was able to get the sensor readings. I also modified the server code that's installed on the Arduino to be able to read in the return pulse and so that I would only have to send one command from Matlab over the serial link in order to get the distance measurement. The only problem I see with this solution is that I have to leave the Arduino tethered to my computer but that's OK.
Ryan G
Ryan G on 28 Sep 2012
It's great to hear that you worked this out. May I suggest you make an enhancement request since it looks like using the same pin I/O is a common workflow for this type of sensor.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!