フィルターのクリア

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 Center および File ExchangeMATLAB 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