Last active
January 23, 2024 02:22
-
-
Save CTXz/5217e5fab09f6cea3f0de0651f463dad to your computer and use it in GitHub Desktop.
An installation script that sets up GPIO functionality for the Banana Pi M2 Zero. It installs prerequired packages, necessary system files, a Banana Pi M2 Zero compatible port of WiringPi and a Banana Pi M2 Zero compatible port of RPi.GPIO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Copyright (C) 2023 Patrick Pedersen | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <https://www.gnu.org/licenses/>. | |
# | |
# To run, execute: | |
# $ chmod +x bpi-m2z-gpio-setup.sh | |
# $ sudo ./bpi-m2z-gpio-setup.sh | |
# Developed for- and tested on: Armbian (22.11.0-trunk) | |
clean_up() { | |
echo "Cleaning up..." | |
rm -rf /tmp/bpi-m2z-system-files | |
rm -rf /tmp/BPI-WiringPi2 | |
rm -rf /tmp/RPi.GPIO | |
} | |
# Check if we are root | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit 1 | |
fi | |
# Check if hardware is bpi-m2z | |
if [ ! -f /sys/firmware/devicetree/base/model ]; then | |
echo "This script is only for the BPI-M2Z" | |
exit 1 | |
fi | |
#-------------------------------------------- | |
# Install prerequired packages | |
#-------------------------------------------- | |
echo "Installing prerequired packages..." | |
apt install -y build-essential git python3-dev | |
if [ $? -ne 0 ]; then | |
echo "Failed to install prerequired packages" | |
exit 1 | |
fi | |
echo "Prerequired packages successfully installed" | |
#-------------------------------------------- | |
# Install required system files | |
#-------------------------------------------- | |
echo "Installing required system files..." | |
cd /tmp | |
git clone https://github.com/CTXz/bpi-m2z-system-files.git | |
if [ $? -ne 0 ]; then | |
echo "Failed to clone bpi-m2z-system-files" | |
exit 1 | |
fi | |
cd bpi-m2z-system-files | |
chmod +x install.sh | |
./install.sh | |
if [ $? -ne 0 ]; then | |
echo "Failed to install required system files" | |
clean_up | |
exit 1 | |
fi | |
#-------------------------------------------- | |
# Build and install BPI-WiringPi2 | |
# | |
# Special thanks to bontango for the fixed | |
# up fork! | |
#-------------------------------------------- | |
echo "Building and installing BPI-WiringPi2..." | |
cd /tmp | |
git clone https://github.com/bontango/BPI-WiringPi2 | |
if [ $? -ne 0 ]; then | |
echo "Failed to clone BPI-WiringPi2" | |
clean_up | |
exit 1 | |
fi | |
cd BPI-WiringPi2 | |
chmod +x build | |
./build | |
if [ $? -ne 0 ]; then | |
echo "Failed to build BPI-WiringPi2" | |
clean_up | |
exit 1 | |
fi | |
# Patch readall table | |
curl https://raw.githubusercontent.com/TuryRx/Bananapi-m2-zero-GPIO-files/master/gpioread.sh > /usr/local/bin/gpioread | |
if [ $? -ne 0 ]; then | |
echo "Failed to patch readall table" | |
clean_up | |
exit 1 | |
fi | |
chmod o+x /usr/local/bin/gpioread | |
chmod 777 /usr/local/bin/gpioread | |
touch /var/lib/bananapi/gpio | |
chmod o+x /var/lib/bananapi/gpio | |
chmod 777 /var/lib/bananapi/gpio | |
# Test if gpio command is available and working | |
gpio -v | |
if [ $? -ne 0 ]; then | |
echo "Failed to install BPI-WiringPi2" | |
clean_up | |
exit 1 | |
fi | |
echo "BPI-WiringPi2 successfully built and installed" | |
#-------------------------------------------- | |
# Build and install RPi.GPIO | |
# | |
# Special thanks to the Grazer Computer Club | |
# for the fixed up fork! | |
#-------------------------------------------- | |
echo "Building and installing BPI port of RPi.GPIO..." | |
cd /tmp | |
git clone https://github.com/GrazerComputerClub/RPi.GPIO.git | |
if [ $? -ne 0 ]; then | |
echo "Failed to clone RPi.GPIO" | |
clean_up | |
exit 1 | |
fi | |
cd RPi.GPIO | |
CFLAGS="-fcommon" python3 setup.py install | |
if [ $? -ne 0 ]; then | |
echo "Failed to build RPi.GPIO" | |
clean_up | |
exit 1 | |
fi | |
echo "BPI port of RPi.GPIO successfully built and installed" | |
#-------------------------------------------- | |
clean_up | |
echo "GPIO setup successfully completed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment