Following is a handy reference that you can use to control and access your BeagleBones general purpose input/output (GPIOs) with the file system, BoneScript, and Python.
\nYou can use the following commands to control the GPIO with the file system.
\nExporting a pin:
\necho 40 > /sys/class/gpio/export\n
Setting a pin OUTPUT:
\necho out > /sys/class/gpio/gpio40/direction\n
Writing a pin HIGH:
\necho 1 > /sys/class/gpio/gpio40/value\n
Writing a pin LOW:
\necho 0 > /sys/class/gpio/gpio40/value\n
Setting a pin INPUT:
\necho in > /sys/class/gpio/gpio40/direction\n
Reading the value from an INPUT pin (returns 1 for HIGH and 0 for LOW):
\ncat /sys/class/gpio/gpio40/value\n
You can use the following BoneScript commands to control the GPIO.
\nLoading a BoneScript module:
\nvar b = require('bonescript');\n
Setting a pin OUTPUT:
\nb.pinMode(\"P9_14\", b.OUTPUT);\n
Writing a pin HIGH:
\nb.digitalWrite(\"P9_14\", b.HIGH);\n
Writing a pin LOW:
\nb.digitalWrite(\"P9_14\", b.LOW);\n
Setting a pin INPUT:
\nb.pinMode(\"P8_11\", b.INPUT);\n
Reading the value from a digital INPUT pin (returns HIGH or LOW):
\nb.digitalRead(\"P8_11\");\n
Setting a pin for pulse-width modulation (PWM) with 50 percent duty cycle:
\nb.pinMode('P9_14', b.OUTPUT);\nb.analogWrite('P9_14', 0.5);\n
Reading the value from an analog INPUT pin (returns a value between 0 and 1):
\nb.analogRead('P9_40');\n
You can use the following Python commands to control the GPIO.
\nImporting Adafruits BeagleBone Input Output Library:
\nimport Adafruit_BBIO.GPIO as GPIO\n
Setting a pin OUTPUT:
\nGPIO.setup(\"P9_14\", GPIO.OUT)\n
Writing a pin HIGH:
\nGPIO.output(\"P9_14\", GPIO.HIGH)\n
Writing a pin LOW:
\nGPIO.output(\"P9_14\", GPIO.LOW)\n
Setting a pin INPUT:
\nGPIO.setup(\"P8_11\", GPIO.IN)\n
Reading the value from a digital INPUT pin (returns HIGH or LOW):
\nGPIO.input(\"P8_11\")\n
Setting a pin for PWM with 50 percent duty cycle:
\nimport Adafruit_BBIO.PWM as PWM\nPWM.start(\"P9_14\", 50)\n
Setting an analog INPUT:
\nimport Adafruit_BBIO.ADC as ADC\nADC.setup()\n
Reading the value from an analog INPUT pin (returns a value between 0 and 1):
\nanalogReading = ADC.read(\"P9_40\")\n
Following is a handy reference that you can use to control and access your BeagleBones general purpose input/output (GPIOs) with the file system, BoneScript, and Python.
\nYou can use the following commands to control the GPIO with the file system.
\nExporting a pin:
\necho 40 > /sys/class/gpio/export\n
Setting a pin OUTPUT:
\necho out > /sys/class/gpio/gpio40/direction\n
Writing a pin HIGH:
\necho 1 > /sys/class/gpio/gpio40/value\n
Writing a pin LOW:
\necho 0 > /sys/class/gpio/gpio40/value\n
Setting a pin INPUT:
\necho in > /sys/class/gpio/gpio40/direction\n
Reading the value from an INPUT pin (returns 1 for HIGH and 0 for LOW):
\ncat /sys/class/gpio/gpio40/value\n
You can use the following BoneScript commands to control the GPIO.
\nLoading a BoneScript module:
\nvar b = require('bonescript');\n
Setting a pin OUTPUT:
\nb.pinMode(\"P9_14\", b.OUTPUT);\n
Writing a pin HIGH:
\nb.digitalWrite(\"P9_14\", b.HIGH);\n
Writing a pin LOW:
\nb.digitalWrite(\"P9_14\", b.LOW);\n
Setting a pin INPUT:
\nb.pinMode(\"P8_11\", b.INPUT);\n
Reading the value from a digital INPUT pin (returns HIGH or LOW):
\nb.digitalRead(\"P8_11\");\n
Setting a pin for pulse-width modulation (PWM) with 50 percent duty cycle:
\nb.pinMode('P9_14', b.OUTPUT);\nb.analogWrite('P9_14', 0.5);\n
Reading the value from an analog INPUT pin (returns a value between 0 and 1):
\nb.analogRead('P9_40');\n
You can use the following Python commands to control the GPIO.
\nImporting Adafruits BeagleBone Input Output Library:
\nimport Adafruit_BBIO.GPIO as GPIO\n
Setting a pin OUTPUT:
\nGPIO.setup(\"P9_14\", GPIO.OUT)\n
Writing a pin HIGH:
\nGPIO.output(\"P9_14\", GPIO.HIGH)\n
Writing a pin LOW:
\nGPIO.output(\"P9_14\", GPIO.LOW)\n
Setting a pin INPUT:
\nGPIO.setup(\"P8_11\", GPIO.IN)\n
Reading the value from a digital INPUT pin (returns HIGH or LOW):
\nGPIO.input(\"P8_11\")\n
Setting a pin for PWM with 50 percent duty cycle:
\nimport Adafruit_BBIO.PWM as PWM\nPWM.start(\"P9_14\", 50)\n
Setting an analog INPUT:
\nimport Adafruit_BBIO.ADC as ADC\nADC.setup()\n
Reading the value from an analog INPUT pin (returns a value between 0 and 1):
\nanalogReading = ADC.read(\"P9_40\")\n
Brock Craft is a Lecturer in Physical Computing at Goldsmiths, University of London in the Department of Computing. successful message appears. Should I re-do this cinched PEX connection? 4-channel I2C-safe Bi-directional Logic Level Converter, "The master in the art of living makes little distinction between work and play", Setting up IO Python Library on BeagleBone Black, Adafruit 1-Wire Thermocouple Amplifier - MAX31850K, 2.3" Monochrome 128x32 OLED Display Module, 1.5" & 2.4" Monochrome 128x64 OLED Display Module. Here is my test script: import Adafruit_BBIO.GPIO as GPIO import time P = "P8_11" GPIO.setup (P, GPIO.OUT) for i in xrange (100): if i % 2 == 0: GPIO.output (P, GPIO.HIGH) else: GPIO.output (P, GPIO.LOW) time.sleep (0.5) GPIO.cleanup () Thanks -=UPDATED=- It's a bug. bring up a web browser window that allows you to login to your balenaCloud Not sure about this but is . In the example trigger.bas this function gets called synchonously, but when you call it in a thread youll end up with asynchonously event handling. Now that a device online in your fleet, it's time to deploy some code. 0. Navigate to the index.html file present in the static directory of the project. To create a release, use the balena push First-Fleet command replacing Please remember that this subscription will not result in you receiving any e-mail from us about anything other than the restocking of this item. I am Revisiting the BeagleBone Black I havent used it in a long time. 565), Improving the copy in the close modal and post notices - 2023 edition, New blog post from our CEO Prashanth: Community is the future of AI. To setup a digital pin as an output, set the output value HIGH, and then cleanup after you're done: This guide was first published on Jun 13, 2013. To start, you'll want to import the library. python - How to generate sound signal through a GPIO pin on BeagleBone Developing the sample project: making changes and testing them on the device in real-time. There are 2 x 46 pins available (well, not all of them are, but we'll get to that later) to use. Why did US v. Assange skip the court of appeal? These commands will require internet access. This entry is part 4 of 4 in the series Getting Started with BeagleBone Black. Wait for the BeagleBone Black to finish flashing and shutdown. Beaglebone Black 2. The wait_for_edge method is blocking, and will wait until something happens: \"https://sb\" : \"http://b\") + \".scorecardresearch.com/beacon.js\";el.parentNode.insertBefore(s, el);})();\r\n","enabled":true},{"pages":["all"],"location":"footer","script":"\r\n
\r\n","enabled":false},{"pages":["all"],"location":"header","script":"\r\n","enabled":false},{"pages":["article"],"location":"header","script":" ","enabled":true},{"pages":["homepage"],"location":"header","script":"","enabled":true},{"pages":["homepage","article","category","search"],"location":"footer","script":"\r\n\r\n","enabled":true}]}},"pageScriptsLoadedStatus":"success"},"navigationState":{"navigationCollections":[{"collectionId":287568,"title":"BYOB (Be Your Own Boss)","hasSubCategories":false,"url":"/collection/for-the-entry-level-entrepreneur-287568"},{"collectionId":293237,"title":"Be a Rad Dad","hasSubCategories":false,"url":"/collection/be-the-best-dad-293237"},{"collectionId":295890,"title":"Career Shifting","hasSubCategories":false,"url":"/collection/career-shifting-295890"},{"collectionId":294090,"title":"Contemplating the Cosmos","hasSubCategories":false,"url":"/collection/theres-something-about-space-294090"},{"collectionId":287563,"title":"For Those Seeking Peace of Mind","hasSubCategories":false,"url":"/collection/for-those-seeking-peace-of-mind-287563"},{"collectionId":287570,"title":"For the Aspiring Aficionado","hasSubCategories":false,"url":"/collection/for-the-bougielicious-287570"},{"collectionId":291903,"title":"For the Budding Cannabis Enthusiast","hasSubCategories":false,"url":"/collection/for-the-budding-cannabis-enthusiast-291903"},{"collectionId":291934,"title":"For the Exam-Season Crammer","hasSubCategories":false,"url":"/collection/for-the-exam-season-crammer-291934"},{"collectionId":287569,"title":"For the Hopeless Romantic","hasSubCategories":false,"url":"/collection/for-the-hopeless-romantic-287569"},{"collectionId":296450,"title":"For the Spring Term Learner","hasSubCategories":false,"url":"/collection/for-the-spring-term-student-296450"}],"navigationCollectionsLoadedStatus":"success","navigationCategories":{"books":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/books/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/books/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/books/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/books/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/books/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/books/level-0-category-0"}},"articles":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/articles/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/articles/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/articles/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/articles/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/articles/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/articles/level-0-category-0"}}},"navigationCategoriesLoadedStatus":"success"},"searchState":{"searchList":[],"searchStatus":"initial","relatedArticlesList":[],"relatedArticlesStatus":"initial"},"routeState":{"name":"Article4","path":"/article/technology/computers/hardware/beaglebone/how-to-control-beaglebones-gpios-144964/","hash":"","query":{},"params":{"category1":"technology","category2":"computers","category3":"hardware","category4":"beaglebone","article":"how-to-control-beaglebones-gpios-144964"},"fullPath":"/article/technology/computers/hardware/beaglebone/how-to-control-beaglebones-gpios-144964/","meta":{"routeType":"article","breadcrumbInfo":{"suffix":"Articles","baseRoute":"/category/articles"},"prerenderWithAsyncData":true},"from":{"name":null,"path":"/","hash":"","query":{},"params":{},"fullPath":"/","meta":{}}},"dropsState":{"submitEmailResponse":false,"status":"initial"},"sfmcState":{"status":"initial"},"profileState":{"auth":{},"userOptions":{},"status":"success"}}, Comparing BeagleBone Black and Raspberry Pi, How to Connect the BeagleBone Black via Serial over USB.