Arduino serial connection reading in data only until buffer is full
Afficher commentaires plus anciens
I am trying to use an Arduino to read in sensor data into MATLAB and store it. I am using a relatively high baud rate (57600) and the MATLAB buffer keeps filling up, causing small lags in my data. I would like to be able to just read in the data until the buffer is full and then stop. I know you can set the input buffer size but is there any way to open/close the buffer or stop the data collection once I have read in a specific number of bytes? I know I can set the amount of time or number of characters to read in before stopping but I need to be able to specify the number of bytes. For example, I know the default buffer size is 512 bytes, so how would I be able to read in exactly 512 bytes and then stop? I am currently using fscanf to read in the data from the Arduino through a serial port. I haven't had any luck so far and would appreciate some guidance.
Réponses (1)
Walter Roberson
le 18 Juin 2015
inbytes = char(fread(s, 512));
and then you can sscanf on inbytes to extract the printable data.
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!