Read COM port data continuously and update output variable in workspace from Raspberry pi
1 次查看(过去 30 天)
显示 更早的评论
s = serial('COM5');
s.BytesAvailableFcnMode = 'terminator';
s.BytesAvailableFcnCount = 8;
s.BytesAvailableFcn = {@serialdata};
fopen(s);
function serialdata(obj,event)
while obj.BytesAvailable == 8
out = fscanf(s,'%f',4);
end
fclose(s)
end
I am trying to continuously read data from my raspberry pi via a USB TTL interface. The data is merely a float variable stored as a string. I have checked and confirmed that data is being transmitted to the laptop via COM5 using the Putty terminal. However, i am having difficulty with reading and storing the same data on matlab. The data gets sent every 0.05s from raspberry pi. I've tried using two different encoding formats, utf-8 and ASCII. The number of bytes being sent by my pi is 8 together with an additional stop-bit.
Ideally, i wish to read the data and store it as soon as i receive it, and reset the buffer when it becomes full.
P.S: i have tried reading the Matlab documentation on the use of callback functions etc, but still unable to get my head around it. Any help will be greatly appreciated!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Raspberry Pi Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!