how to control beaglebone gpio pins

16,173

Here is a tutorial on using c++ to control the LEDs: http://derekmolloy.ie/beaglebone-controlling-the-on-board-leds-using-c/

Halfway down the page is the C++ code. Take this implementation, but instead of writing to the LED device files, write the appropriate information to the GPIO device files, like in this manual:

http://elinux.org/images/3/33/GPIO_Programming_on_the_Beaglebone.pdf

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main(){
   std::fstream fs;

   fs.open("/sys/kernel/debug/omap_mux/gpmc_ad4");
   fs << "7";
   fs.close();
   fs.open("/sys/class/gpio/export");
   fs << "32";
   fs.close();
   fs.open("/sys/class/gpio/gpio32/direction");
   fs << "out";
   fs.close();
   fs.open("/sys/class/gpio/gpio32/value");
   fs << "1"; // "0" for off
   fs.close();
   // select whether it is on, off or flash

   return 0;
}
Share:
16,173
Admin
Author by

Admin

Updated on June 07, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm trying to make a program for beaglebone to let me control the gpio pins. I tried to use sprintf() but doesn't accept input as I know.

    I have to re-write couple files in the beaglebone like

    gpio export active the pin gpio gpio$pin/direction pin mode in/out gpio gpio$pin/value pin value 1/0

    guys..!! just need a idea how to accomplish my goal.

    I'm newbie in c++. any information or comment I'll appreciated thks guys for your time.

  • Rufus
    Rufus over 5 years
    As per here, current version of Beaglebone Black do not use omap_mux. This instruction will not work for newer BBBs
  • Rufus
    Rufus over 5 years
    Refer to this question for configuring pin modes