# BBB Libpruio Analog Data

Hello! I’m a graduate student working with a BBB trying to collect analog data from some sensors through the onboard PRUs (we need high sampling rate on the order of 20kHz since it’s a frequency based experiment). I’m working with code from previous students that worked on this project and they used Libpruio to accomplish this. Specifically, they are collecting the data using Ring Buffer mode and saving it to a text file to be processed further for some feature extraction and further analysis.

What I’m trying to understand is this: how does Ring Buffer sampling actually work? As in, if I’m reading data using two analog inputs and saving it to a text file, what order are the values in? How do I parse them into meaningful sensor values? I’ve attached the C code I’m working with, and greatly appreciate any help or pointers!

Hello TJF,

Thank you for the explanation that is very useful! With parsing the file, I’m doing that in Node-Red reading in the file as a binary buffer, but for some reason the buffer is 4x the number of sampling points I set. Like let’s say I tell the script to sample the analog inputs 5000 times, the file will come back with 20000 when I read it into Node-Red (I’d expect 10000 points since I’m using 2 analog inputs). What could be the cause?

Thanks!

16 bit = 2 byte!

Parsing the buffer in JavaScript code:

const val = new Uint16Array(Buffer); // val.length = 10000 (2 channels x 5000 samples)

// output raw data: integer from 0 (=0V) to 4095 (=1V8)
console.log(val[0], val[1]); // first samples AIN-1, AIN-2
console.log(val[2], val[3]); // second samples AIN-1, AIN-2

// output voltage: foating point from 0.0 V to 1.8 V
const f = 1.8 / 4095;
console.log(fval[0], fval[1]); // first samples AIN-1, AIN-2
console.log(fval[2], fval[3]); // second samples AIN-1, AIN-2