Introduction: Controlling Raspberry Pi Using Matlab

Hey, this tutorial is about controlling your headless raspberry pi using matlab. You may have to install matlab to the latest version for support to newer raspberry pi board.

Supplies

Step 1: Installing Necessaary Support Package in MATLAB

  • Click the addon icon on the matlab menu.
  • Search for MATLAB Support Package for Raspberry Pi Hardware
  • Download and install the package
  • Follow the procedure for the first time setup with matlab

Step 2: Get the Code

Download the matlab code from the link given below.

MATLAB File

Step 3: Coding

rpi=raspi('raspberrypi.mshome.net','pi','qwerty');
  • raspi is used to create connection with raspberry pi through ssh
  • raspberrypi.mshome.net- IP of pi pi-user name of your pi board
  • qwerty-password of your user account
showPins(rpi);
  • showPins is a command to show the pin out connection of your pi board connected.
    you can find the GPIO pin number using this command
for i=1:10
	writeDigitalPin(rpi,21,1);
	pause(1);
        writeDigitalPin(rpi,21,0);
	pause(1);
end
  • for loop is used to perform an specific action for specified number of times.
  • writeDigitalPin is used to write GPIO pins as high and low outputs pause is created a delay specified in terms of seconds

Step 4: Run the Code in Section

Run the first section (CTRL+ENTER) and open the variable created in workspace.

  • Try to analyze the different parameters inside rpi.
  • It gives the total description of your pi board like number of pins, number of leds, i2c and everything available on-board.

Then run the second section to display the raspberry pi board pin diagram.

  • Observe the GPIO pin number from this image.

In the third image define the led blink parameters as per your requirement.

  • You can alter the pause value to adjust the delay.
  • Change the for value to define the number of time you want the blink to execute.

Step 5: That's It!

You have done your first experiment of raspberry pi using matlab.

First Time Author Contest

Participated in the
First Time Author Contest