Using Raspberry Pi SPI interface from Simulink

조회 수: 4 (최근 30일)
Rebecca Reck
Rebecca Reck 2014년 6월 10일
답변: Jhon Ardilla 2019년 9월 20일
Hello,
I found this example for collecting analog data with a Raspberry Pi and an MCP3008. It works great in the MATLAB command window. However, I'd love to be able to do the same thing in Simulink. I've tried using a MATLAB Function block in Simulink, however I can't seem to get it to pass the mcp3008 parameter into the function. I've made it a global variable and I've tried to use a To Workspace block and neither seem to work. It seems like a waste of resources to start and stop the connection to the Raspberry Pi on each Simulink iteration.
Does anyone have any ideas on how to make this work?
Thank you, Rebecca

답변 (4개)

Pjer
Pjer 2016년 9월 14일
maybe some command in s-function is not supported,so what you need id SPI-driver which read from analog signal.You may like this: SPI driver

mprice
mprice 2016년 10월 28일
Try using the WiringPi library, found here: WiringPi
It contains c code to access various Raspberry Pi capabilities, including SPI. You can implement it in an s-function or the s-function builder as long as you're including the right headers and have the library available in your working directory. You also want to make sure that the code is stored on the Pi itself as well, and make sure that “-lwiringPi” is included in the linker flags in the Simulink makefile.
  댓글 수: 1
Alex83
Alex83 2017년 1월 7일
Hi! I also have this problem...for newbies it is hard to find a step-by-step instruction how to implement wiringpi in simulink and the rpi device. Is there a chance that you could help me with a short step-by-step tutorial imagining that there is a blank Matlab 2016 version only with RPI support package installed? What do I do next? Kind regards, Alex

댓글을 달려면 로그인하십시오.


Alex83
Alex83 2017년 1월 7일
By the way, when I am trying to run Rebecca's example, I get always a very long error message starting with:
Error executing command "touch -c /home/pi/untitled_ert_rtw/.*;make -f untitled.mk all -C /home/pi/untitled_ert_rtw". Details:*
What do I do wrong?
  댓글 수: 2
Fernando Lima Saraiva Filho
Fernando Lima Saraiva Filho 2017년 5월 5일
Hello Alex83. I have the same message of error in another problem. Did you find a solution for this? Thanks in advance. Fernando.
Morteza aliyari
Morteza aliyari 2017년 11월 24일
편집: Morteza aliyari 2017년 11월 24일
hi,i have same problem like Alex83. i can't use any wiringPi functions on s_function in matlab 2017a simulink. i add wiringPi to rpi3b too.but error didn't change. Anyone can help?

댓글을 달려면 로그인하십시오.


Jhon Ardilla
Jhon Ardilla 2019년 9월 20일
¿Alguien pudo encontrar la solución?

카테고리

Help CenterFile Exchange에서 Raspberry Pi Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by