Main Content

getFile

Transfer file fromRaspberry Pihardware to host computer orMATLABDrive

Description

example

getFile(mypi,source)copies the specified file from the Raspberry Pi™ hardware to the MATLAB®Current Folder. Wildcards are supported.

example

getFile(mypi,source,destination)copies the file to a destination path and optional file name.

Examples

collapse all

You can copy a file, such as.profile, from the Raspberry Pi hardware to the MATLAB Current Folder on your host computer. InMATLAB Online™, the Current Folder is yourMATLAB Drive™folder.

getFile(mypi,'/home/pi/.profile')

You can use a wildcard to copy any matching file or files from the Raspberry Pi hardware to your host computer. InMATLAB Online, the folder you copy files to is located in yourMATLAB Drivefolder. You can specify the path of a destination folder. The folder must exist.

Copy the file from/home/pi/and save it toDesktop.

getFile(mypi,'/home/pi/*.png','C:\Users\myusername\Desktop')

MATLAB Online, copy the file from/home/mwuser/and save it tomyfolderinMATLAB Drive.

getFile(mypi,'/home/mwuser/*.png','myfolder')

You can copy a file from the Raspberry Pi hardware to yourMATLAB Drivefolder when connected to it fromMATLAB Online. To use your hardware fromMATLAB Online, follow the instructions inConnect to Raspberry Pi Hardware Board in MATLAB Online.

When connected to your hardware fromMATLAB Online, the default working directory is/home/matlabrpi, instead of/home/pi. Copy a file from this folder to yourMATLAB Drivefolder. YourMATLAB Drivefolder is the default startup folder inMATLAB 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 toMATLAB 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'

Copycap.jpgfrom/home/pitoMATLAB Drive.

getFile(mypi,'/home/pi/cap.jpg')

You can also specify the destination folder inMATLAB Drive. The destination folder must already exist in yourMATLAB Drive. Copymyvideo.h264from/home/matlabrpitomyfolderinMATLAB Drive.

getFile(mypi,'myvideo.h264','myfolder')

You can connect to the camera board from the MATLAB software, take a photograph, and record video.

Create a connection from the MATLAB software to the Raspberry Pi hardware.

mypi = raspi

Create a connection,mycam, from the MATLAB software to the camera board, 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, 90, 180 or 270) HorizontalFlip: 0 VerticalFlip: 0 FrameRate: 30 (2 to 30) 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: 'auto' (View available exposure modes) ExposureCompensation: 0 (-10 to 10) AWBMode: 'auto' (View available AWB modes) MeteringMode: 'average' (View available metering modes) Effects ImageEffect: 'none' (View available image effects) VideoStabilization: 'off' ROI: [0.00 0.00 1.00 1.00] (0.0 to 1.0 [top, left, width, height])

Import and display a sequence of 10 snapshots on your computer.

forii = 1:10 img = snapshot(mycam) imagesc(img) drawnowend

如果图像是upside down, change its orientation.

mycam.Rotation = 180

You can use the same approach to change the values of othercameraboardproperties.

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')

在put Arguments

collapse all

Connection to a specific Raspberry Pi hardware board, specified as araspiobject.

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/. InMATLAB Online, the default path is/home/matlabrpi/.

Example:'.profile'

Example:'/home/pi/.profile'

Example:'/home/pi/.pro*'

Data Types:char

Path and name of file on host computer, specified as a string. If not specified,getFileuses 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. InMATLAB Online, this path must be located inMATLAB Drive. Optional.

Example:'C:\Users\myusername\Desktop'

Data Types:char