フィルターのクリア

Call python stepper motor code to Matlab with Raspberry Pi

7 ビュー (過去 30 日間)
Tharima Ferdausi
Tharima Ferdausi 2021 年 3 月 14 日
回答済み: puneet sharma 2021 年 11 月 16 日
Hello
This is a python code for a stepper motor with raspberry pi. I am trying to call this python code to Matlab but nothing is really happening. Using a def function and system command did not work. I want Matlab to call python to make the stepper motor rotate but I did get an error. What should I do?
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""Simple test for using adafruit_motorkit with a stepper motor"""
import time
import board
from adafruit_motorkit import MotorKit
kit = MotorKit(i2c=board.I2C())
#Number of times the shaft rotates and pauses (same as number of pictures)
for y in range (67):
#Input for range multiplied by 1.8 (step size) is amount of rotation (degrees)
for x in range(3):
#Moves the motor a single step (1.8 degrees)
kit.stepper1.onestep()
#Time between adjacent steps (seconds)
time.sleep(.5)
#Time for image capture (seconds)
time.sleep(2)

回答 (3 件)

Prasanth Sunkara
Prasanth Sunkara 2021 年 3 月 25 日
編集済み: Prasanth Sunkara 2021 年 3 月 25 日
Hi Tharima,
"system" function when called without passing "raspi" object will run the command on host PC on which the MATLAB is currently running.
What you need in this case is to make system command execute on Pi.
Alternatively, you can do the same thing python script is doing from MATLAB(or Simulink) support package for Raspberry Pi. The support package has MATLAB function/ Simulink blocks to work with servos, GPIOs, Audio, Video and other peripherals.
https://www.mathworks.com/help/supportpkg/raspberrypi/examples.html
Hope it helps!
Thanks,
Prasanth
  1 件のコメント
Asvin Kumar
Asvin Kumar 2021 年 3 月 25 日
Thanks for correcting me, Prasanth. Your answer is helpful.

サインインしてコメントする。


Asvin Kumar
Asvin Kumar 2021 年 3 月 18 日
編集済み: Asvin Kumar 2021 年 3 月 18 日
This is not a MATLAB error. The output that you're seeing comes from the system. Refer doc page for system command's output.
This is likely caused because you don't have the 'board' python library installed. Are you sure the program 'StepperMATLABTest.py' works when called from Python?
  1 件のコメント
Prasanth Sunkara
Prasanth Sunkara 2021 年 3 月 25 日
編集済み: Prasanth Sunkara 2021 年 3 月 25 日
This particular answer is relevant only for "OS command execution on the PC" which runs MATLAB.
Please see this to understand how you can run an OS command on Raspberry Pi from MATLAB.

サインインしてコメントする。


puneet sharma
puneet sharma 2021 年 11 月 16 日
Hi did you find the solution yet?
i am also facing some similar problem.
what you can do is try to call python file in raspberry pi using system command.

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Raspberry Pi Hardware についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by