How can I use MATLAB code with BeagleBONE Black?
4 次查看(过去 30 天)
显示 更早的评论
Im using Computer Vision and Image Processing toolboxes of MATLAB to write a code which is detecting faces, recognizing number plates and converts them to text file. My code is completed but I don't know how it works on Beagle Bone Black platform.
Can I install Matlab directly on BBB (Linux OS). I read that it can be used with Beagle Board. But I cant find any info about BeagleBone Black.
I have also tried to convert it C file by using Matlab Coder , but this is not possible because all of the functions are not avaible almostly. Is there any way to do that? If there is no any way, will it be avaible and when?
By the way, I use viola jones algorith for face detection.
Best regards
回答(2 个)
Kurt Stewart
2018-5-17
There are functions that let you control the beaglebone look for "matlab support package for beaglebone"
0 个评论
Jorge
2015-6-3
Here are the steps for controlling the BeagleBone Black card from Matlab using a very simple program.
Hardware/Software used:
Windows Platforms: XP and 7 Hardware: BeagleBone Black BBB Operating System: Debian GNU/Linux 7 BeagleBone image: BeagleBone Debian Image 2014-04-23 Matlab version: R2009b g++ compliler. The Linux distributions come with a built-in c-compiler (gcc) and c++ compiler (g++). Example program: myprog from http://inspire.logicsupply.com/2014/07/beaglebone-c-programming-example.html Instructions
First, let’s create a file 'myprog.cpp' in BBB’s root directory using the nano editor (or vim, or emacs - if you prefer) Then, we will connect to the BeagleBone from Matlab and log in as 'root'.
STEP 1- Source Code Example program from elinux.org:
#include <iostream>
#include <stdio.h>
#include <unistd.h>
using namespace std;
int main(){
cout << "LED Flash Start" << endl;
FILE *LEDHandle = NULL;
const char *LEDBrightness="/sys/class/leds/beaglebone:green:usr0/brightness";
for(int i=0; i<3; i++){
if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
fwrite("1", sizeof(char), 1, LEDHandle);
fclose(LEDHandle);
}
usleep(1000000);
if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){ fwrite("0", sizeof(char), 1, LEDHandle); fclose(LEDHandle); } usleep(1000000); } cout << "LED Flash End" << endl; }
Program Overview
In this simple example program, we flash the built-in LED USR0 three times. We start out by sending a message to 'cout' (console output) to let us know that the program has started. Finally, a simple message is sent to indicate that we are done is sent to the console.
Step 2 - Compiling: g++ myprog.cpp -o myprog
This command calls the C++ compiler with the source file myprog.cpp and outputs (-o) the file myprog.
STEP 3- Running the Program within the BeagleBone: ./myprog
The program will flash the built-in USR0 LED three times, and display a message at the start and the end:
root@beaglebone:~# ./myprog LED Flash Start LED Flash End
STEP 4- Running the Program Manually from Matlab
Running the program manually in Matlab using basic serial port commands. Create a serial port object for serial port COM5 (check Windows Device Manager to find out the serial port used by the BeagleBone): s=serial('COM5');
Configure the Baudrate to 115,200: set(s,'BaudRate',115200);
Connect the serial port object to the BeagleBone:
fopen(s);
Write data to the BeagleBone. Here we log in as root: fprintf(s,'root')
Write data to the BeagleBone. This time execute the program myprog: fprintf(s,'./myprog')
Disconnect and clean up — When you no longer need the serial port object, disconnect it from the device using the fclose function: fclose(s)
Remove the serial port object from memory using the delete function: delete(s)
Remove the serial port object from the MATLAB workspace using the clear command: clear s;
If you encounter any of the messages listed below in Matlab just simply run the following command: delete(instrfind({'Port'},{'COM5'}))
then disconnect the USB cable from the BeagleBone momentarily and then connect it again before continuing.
??? Error using ==> serial.fopen at 72 Port: COM5 is not available. No ports are available. Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Error in ==> LED_tester>LED_tester_OpeningFcn at 77 fopen(s);
Error in ==> gui_mainfcn at 221 feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> LED_tester at 42 gui_mainfcn(gui_State, varargin{:});
This simple example program should help you get started with Matlab controlling the BeagleBone Black where you can go from here.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!