Trouble with hardware sampling and data grabbing

Hey guys, I’ve been playing around for a few days and reading through some of the other posts trying to find a good way to accomplish this. I’ve kind of been striking out of luck, mostly because I’m getting strange numbers for my adc reading.

My goal, I’d like to be able to sample pins, using the hardware sampler and be able to read individual values from the buffers. I think I’m sampling correctly:
buffer_1 <- blob(200); buffer_2 <- blob(200); hardware.sampler.configure(hardware.pin2, 50, [buffer_1, buffer_2], DataReady );

This samples .pin2 and puts it into buffer_1, once that is full fills up buffer_2.
for multiple pins it does the same thing but alternating between the two, or three.

My problem lies when I go to read the buffer values in DataReady, or after I send to agent.

I pulled the stock one off the website to play with and that all works fine, but when it comes to looking at individual values in the buffer I get really weird results, which half the time aren’t even letters or numbers. I’d like the results to display from 3.3V - 0V.

Here’s my coding including my bunch of server.logs to help me figure out what everything is doing,

CODE:
`
function DataReady(buffer, length)
{
local output = blob(200);
local i;
if (length > 0) {
server.log(“length”);
server.log(length);

    server.log(hardware.pin2.read()*3.3/65536);
    for (i=0;i<length;i+=1)
        {
        output[i] = (buffer[i])*3.3/65536;
        }
        server.log("readn");
        server.log(buffer.readn('w')*3.3/65536);

        server.log("output");
        for (i=0; i<4; i+=1){
        server.log(output[0]);
        }
} 
else {
    server.log("Overrun");
}

}
`

LOGS:
2014-05-13 14:14:00 UTC-6 [Device] length 2014-05-13 14:14:00 UTC-6 [Device] 200 2014-05-13 14:14:00 UTC-6 [Device] 2.032338 2014-05-13 14:14:00 UTC-6 [Device] readn 2014-05-13 14:14:00 UTC-6 [Device] 2.040395 2014-05-13 14:14:00 UTC-6 [Device] output 2014-05-13 14:14:00 UTC-6 [Device] 0 2014-05-13 14:14:00 UTC-6 [Device] 0 2014-05-13 14:14:00 UTC-6 [Device] 0 2014-05-13 14:14:00 UTC-6 [Device] 0 2014-05-13 14:14:02 UTC-6 [Device] length 2014-05-13 14:14:02 UTC-6 [Device] 200 2014-05-13 14:14:02 UTC-6 [Device] 2.040395 2014-05-13 14:14:02 UTC-6 [Device] readn 2014-05-13 14:14:02 UTC-6 [Device] 2.034755 2014-05-13 14:14:02 UTC-6 [Device] output 2014-05-13 14:14:02 UTC-6 [Device] 0 2014-05-13 14:14:02 UTC-6 [Device] 0 2014-05-13 14:14:02 UTC-6 [Device] 0 2014-05-13 14:14:02 UTC-6 [Device] 0 2014-05-13 14:14:02 UTC-6 [Device] done sampling 2014-05-13 14:14:02 UTC-6 [Device] Overrun

For this test I used a straight DC input of 2V into pin two, in the future though it won’t be a DC input and I’ll need to access individual samples. Any ideas on how to be able to access and read these buffer values ?

PS. Sorry I’m a n00b. :slight_smile:

Can you fix up your code using code tags? It’s missing some bytes due to the “<” being interpreted as HTML (press the “c” button above the editor text field, paste code)