Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIN read performance issue #29

Closed
Sanerix opened this issue Jan 31, 2014 · 7 comments
Closed

AIN read performance issue #29

Sanerix opened this issue Jan 31, 2014 · 7 comments

Comments

@Sanerix
Copy link

Sanerix commented Jan 31, 2014

I have wrote a small program to read as many requests as possible from AIN0:

from bbio import *
import time

bbio.bbio_init()

i = 0
j = 0
end = time.time() + 1
while time.time() < end:
x = analogRead(AIN0)
if x > 0:
i=i+1
else:
j=j+1
print "have read " ,i , " times in a second with ",j," failed."
bbio.bbio_cleanup()

I get the following output:

root@beaglebone:/python# python readAIN1_PyBBIO.py
have read 307 times in a second with 0 failed.
root@beaglebone:
/python# python readAIN1_PyBBIO.py
have read 320 times in a second with 0 failed.
root@beaglebone:/python# python readAIN1_PyBBIO.py
have read 313 times in a second with 0 failed.
root@beaglebone:
/python# python readAIN1_PyBBIO.py
have read 318 times in a second with 0 failed.
root@beaglebone:/python# python readAIN1_PyBBIO.py
have read 320 times in a second with 0 failed.
root@beaglebone:
/python# python readAIN1_PyBBIO.py
have read 317 times in a second with 0 failed.
root@beaglebone:/python# python readAIN1_PyBBIO.py
have read 318 times in a second with 0 failed.
root@beaglebone:
/python# python readAIN1_PyBBIO.py
have read 317 times in a second with 0 failed.
root@beaglebone:~/python# python readAIN1_console.py

when I do the same on Adafruit library, I get

import Adafruit_BBIO.ADC as ADC
import time

ADC.setup()
i = 0
j = 0
end = time.time() + 1
while time.time() < end:
x = ADC.read("AIN1")
if x > 0:
i=i+1
else:
j=j+1
print "have read " ,i , " times in a second with ",j," failed."

root@beaglebone:/python# ./readAIN1_console.py
have read 818 times in a second with 0 failed.
root@beaglebone:
/python# ./readAIN1_console.py
have read 822 times in a second with 0 failed.
root@beaglebone:/python# ./readAIN1_console.py
have read 820 times in a second with 0 failed.
root@beaglebone:
/python# ./readAIN1_console.py
have read 825 times in a second with 0 failed.
root@beaglebone:~/python# ./readAIN1_console.py
have read 820 times in a second with 0 failed.

So, I figured that you read from sysfs, are you still having plans for reading AIN0 from memory? Is there any way to get more reads per second?

@alexanderhiam
Copy link
Member

Thanks, that's good info. Both PyBBIO and Adafruit_BBIO are using the sysfs drivers. The difference is that Adafruit is using a C extension to do the file I/O, where as PyBBIO is currently doing file I/O straight from Python. I did it that way because it was the quickest way to get the ADC working, but I am planning on moving more of the IO to C extensions as I find the time.

I suppose it would still be possible to directly control the ADC the way I was on earlier kernels, but the problem is it then wouldn't be compatible with any overlays that use the ADC, because the iio driver would just reconfigure it. One of my goals is to make PyBBIO as cape compatible as possible, so it has to be able to work along side the iio driver. I'm still looking into how best to do this.

@Sanerix
Copy link
Author

Sanerix commented Jan 31, 2014

In new kernels there is now a fix for AM335x_ADC_Driver that provides continuous sampling support
link: http://thread.gmane.org/gmane.linux.kernel.input/32024
blog: http://beagleboard-gsoc13.blogspot.nl/2013/09/success-at-last.html

Would be awesome to have same functionality in python. May be worth to consider?

@alexanderhiam
Copy link
Member

Thanks for pointing that out. It would definitely be cool to support continuous mode in PyBBIO to get some faster sampling, perhaps even combined with epoll to fire a callback after every sample. I definitely want to get the normal ADC reads faster first though.

@alexanderhiam
Copy link
Member

I'm closing this issue as I'm not planning on changing the way analogRead() works any time soon.

@ghost
Copy link

ghost commented Apr 6, 2015

Where can i find 'adafruit_bbio.adc'; i was interested to know the definitions of 'adc.read', 'adc.read_raw'

@deepakkarki
Copy link
Contributor

This is the wrong repository.
You are looking for adafruit.bbio and not PyBBIO

@ghost
Copy link

ghost commented Apr 6, 2015

Ok.. Problem was solved.. Thanks

-----Original Message-----
From: "Deepak Karki" notifications@github.com
Sent: ‎06-‎04-‎2015 15:13
To: "graycatlabs/PyBBIO" PyBBIO@noreply.github.com
Cc: "Advanta09" advaitjavadekar@gmail.com
Subject: Re: [PyBBIO] AIN read performance issue (#29)

This is the wrong repository.
You are looking for adafruit.bbio and not PyBBIO

Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants