Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 12256|回復: 7
打印 上一主題 下一主題

用matlab讀取arduino serial.print的方法

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-2-28 14:58:07 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
小弟我目前在使用arduino來做超音波的讀取,希望能用matlab繪圖的功能把arduino裡面serial.print的data儲存在matlab並畫圖。
matlab裡面有讀取 serial com port 的功能 。例如:

s2 = serial('COM23', 'BaudRate', 9600);
fopen(s2)
fprintf(s2,'*IDN?');
idn = fscanf(s2);

但由此程式出來的數值與arduino serial.print 不同且不連續。
想請問有大大做過類似以"matlab讀取arduino資料"的方法嗎。
謝謝指教
2#
發表於 2012-2-28 22:46:15 | 只看該作者
回復 1# iwanturass


在下也在做類似的事情,擷取的是三軸加速度規的訊號,來畫二維的圖形。
請問你有用arduino與Matlab通訊的套件跟涵式庫嗎?(網址如下)http://www.mathworks.com/academia/arduino-software/arduino-matlab.html

這個是個很好溝通的方式,不過必須在arduino寫入一個與Matlab溝通的程式,
而我還必須要讓他去擷取加速度規的訊號,目前有點小困擾...
3#
 樓主| 發表於 2012-2-29 13:35:26 | 只看該作者
回復 2# LCW

目前還沒有耶,謝謝你給我這寶貴的資訊,我研究一下,如果有進展我會在跟你方想。謝謝你
4#
 樓主| 發表於 2012-3-15 02:47:45 | 只看該作者
回復 3# iwanturass

LCW大大,請問你在a=arduino('COM12'); 這邊會有問題嗎,我明明是12沒錯 但是他一直說

"??? Error using ==> arduino>arduino.arduino at 102
Connection unsuccessful, please make sure that the Arduino is powered on, running either srv.pde, adiosrv.pde or
mororsrv.pde, and that the board is connected to the indicated serial port. You might also try to unplug and
re-plug the USB cable before attempting a reconnection."

你有相同問題嗎
5#
發表於 2012-3-16 19:51:12 | 只看該作者
本帖最後由 LCW 於 2012-3-16 20:54 編輯

Connection unsuccessful, please make sure that the Arduino is powered on, running either srv.pde, adiosrv.pde or mororsrv.pde, and that the board is connected to the indicated serial port. You might also try to unplug andre-plug the USB cable before attempting a reconnection."

你的arduino有把srv.pde或adiosrv.pde 編譯好放進去嗎?
6#
 樓主| 發表於 2012-3-20 05:28:23 | 只看該作者
To LCW:
我沒有做你所說的事情,可否請教一下,但是我最近試一試竟然可以讀的到資料了,但是用了一陣子就會找不到com port,
以及我不懂假設arduino這邊有兩個print 如何讓 matlab都讀取。
我是用網路上看到的code下去改的給你參考看看
arduino端:http://felipelang.webs.com/codes/aquisitaSomente.c
matlab端:http://felipelang.webs.com/codes/aquisitaSomente.m

萬分感謝你
7#
發表於 2012-3-20 21:52:58 | 只看該作者
本帖最後由 LCW 於 2012-3-20 22:03 編輯

回復 6# iwanturass

Hi

如果你想要抓資料進 Matlab 做分析,在下在提供另一種方法,

你可以將資料 Serial.print 出來之後,利用終端機連線工具,

(可參考Cooper Maa前輩的Tera Term簡介)這個程式能設定當

COM Port 開啟所有資料都會存成 *.log檔
(可參考如何把Arduino丟出來的資料存成檔案?)

寫個 Matlab 開檔&讀檔的程式,需注意資料的格式再分析畫圖。


這個方式可能沒有直接開啟 COM Port 來讀資料那麼直接也可能沒那麼即時,

但是應該是不會出什麼大問題。

在下目前是用這種方式抓加速度規的資料再畫圖...
8#
 樓主| 發表於 2012-3-29 15:57:39 | 只看該作者
LCW大 感謝你 我努力寫看看Matlab 開檔&讀檔的程式 如果遇到困難可能再麻煩妳了 萬分感謝
log檔我有順利產生沒問題
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-6-1 13:10 , Processed in 0.122079 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表