Arduino serial connection reading in data only until buffer is full
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Walter Roberson
on 18 Jun 2015
inbytes = char(fread(s, 512));
and then you can sscanf on inbytes to extract the printable data.
0 Comments
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!