Logo

dev-resources.site

for different kinds of informations.

Test GPIO pins on BeagleBone Black by toggling high to low

Published at
1/1/2025
Categories
govapemaker
bash
linux
beaglebone
Author
govapemaker
Categories
4 categories in total
govapemaker
open
bash
open
linux
open
beaglebone
open
Author
11 person written this
govapemaker
open
Test GPIO pins on BeagleBone Black by toggling high to low

Tutorial: Testing GPIO Pins on BeagleBone Black Using Bash
This tutorial explains how to write and execute a Bash script to test GPIO pins on the BeagleBone Black. The GPIO (General-Purpose Input/Output) pins are versatile and can be controlled programmatically. Here, we'll guide you step-by-step on using a simple script to toggle a GPIO pin.

Image description

  1. Prerequisites Before starting, ensure the following:

You have access to a BeagleBone Black board.
The board runs a Linux-based operating system.
You have root access (some operations require elevated privileges).
The GPIO pin numbering and mappings for your board are known.

  1. Understanding GPIO Pins GPIO pins are accessible through the Linux filesystem under /sys/class/gpio. Each GPIO pin is represented by a number that you can use to control its state. For example:

P8 Pin 12 corresponds to GPIO1_12, which is 44 in GPIO numbering.
The calculation for GPIO number is:
GPIO Pin = (Bank Number × 32) + Pin Number.
Refer to the BeagleBone Black GPIO Pinout for details.

  1. Script Overview The script performs the following:

Exports a GPIO pin for user control.
Sets the pin direction to output.
Toggles the pin state (HIGH/LOW) three times with 1-second intervals.
Unexports the pin after testing.

  1. The Bash Script Here’s the script:
#!/bin/bash

# Define the GPIO pin to test
# Examples of GPIO numbers:
# P8 Pin 11 -> GPIO1_13 = 45
# P8 Pin 12 -> GPIO1_12 = 44
# P8 Pin 14 -> GPIO0_26 = 26
# P8 Pin 16 -> GPIO1_14 = 46

TESTPIN=44  # Replace with your target GPIO pin number

# Export the GPIO pin to make it available
echo "$TESTPIN" > /sys/class/gpio/export

# Set the direction of the pin as output
echo "out" > /sys/class/gpio/gpio$TESTPIN/direction

# Toggle the pin value HIGH and LOW three times
for i in {1..3}; do
  echo "Setting gpio$TESTPIN HIGH"
  echo "1" > /sys/class/gpio/gpio$TESTPIN/value
  sleep 1  # Wait for 1 second

  echo "Setting gpio$TESTPIN LOW"
  echo "0" > /sys/class/gpio/gpio$TESTPIN/value
  sleep 1  # Wait for 1 second
done

# Unexport the GPIO pin after testing
echo "$TESTPIN" > /sys/class/gpio/unexport
Enter fullscreen mode Exit fullscreen mode

If you want more information, please visit GOVAPEMAKER

bash Article's
30 articles in total
Favicon
Understanding Linux Shells: Interactive, Non-Interactive, and RC Files
Favicon
Fixing Linux Backup Sync Issues for exFAT Compatibility
Favicon
Ergonomic Pyhon Text Piping Solution for Linux Shell with pypyp and uv
Favicon
Changing the Login Shell with Security and Interactivity
Favicon
Final Bash Script Series Mastering Remote Server Management and Web App Deployment
Favicon
Writting a GH extension with AI
Favicon
Test GPIO pins on BeagleBone Black by toggling high to low
Favicon
NYP Infosec December CTF 2024 writeup!
Favicon
Building a Smart Heater Controller with Python, Docker, and Bluetooth #3
Favicon
The Complete Guide to Bash Commands
Favicon
How to Get Started with Bash Scripting for Automation
Favicon
Building a Basic Testing Framework in Bash 🐚
Favicon
Funny how, as I was writing this, I started wondering—could we make this pipeline even smarter? That’s when SonarQube came to mind. But can it even work with Bash scripts? I’d love to hear your thoughts!
Favicon
Domina Bash con ejemplos prácticos de Git
Favicon
Explaining Null Device or Black Hole Register in Vim
Favicon
A Media Server on Steroids - Walkthrough
Favicon
From FZF file preview to a browser for cht.sh to discovering the ideal solution
Favicon
Code. Battery notifier.
Favicon
🌟Simplifying User Account Management with Bash Scripting Day3🌟
Favicon
Become a Bash Scripting Pro in 10 Minutes: A Quick Guide for Beginners
Favicon
Automatically Monitor and Manage RAM Usage for Next.js Development
Favicon
Bash Script - Task Management
Favicon
Bash Your Tools
Favicon
Bash Script Series: Automating Log Analysis with Bash Script or Shell Script
Favicon
The Most Interesting Mostly Tech Reads of 2024
Favicon
🚀 Automating Process Monitoring & Restarting with Bash Scripting Day4! 🔧
Favicon
🚀 RazzShell v1.0.1 is Here: Plugin Support, Enhanced Job Management, and More! 🌟
Favicon
Step-by-Step Guide: Assigning a Namecheap Domain to DigitalOcean Hosting with Nginx
Favicon
Simplify GitHub Workflow Management with My-GitHub-Manager
Favicon
How to play a bunch of lemmings

Featured ones: