jadonk / bonescript

Scripting tools for BeagleBone and PocketBeagle
http://beagleboard.org
MIT License
513 stars 159 forks source link

analogRead does not work on Beaglebone Black #39

Closed weboide closed 11 years ago

weboide commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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

jadonk commented 11 years ago

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 commented 11 years ago

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.

weboide commented 11 years ago

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 commented 11 years ago

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.