How to read a variable from Arduino or a PWM value from Arduino in Matlab

조회 수: 9 (최근 30일)
Szillat
Szillat 2018년 1월 19일
댓글: Mahesh 2018년 1월 23일
Hi Mathworkes
I made an RC using nrf24l01 and Arduino and now I need to see what the transmitting Arduino send as a information to my receiver. In Arduino IDE I use:
radio.read(&data, sizeof(MyData));
my data are:
struct MyData {
byte latitude;
byte longitude;}
I use this to acquire the information that I receive and, in the same code, I transform that in PWM values to control motors.
Is it any method to read this values em Matlab? I need it to create a control system.
I'm really grateful for you help.

채택된 답변

Mahesh
Mahesh 2018년 1월 19일
Establish the serial communication between Arduino and MatLab. So that you can read and use the values for creating your control system. For example:
//From your Arduino end, send the data
serial.begin('Baud rate')
if (serial.available())
serial.print('Mydata');
end
%% MatLab end, receive the data
ser=serial('Com port ', 'Baud rate')
fopen(ser);
output = fscanf(ser);
fclose(ser);
delete(ser);
  댓글 수: 2
Szillat
Szillat 2018년 1월 23일
It works but the bad thing which that is that I can only read one information. for example, if I like to read more then 'Mydata' I need to hide something.
Mahesh
Mahesh 2018년 1월 23일
Something you could do like this to read all the data until you close the serial connection
result=[];
if ~isempty(output)
result=[result;output];
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

커뮤니티

더 많은 답변 보기:  Power Electronics Community

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by