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

analogRead does not work on Beaglebone Black #39

Closed
weboide opened this issue May 24, 2013 · 7 comments
Closed

analogRead does not work on Beaglebone Black #39

weboide opened this issue May 24, 2013 · 7 comments
Assignees

Comments

@weboide
Copy link

weboide commented May 24, 2013

On a beaglebone black, the default bonescript installed through opkg (or even pulled from github) does not support reading using analogRead
It fails with file not found "undefined/AIN3". Also, the beaglebone black does not need any value scaling, since the ADC returns raw voltage directly (in millivolts).

The patch below seems to fix the problem.

Package: bonescript
Version: 1.0-r21.3
Linux beaglebone 3.8.11 #1 SMP Wed May 8 07:34:27 CEST 2013 armv7l GNU/Linux

diff --git a/node_modules/bonescript/index.js b/node_modules/bonescript/index.js
index e762e47..947521f 100644
--- a/node_modules/bonescript/index.js
+++ b/node_modules/bonescript/index.js
@@ -366,7 +366,7 @@ f.analogRead = function(pin, callback) {
     pin = getpin(pin);
     if(typeof this.ainPrefix == 'undefined') {
         if(load_dt('cape-bone-iio')) {
-            var helper = file_find('/sys/module/bone_iio_helper/drivers/platform:bone-iio-helper', 'helper.', 10000);
+            var helper = file_find('/sys/devices/ocp.2', 'helper.', 10000);
             this.ainPrefix = helper + '/AIN';
             this.indexOffset = 0;
             this.scale = 1800;
@@ -397,7 +397,8 @@ f.analogRead = function(pin, callback) {
         delete this.ainPrefix;
         throw('analogRead(' + pin.key + ') returned ' + data);
     }
-    data = data / scale;
+    if(f.getPlatform().name == 'Beaglebone')
+        data = data / scale;
     if(isNaN(data)) {
         delete this.ainPrefix;
         throw('analogRead(' + pin.key + ') scaled to ' + data);
@paulrichards19
Copy link

I've just tried this fix and it appears to work.

Why not create a pull request for this bug fix? It hard to imagine though why this is broken, maybe its just for some certain versions of the BBB. Surely it would be fixed already if it was broken for everyone.

@weboide
Copy link
Author

weboide commented Jun 12, 2013

I may do a pull request, but first I'm not sure if I have a good enough understanding of the BB or bonescript itself, and second I would need to make sure my fix is accurate and still allows bonescript to function properly on the Beaglebone White.
That's why I decided about just posting it here in the first place.

@ghost
Copy link

ghost commented Jun 13, 2013

It would be nice if someone that was currently working on developing the BBB could respond to the question about "how broken" things are. Am I one of the few or one of the many with this not working? Things work with an earlier image but not the more current ones. I was hoping the 6-6 image would have fixed this but alas no luck. Cheers, Wisar

@ghost ghost assigned jadonk Jun 18, 2013
@jadonk
Copy link
Owner

jadonk commented Jun 18, 2013

I'm working on my first update since the 4.13 image right now and attempting to incorporate fixes for any outstanding issues. The fix mentioned here cannot work because BeagleBone can also run the newer software. A test for what the kernel shares is more appropriate to determine which driver is being used and thus what scale is being used. If the latest version on the git tree still fails for you, please let me know. Version should report 0.2.2 if you have the latest.

@jadonk
Copy link
Owner

jadonk commented Jun 18, 2013

The latest code is working for me on the 06.17 candidate image, though I'm still manually updating the BoneScript files. I'm going to close this for now. If you see the issue on an image newer than 06.17, please re-open or open a new issue.

@jadonk jadonk closed this as completed Jun 18, 2013
@weboide
Copy link
Author

weboide commented Jun 18, 2013

jadonk, note that scaling may still need to be disabled on newer kernels or BBB. I'm not sure if it's BBB or the kernel that has a different setting, but the BBB with the latest angstrom reports the actual voltage in mV (1800 mV max), so there is no need to scale the returned value.

@ghost
Copy link

ghost commented Jun 19, 2013

Thanks, that is good news.   Any idea on when a post 6-17 image will be available for my flashing pleasure?

Cheers, Will


From: Jason Kridner notifications@github.com
To: jadonk/bonescript bonescript@noreply.github.com
Cc: Will Kostelecky willkostelecky@yahoo.com
Sent: Tuesday, June 18, 2013 6:36 PM
Subject: Re: [bonescript] analogRead does not work on Beaglebone Black (#39)

The latest code is working for me on the 06.17 candidate image, though I'm still manually updating the BoneScript files. I'm going to close this for now. If you see the issue on an image newer than 06.17, please re-open or open a new issue.

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