Azzera filtri
Azzera filtri

Read COM port data continuously and update output variable in workspace from Raspberry pi

1 visualizzazione (ultimi 30 giorni)
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!

Risposte (0)

Categorie

Scopri di più su MATLAB Support Package for Raspberry Pi Hardware in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by