About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

How to use continuous sampling

1310 Views - Created 27/06/2016

27/06/2016

Posted by:
Al Capern

Users Avatar

I have been using the ADC pi+ to collect accelerometer data. I can only achieve 70Hz using a loop with a single read. The specs for the ADC Pi + say that it has continuous sampling @ around 200Hz but I can find no information or code sample to help me implement it. Any advice or pointers to the information would be greatly appreciated.

Cheers

27/06/2016

Posted by:
Al Capern

Users Avatar

27/06/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

If you are using our python libraries then you can set the conversion mode to continuous with the set_conversion_mode(1) function.

bus = i2c_helper.get_smbus()
adc = ADCPi(bus, 0x68, 0x69, 12)
adc.set_conversion_mode(1)

For our C library you set the 5th parameter in the read_voltage() function to 1.

read_voltage(0x68,1, 12, 1, 1));

You will also need to set the sample bit rate to be 12 bit for it to read at 200Hz.

In python on a Raspberry Pi 3 you should be able to get around 250 samples per second when reading from a single channel in 12 bit mode.  Reading from two channels on the same ADC chip, for example channels 1 and 3 will reduce the sample rate to around 170sps as it takes a short amount of time to change channel.    

AB Electronics UK Tech Support

28/06/2016

Posted by:
Al Capern

Users Avatar

Thanks Andrew,

Thanks for the info.  Yes, I tried that. How do you get the data? Do you still take adc.read_voltage() single samples and loop? It takes 28s to take 2000 samples in 12bit mode. It should take about 8s. I'm using a pi 2.  I thought you would be able to collect continuous samples and sleep for say 10s similar to how you do video with the pi camera.

28/06/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

To read the samples you need to put the adc.read_voltage() inside a loop as each call to the adc.read_voltage() function will return one sample.

I have written a knowledgebase article on the different sample rates on the ADC Pi Plus.  It includes some python code which you should be able to run to test your board.

If you need to record samples and do other processing at the same time then you will probably need to write a threaded application and have the adc sampling in a different thread to the rest of the application.

AB Electronics UK Tech Support

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.