element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
BeagleBoard
  • Products
  • Dev Tools
  • Single-Board Computers
  • BeagleBoard
  • More
  • Cancel
BeagleBoard
Forum Accessing GPIO and PWM on BeagleBone AI
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join BeagleBoard to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 36 replies
  • Answers 21 answers
  • Subscribers 104 subscribers
  • Views 8087 views
  • Users 0 members are here
  • beaglebone ai
Related

Accessing GPIO and PWM on BeagleBone AI

Sean_Miller
Sean_Miller over 5 years ago

I'm running through the BeagleBone examples for the AI, but the ones that attempt to read or write to pins throw errors in both Python and bonescript.

 

Here is the output from analoginout.js:

 

Hit ^C to stop

info: No pinmux for P9_14

fs.js:733

  var r = binding.read(fd, buffer, offset, length, position);

                 ^

Error: ETIMEDOUT: connection timed out, read

    at Error (native)

    at Object.fs.readSync (fs.js:733:19)

    at tryReadSync (fs.js:488:20)

    at Object.fs.readFileSync (fs.js:528:19)

    at Object.readAIN (/usr/local/lib/node_modules/bonescript/src/hw_mainline.js:287:30)

    at Object.f.analogRead (/usr/local/lib/node_modules/bonescript/src/index.js:330:19)

    at Timeout.loop [as _onTimeout] (/var/lib/cloud9/BeagleBone/AI/analogInOut.js:23:19)

    at ontimeout (timers.js:386:11)

    at tryOnTimeout (timers.js:250:5)

    at Timer.listOnTimeout (timers.js:214:5)

 

Is there a config I need to do first?  I see other's in the world with this issue on older BeagleBone's and the responses vary considerably.

 

This is the code:

const b = require('bonescript');


const inputPin  = "A3";
const outputPin = "P9_14";


console.log('Hit ^C to stop');
b.pinMode(outputPin, b.ANALOG_OUTPUT);
setTimeout(loop, 200);  // work-around to wait for PWM permissions


function loop() {
    var value = b.analogRead(inputPin);
    process.stdout.write(inputPin + '-->' + outputPin + ': ' + (value*100).toFixed(1) + '%   \r');
    b.analogWrite(outputPin, value);
    setTimeout(loop, 10);
}

 

Thanks,

Sean

  • Sign in to reply
  • Cancel

Top Replies

  • Sean_Miller
    Sean_Miller over 5 years ago in reply to Sean_Miller +4
    YYYYYEEEEEAAA!!!!!!!! blinkLED.js works now!!! I always tell the boy...if you can blink an LED, you can change the world. The door is open! See ya', Sean
  • Sean_Miller
    Sean_Miller over 5 years ago in reply to clem57 +2 suggested
    I saw these two references tonight in my hunt. My thoughts were "this surely is handled in by the bonescript and Python libraries on the fly, right?" "Otherwise, it would be in the comments in the header…
  • mayermakes
    mayermakes over 5 years ago in reply to clem57 +2 suggested
    The only thing I could find out about this issue is that the device tree files for the BB-AI are missing, there is currently no suitable file provided for the BB-AI all the BBB black files just brick the…
  • clem57
    0 clem57 over 5 years ago

    Yes since the number of pins is less than possible interfaces...

    https://www.bing.com/videos/search?q=how+to+setup+pins+beagle+bone&docid=608009253376952439&mid=30773886A1337BD47A863077…

     

    Or a better read https://vadl.github.io/beagleboneblack/2016/07/29/setting-up-bbb-gpio .

    Enjoying the BB-AI Sean_Miller ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • clem57
    0 clem57 over 5 years ago

    https://groups.google.com/forum/#!topic/beagleboard/mFTpBYv5PNI is same problem!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Sean_Miller
    0 Sean_Miller over 5 years ago in reply to clem57

    I saw these two references tonight in my hunt.  My thoughts were "this surely is handled in by the bonescript and Python libraries on the fly, right?"  "Otherwise, it would be in the comments in the header, right?"  I guess not.

     

    For the video, I didn't have the directories he showed for the capes and trees.

     

    I tried the redirect to export tricks, but still received the same error of having no pinmux.

     

    I'll run it harder through the paces tomorrow evening.  I found the tutorials just aren't out there like you find for Raspberry Pi and Arduino IDE driven microcontrollers.

     

    But, so, far, I love the idea of computations happening at the speed of the frame with the tidl libraries, love the Cloud 9 interface (1st time using it), and love being able to use it as an adhoc device while its connected to the internet.

     

    Just got to get an LED to blink and stop it from calling my black cat a ping-pong-ball.  image

     

    -Sean

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • clem57
    0 clem57 over 5 years ago in reply to Sean_Miller

    Just got to get an LED to blink and stop it from calling my black cat a ping-pong-ball.  image

     

    LMAO

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 5 years ago

    #include <unistd.h>

    #include <stdio.h>

    using namespace std;

     

     

    int main()

    {

       FILE *export_file = NULL; //declare pointers

       FILE *IO_direction = NULL;

       FILE *IO_value = NULL;

       char str1[] = "0";

       char str2[] = "1";

       char str3[] = "out";

       char str[] = "23";

       //this part here exports gpio23

       export_file = fopen ("/sys/class/gpio/export", "w");

       fwrite (str, 1, sizeof(str), export_file);

       fclose (export_file);

       //this part here sets the direction of the pin

       IO_direction = fopen("/sys/class/gpio/gpio23/direction", "w");

       fwrite(str3, 1, sizeof(str3), IO_direction); //set the pin to HIGH

       fclose(IO_direction);

       usleep (1000000);

     

       for (int i=0; i<10; i++){ //blink LED 10 times

            IO_value = fopen ("/sys/class/gpio/gpio23/value", "w");

            fwrite (str2, 1, sizeof(str2), IO_value); //set the pin to HIGH

            fclose (IO_value);

            usleep (1000000); //delay for a second

     

     

            IO_value = fopen ("/sys/class/gpio/gpio23/value", "w");

            fwrite (str1, 1, sizeof(str1), IO_value); //set the pin to LOW

            fclose (IO_value);

            usleep (1000000); //delay for a second

            }

    }

     

    The 3 bold lines are the setup for pin 23.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • mayermakes
    0 mayermakes over 5 years ago in reply to clem57

    The only thing I could find out about this issue is that the device tree files for the BB-AI are missing, there is currently no suitable file provided for the BB-AI
    all the BBB black files just brick the BB-Ai if loaded with uENv.txt. the Universal cape also does not support the processor.
    I raised an Issue on the github for the examples and messaged them,. hope Beaglebone will shortly provide a suitable overlay file /inlcuded it loaded in the next OS image release.

    thanks for posting your solution!

    For generall usage these setup procedures should be handeled in a Library or the u-boot (like intended).
    To get an urgent project working i had to do some workaround which thought me about interfacing it with USB devices, but I really would like to redo it without any additional hardware.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • mp2100
    0 mp2100 over 5 years ago

    Sean, I am definitely not a nodejs expert, but I compared your code to the example from cloud9 on my BBBlack (I don't yet have a BB AI).  In the given example, the first 3 lines read:

       var b = require('bonescript');

       var inputPin = "P9_38";

       var outputPin = "P9_14";

     

    Your code reads:

    1. const b = require('bonescript');
    2. const inputPin  = "A3";
    3. const outputPin = "P9_14";

     

    Is there a reason you used constant instead of variable?

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Sean_Miller
    0 Sean_Miller over 5 years ago in reply to mp2100

    My code came from the example code found in the Cloud9 IDE under cloud9-->BeagleBone--AI which is on the BeagleBone GitHub as well.

     

    https://github.com/beagleboard/cloud9-examples/tree/master/BeagleBone/AI

     

     

    As for const versus var, in general, I do prefer const for a variable I don't want to mistakenly change its value, as in this case.  I want to set it and fix it to that pin for all references.

     

    See ya',

    Sean

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Sean_Miller
    0 Sean_Miller over 5 years ago in reply to clem57

    Thanks for posting.

     

    Another file/shell based BoneScript workaround was in that post you sent as well:

    /*------------------------------------------------------------------------------------
    function to export a gpio Pin
        Parameter : the pin that you want to export  
    */
    function gpio_export(pin)
    {
        
        var path_export=path+"/export"; // export path
    
        //method where we execute the shell command
    
         var command = "echo "+pin.toString()+" > "+path_export //the shell command that want to do
        
         //execution of the command
           process.exec(command,function (err,stdout,stderr) {
                //if there is some error print them
                if (err) {
                    console.log("\n"+stderr);
                } else {
                    console.log(stdout);
                }
            });
    
    }

     

    But, this makes for a negative demo if I blog and make a video on it.  Someone on the fence on going to BeagleBone could get turned off immediately.  Ping-pong-ball and I are gonna keep digging in hopes find the magic.

     

    image

     

     

    -Sean

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Sean_Miller
    0 Sean_Miller over 5 years ago in reply to mayermakes

    I got excited when I read this article on Adafruit:  https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/overview

     

    But then I read your post that the BeagleBone Black overlays will brick the AI.

     

    Oh well, at least I understand it now, just not enough to make my own overlay.

     

    See ya',

    Sean

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube