Read COM port data continuously and update output variable in workspace from Raspberry pi
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Raspberry Pi Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!