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 & Tria 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 105 subscribers
  • Views 8369 views
  • Users 0 members are here
  • beaglebone ai
Related

Accessing GPIO and PWM on BeagleBone AI

Sean_Miller
Sean_Miller over 6 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 6 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 6 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 6 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…
Parents
  • Sean_Miller
    0 Sean_Miller over 6 years ago

    Here's a hack for Python on the BBAI.

     

    Change...

     

    out = "P9_15"

    to

    out = "P8_39"

     

    in the blink demo and you'll get an LED blink.  It's because of the mapping difference between the BBB and BBAI.

     

    See ya',

    Sean

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

    And another pin hack for the BBAI for Adafruit's Python Library BBB pins:

     

    out = "P8_13" #actually 8_22 on BBAI

     

    Here's how I'm finding it...

    • At the terminal type:
      • node -pe "require('bonescript').bone.getPinObject('p8.22').ai.gpio"
    • It will give you a number.  In this case it returns 23.
    • Do a CTRL f on the number here:  https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/common.c#L73
    • For this one, I found { "EHRPWM2B", "P8_13", 23, 4, -1} - which is P8_13.

     

    So, using BBB's reference to P8_13 will get you use of BBAI 8_22.

     

    Two out pins are much better than none for now.  Now to get an analog in and a PWM out working.  Most likely, as soon as I get it, Adafruit will release their update.  image

     

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

    And this makes perfect sense. The new Sitera for the BB-AI has pins at new places on the board versus the old Sitera.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jomoenginer
    0 jomoenginer over 6 years ago in reply to Sean_Miller

    Again, your "node -pe "require('bonescript').bone.getPinObject('p8.22').ai.gpio"" command came from a Jason post regarding an issue with the node.js lib.

     

    The bonescript gave you 23 since P8_22 on a BB AI is mapped to gpio1_23 thus it is like ((32x0) +23) = gpio 23.

     

    Also, by default, the unused pins tend to be set to a default that seems to set it to the GPIO mode, mode 14. To set the pin to PWM, it would need to be set to Mode 10 to enable ehrpwm3B.

     

    Jason sent out a table but this is listed in the TI AM572x Data sheet as well:

    http://www.ti.com/lit/ds/symlink/am5728.pdf

     

    To make this change, from what I gather from Robert, the pin would need to be set to the following in the am5729-beagleboneai.dts

    Ex:

    DRA7XX_CORE_IOPAD(0x3794, PIN_OUTPUT | MUX_MODE10) /* AC8: P8.23: mmc3_dat4.ehrpwm3A - PWM3A */

     

    Changes to the .dts require a rebuild of the dtb:

    cd /opt/source/dtb-4.19-ti/
    make src/arm/am5729-beagleboneai.dtb 
    sudo make install
    sudo reboot

     

     

    NOTE: The pin will not work as normal GPIO output at this point.

     

    Since the Adafruit stuff is not really working with the BB AI, I'm still looking for an example to test the PWM capability.

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

    Good stuff.

     

    When I tried altering the .dts earlier this week, it unfortunately bricked my SD card.  But, I had the 4.14x kernal I believe.  Did you have success with the .dts changes above with 4.19?

     

    I'll try again this evening once I get back from work and see if the BoneScript beta library will work with it.

     

    Thanks,

    Sean

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jomoenginer
    0 jomoenginer over 6 years ago in reply to Sean_Miller

    It should work with either kernel, but I have only used 4.19.  I have done all of the latest updates and pulled in the latest code changes as well. 

     

    After changing the pin mode, the analogInOut.js example no longer works so I suspect I am still missing something. It does sort of work with the pin as a GPIO, but only as an on or off state and does not fade the LED.

     

    However, 4.19 seems to break the TIDL example where it will not build anymore and the blinkLED.js example causes the system to become nearly unresponsive.

     

    Another thing I found with the Cloud9 examples is that you need to set the gpio port before running the scripts.

    Ex for P8_23 set as GPIO (Mode 14):

    echo 22 > /sys/class/gpio/export 
    echo out > /sys/class/gpio/gpio22/direction

     

    I also removed the other led  except usr3 since I still want to see the heartbeat on the board.

    .

    const leds = ["USR3", "P8_23"];
    //const leds = ["USR0", "USR1", "USR2", "USR3", "P9_15"];

     

    The board does not seem to become unresponsive after running the example this way.

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

    okay...back at it again...

     

    I reverted back to 4.14 and got the classification.cpp to process again as you said.  It's much more responsive since they fixed the bug. It could use some training, but at least it processes fast and doesn't call my cat a ping pong ball anymore - although it did say coffee mug twice.

     

    At line 310, you can tap into the frame to do your own overlay.  Originally, it would put text on the frame if it just saw an object.  Below, I added an "else" so when it doesn't detect an object, the user gets validation that its at least trying:

     

    if(is_object >= 0)  //excerpt from cloud9/BeagleBone/AI/tidl/classification.cpp
        {
            cv::putText(
                dst,
                (*(labels_classes[is_object])).c_str(),
                cv::Point(15, 60),
                cv::FONT_HERSHEY_SIMPLEX,
                1.5,
                cv::Scalar(0,255,0),
                3,  /* thickness */
                8
            );
        } 
        //new code is below that allows for a constant message or tweaking as you see fit.
        else
        {
            char my_message[]="Searching...";
            cv::putText(
                dst,
                my_message,
                cv::Point(30, 60),
                cv::FONT_HERSHEY_SIMPLEX,
                1.5,
                cv::Scalar(0,255,0),
                3,  /* thickness */
                8
            );
        }
        //end of new code
       

    image

     

     

    Back to trying to get a pin to input.  I'm getting the following error with input even though I've set permissons on the files it thinks are missing:

    ValueError: Set gpio mode failed, missing file or invalid permissions

     

    -Sean

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • Sean_Miller
    0 Sean_Miller over 6 years ago in reply to jomoenginer

    okay...back at it again...

     

    I reverted back to 4.14 and got the classification.cpp to process again as you said.  It's much more responsive since they fixed the bug. It could use some training, but at least it processes fast and doesn't call my cat a ping pong ball anymore - although it did say coffee mug twice.

     

    At line 310, you can tap into the frame to do your own overlay.  Originally, it would put text on the frame if it just saw an object.  Below, I added an "else" so when it doesn't detect an object, the user gets validation that its at least trying:

     

    if(is_object >= 0)  //excerpt from cloud9/BeagleBone/AI/tidl/classification.cpp
        {
            cv::putText(
                dst,
                (*(labels_classes[is_object])).c_str(),
                cv::Point(15, 60),
                cv::FONT_HERSHEY_SIMPLEX,
                1.5,
                cv::Scalar(0,255,0),
                3,  /* thickness */
                8
            );
        } 
        //new code is below that allows for a constant message or tweaking as you see fit.
        else
        {
            char my_message[]="Searching...";
            cv::putText(
                dst,
                my_message,
                cv::Point(30, 60),
                cv::FONT_HERSHEY_SIMPLEX,
                1.5,
                cv::Scalar(0,255,0),
                3,  /* thickness */
                8
            );
        }
        //end of new code
       

    image

     

     

    Back to trying to get a pin to input.  I'm getting the following error with input even though I've set permissons on the files it thinks are missing:

    ValueError: Set gpio mode failed, missing file or invalid permissions

     

    -Sean

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
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