graycatlabs / PyBBIO

A Python library for Arduino-style hardware IO support on the Beaglebone
https://github.com/graycatlabs/PyBBIO/wiki
MIT License
251 stars 87 forks source link

AnalogRead broken on Beaglebone Black #26

Closed dn-hx closed 10 years ago

dn-hx commented 11 years ago

Hello, although I'm very impressed by your library and think its really great I'm having an issue with analogRead on my BBB. Althoug AIN5 pulled to GND this is what I read with your library

AIN0 [P9.39] - 3138 AIN1 [P9.40] - 124 AIN2 [P9.37] - 2987 AIN3 [P9.38] - 188 AIN4 [P9.35] - 3132 AIN5 [P9.36] - 169 AIN6 [P9.33] - 3254 AIN7 [P9.39] - 233

If I do this read multiple time the value switch between the AINs so it seems there is an issue with waiting or syncing the ADC clock with the read.

If I read AIN5 with the adafruitBBIO library which instead of yours just uses on the filesystem AIN read (like with cat /sys/devices/ocp....) which is in my opinion a much worse way of doing this i get:

root@beaglebone:~/AdafruitBBIO# python aread.py ADC AIN5 voltage: 0.001000v

which is exactly what I expected.

I really would appreciate it if there was a fix for this. If you need some more information or testing just let me know!

alexanderhiam commented 11 years ago

Currently only GPIO is working on the BeagleBone Black. Because the kernel has had much more control over the IO peripherals since 3.8, it's not as trivial to read and write directly to the memory registers for anything other than the GPIO modules. I'm not sure there's any alternative to using the filesystem drivers for the ADC, but I'm still looking into it.

alexanderhiam commented 10 years ago

analogRead() should be working now on the BeagleBone Black. It's currently interfacing to the sysfs kernel driver which outputs in millivolts, so instead of the 12-bit ADC value it returns an integer of the mV.