store data and retrieve
oldhippy
Posts: 36
I have been trying to find a way to store serial data on a BS2 and retrieve it to get the average of the data. Any Suggestions?
Comments
Or are you asking the "how-to" on grabbing a serial stream and stuffing it into memory?
I will try to see what i can do with WRITE AND READ
The wait 75ms to 79ms will depend on how often your samples come along and how important it is to be right on 5 seconds. Whether you sample for 4.8 seconds or 5.3 won’t matter as long as you have 64 samples to divide by 64. Simple, accurate and no memory would be involved.
My disclaimer-- I've never tried this and never worked with a BS2---
Dom..
SERIN <pin>,<Baud code>,[wait("R"),DEC4 sample]
The PUT statement can write a single 16-bit value as two bytes
PUT <address>,WORD sample
After reading 40 samples, your program can go back and process the saved values. You could compute the max and min for the 40 samples "on the fly" as well. Remember that the PUT address has to be an even number since each sample takes two bytes to store.
The DEC modifier waits for decimal digits, so it will bypass the "R" at the start of the string and it will close with the CR at the end of the number. At a sample rate of 6.67 Hz, 32 samples take 4.8 seconds.
I think the DEC modifier by itself can work at 9600 baud. Here there is no WAIT or SKIP modifier in front of the DEC, so no slow call back to the interpreter. It it doesn't work, there is another approach using the STR modifier that definitely will work.
An alternative to a straight average would be a low-pass filter. The Maxbotics sensor itself lowpass filters the streaming data.