serial communication data shifted

2 views (last 30 days)
isra
isra on 26 Jan 2017
Commented: isra on 26 Jan 2017
Hello I'm trying to read analog inputs from arduino and send them to matlab, My problem is that sometimes the data is shifted. I'm erading several analog inputs. When I plot the second input's data, I sometimes get the data from input 1, then I find input 2's data in the plot of input 3. There seem to be a synchronization issue, how can I fix it?

Answers (1)

Walter Roberson
Walter Roberson on 26 Jan 2017
I suggest you debug this by sending the sensor number and the current sample count along with the sensor reading. This will allow you to see whether the data is all being transmitted but sometimes out of order, or if the problem is that entire chunks of data are being missed.
  2 Comments
isra
isra on 26 Jan 2017
Yes I did this, I made Arduino print out the number of the pin before printing it's data (i.e printe "1" then A0's output each in a line). Then in matlab, it will read the first raw then according to it's value (1,2,,4) it will save the next reading in the corresponding vector. This seems to be the only way around it, I still have to realtime plot it so I'll have to see if it will work with it or not. Thanks
isra
isra on 26 Jan 2017
I've tried plotting the data, I have a problem with it, it seems to display the readings for a certain time only (700 samples) then after that I get random lines. Do you have any idea as to why this happens? I'm supplying my board with a continuous sine wave.

Sign in to comment.

Categories

Find more on Data Acquisition Toolbox Supported 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!