필터 지우기
필터 지우기

Change pin mode for Arduino in Simulink

조회 수: 6 (최근 30일)
John
John 2012년 9월 21일
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에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by