Run Linux Commands on Raspberry Pi Hardware

Note

Certain Linux® functions are limited in MATLAB® Online™. See Security Considerations for Raspberry Pi in MATLAB Online for details.

Use the system function to run Linux commands on the Raspberry Pi™ hardware. Pass commands, such as 'ls -al', as the second argument. The function returns standard output from the Linux command line.

system(mypi,'ls -al')
ans =

total 100
drwxr-xr-x 10 pi   pi    4096 Nov 22 14:18 .
drwxr-xr-x  3 root root  4096 Sep 25 16:22 ..
-rw-------  1 pi   pi   21712 Nov 13 17:40 .bash_history
-rw-r--r--  1 pi   pi     220 Sep 25 16:22 .bash_logout
-rw-r--r--  1 pi   pi    3243 Sep 25 16:22 .bashrc
drwxr-xr-x  4 pi   pi    4096 Oct  1 18:17 .cache
drwxr-xr-x  6 pi   pi    4096 Oct  2 12:01 .config
drwx------  3 pi   pi    4096 Oct  1 18:17 .dbus
drwxr-xr-x  2 pi   pi    4096 Nov 13 17:30 Desktop
-rw-r--r--  1 pi   pi      35 Nov 13 17:41 .dmrc
drwx------  2 pi   pi    4096 Oct  1 18:17 .gvfs
drwxr-xr-x  3 pi   pi    4096 Oct  2 14:46 MATLAB
-rw-r--r--  1 pi   pi    5781 Feb  3  2013 ocr_pi.png
-rw-r--r--  1 pi   pi     675 Sep 25 16:22 .profile
drwxrwxr-x  2 pi   pi    4096 Mar 10  2013 python_games
drwxr-xr-x  8 pi   pi    4096 Oct  2 12:41 wiringPi
-rw-------  1 pi   pi      66 Nov 13 17:41 .Xauthority
-rw-------  1 pi   pi     261 Nov 13 17:41 .xsession-errors
-rw-------  1 pi   pi     449 Nov 13 17:40 .xsession-errors.old

Use the openShell function to open an SSH terminal that is connected to the Linux command-line interface on the Raspberry Pi hardware. Log in as the pi user. The default password for pi is raspberry.

mypi = raspi()
openShell(mypi)

It is a good security practice to change the default password. Use the SSH terminal window to run the raspi-config utility.

sudo raspi-config

Select 2 Change User Password and change the password.

After changing the password, clear the mypi handle and any handles that you created using mypi. Then, use raspi to create a new connection based on the new password.

clear mypi
mypi = raspi('172.28.201.137','pi','newpassword')

For more information, see Linux.