Change pin mode for Arduino in Simulink

3 次查看(过去 30 天)
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.

采纳的回答

Ryan G
Ryan G 2012-9-21
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 个评论
John
John 2012-9-28
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 2012-9-28
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by