필터 지우기
필터 지우기

How to read data from arduino bluetooth?

조회 수: 2 (최근 30일)
kintali narendra
kintali narendra 2016년 9월 21일
댓글: Walter Roberson 2016년 9월 23일
I am successful in sending data from matlab to arduino via Bluetooth, but I am unable to read the data sent by Arduino-bluetooth(JY-MCU).
% serial communication between matlab and bluetooth
delete(instrfind);
b = Bluetooth('BTslave',1);
fopen(b); %write and read function
fwrite(b,'K');
A = fread(b,5)
fclose(b);
clear('b');
I am able to read 5 values but they are just random values not the right values.

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 21일
Watch out for the default on fread() being 'double' . If the bluetooth device is sending data in some other datatype you need to adjust your fread() to know that.
  댓글 수: 6
kintali narendra
kintali narendra 2016년 9월 23일
편집: kintali narendra 2016년 9월 23일
Hi Walter, sorry, I didnt see the mistake in the comment section. It worked perfectly with fscanf() thanku. Can u say why it didn't work for fread() and how to make matlab to read the value continuously.
Walter Roberson
Walter Roberson 2016년 9월 23일
Earlier I indicated that the default for fread was double. That was incorrect: the default is uint8=>double . Each character of the printable values was being interpreted as a separate value, but you needed a group of printable values to be read together as a single value.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by