getFile
Transfer file from Raspberry Pi hardware to host computer or MATLAB Drive
Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.
Description
Examples
Download a File to the MATLAB Current Folder
You can copy a file, such as .profile
, from the
Raspberry Pi hardware to the MATLAB Current Folder on your host computer. In MATLAB
Online™, the Current Folder is your MATLAB
Drive™ folder.
getFile(mypi,'/home/pi/.profile')
Download Files to a Folder on Your Computer or on MATLAB Drive
You can use a wildcard to copy any matching file or files from the Raspberry Pi hardware to your host computer. In MATLAB Online, the folder you copy files to is located in your MATLAB Drive folder. You can specify the path of a destination folder. The folder must exist.
Copy the file from /home/pi/
and save it to
Desktop
.
getFile(mypi,'/home/pi/*.png','C:\Users\myusername\Desktop')
In MATLAB
Online, copy the file from /home/mwuser/
and save
it to myfolder
in MATLAB
Drive.
getFile(mypi,'/home/mwuser/*.png','myfolder')
Download Files to MATLAB Drive in MATLAB Online
You can copy a file from the Raspberry Pi hardware to your MATLAB Drive folder when connected to it from MATLAB Online. To use your hardware from MATLAB Online, follow the instructions in Connect to Raspberry Pi Hardware Board in MATLAB Online.
When connected to your hardware from MATLAB
Online, the default working directory is
/home/matlabrpi
, instead of
/home/pi
. Copy a file from this folder to your
MATLAB
Drive folder. Your MATLAB
Drive folder is the default startup folder in MATLAB
Online. View its contents by clicking the Current Folder tab on the
left side of the Command Window.
getFile(mypi,'myvideo.h264')
You can also copy files from other folders on your hardware to MATLAB
Drive. List the files in /home/pi
.
system(mypi,'ls /home/pi')
ans = 'cap.jpg debug.log Desktop Documents Downloads matlab_online_login.expect matlab-rpi.deb Music Pictures Public python_games Templates Videos'
Copy cap.jpg
from /home/pi
to
MATLAB
Drive.
getFile(mypi,'/home/pi/cap.jpg')
You can also specify the destination folder in MATLAB
Drive. The destination folder must already exist in your MATLAB
Drive. Copy myvideo.h264
from
/home/matlabrpi
to myfolder
in
MATLAB
Drive.
getFile(mypi,'myvideo.h264','myfolder')
Capture Images from the Camera Board
Create a connection from the MATLAB to the Raspberry Pi board. If you encounter errors after running the above command, try using
additional arguments (as listed in raspi
) or refer to Troubleshoot Connecting Issues to Raspberry Pi Hardware.
mypi = raspi;
Create a connection, mycam
, from the MATLAB software to the camera board on the Raspberry Pi hardware, and set the image
resolution. The connection displays the camera board properties.
mycam = cameraboard(mypi,"Resolution","1280x720")
mycam = Cameraboard with Properties: Name: Camera Board Resolution: "1280x720" (View available resolutions) Quality: 10 (1 to 100) Rotation: 0 (0 or 180) HorizontalFlip: 0 VerticalFlip: 0 FrameRate: 30 (2 to 90) Recording: 0 Picture Settings Brightness: 50 (0 to 100) Contrast: 0 (-100 to 100) Saturation: 0 (-100 to 100) Sharpness: 0 (-100 to 100) Exposure and AWB ExposureMode: "normal" (View available exposure modes) ExposureCompensation: 0 (-10 to 10) AWBMode: "indoor" (View available AWB modes) MeteringMode: "average" (View available metering modes) Effects ROI: [0.00 0.00 1.00 1.00] (0.0 to 1.0 [top, left, width, height])
Capture and display a sequence of 10 snapshots on your computer.
for ii = 1:10 img = snapshot(mycam); imagesc(img) drawnow end
Each of the 10 snapshots is the latest image captured by the camera.
If the image is upside down, change its orientation.
mycam.Rotation = 180
You can use the same approach to change the values of other
cameraboard
properties.
Record a 60 second video.
record(mycam,"myvideo.h264",60)
Stop the recording immediately.
stop(mycam)
Copy the video from the board to your computer.
getFile(mypi,"myvideo.h264","C:\MATLAB")
Delete the video file from the hardware to free up space.
deleteFile(mypi,"myvideo.h264")
Input Arguments
mypi
— Connection to Raspberry Pi hardware board
raspi
object
Connection to the Raspberry Pi hardware board, specified as a raspi
object.
source
— Path and name of file on Raspberry Pi hardware
path and name file name
Path and file name on the Raspberry Pi hardware, specified as a string. You can use either the
absolute path from the root folder, or the relative path from the present
working folder. Use Linux® path and file naming conventions. The default path is
/home/pi/
. In MATLAB
Online, the default path is
/home/matlabrpi/
.
Example: '.profile'
Example: '/home/pi/.profile'
Example: '/home/pi/.pro*'
Data Types: char
destination
— Path and name of file on host computer
MATLAB Current Folder (default) | destination path
Path and name of file on host computer, specified as a string. If not specified,
getFile
uses the MATLAB Current Folder and the current file name. Use the naming
conventions of the operating system on the host computer. This function does
not create new folders. Folders in the path must exist. In MATLAB
Online, this path must be located in MATLAB
Drive. Optional.
Example: 'C:\Users\myusername\Desktop'
Data Types: char
See Also
system
| openShell
| putFile
| deleteFile
| cameraboard
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)