0

So I built an MLB scoreboard with a RPI 3. Right now the display can either show my favorite teams playing, OR all the teams playing and cycle through them as they are going on. I would like to add a toggle switch to the back of the scoreboard to select either the All-Teams or My-Teams depending on who's playing at that time. I have two separate nearly identical directories for the scoreboard accommodating either All-Teams or My-Teams.

Right now I have a cron file called "start-scoreboard.sh" that will start the score board showing either All-Teams, or My-Teams depending on what I have entered into "cd /home/pi/mlb-led-scoreboard-(All-Teams OR My-Teams here)" within the cron file.

Is there a way for the RPI to read the state of a gpio pin and run either All-Teams OR My-Teams directories? Here is an example of what I have in my "start-scoreboard.sh" cron file with the All-Teams directory listed...

!/bin/bash
u/reboot sleep 60 $$ start-scoreboard.sh
cd /home/pi/mlb-led-scoreboard-All-Teams
n=0
until [ $n -ge 10 ]
do
python main.py --led-gpio-mapping=adafruit-hat --led-brightness=50 --led-slowdown-gpio=3 --led-rows=32 --led-cols=64 && break
n=$[$n+1]
sleep 10
done

2 Answers 2

0

So first off: you're doing GPIO things in your python script. Honestly, you should just use the very same library you use there (which I don't know) to read the GPIO state and behave accordingly! Same for your do python… ; sleep 10; done loop: this would really be something you should rather integrate in your python script.

Secondly, sure, just check the value of the GPIO-pseudofile, depending on your kernel setup probably in /sys/class/gpio/gpio{number}/value (might need to set the direction of that pin with echo in > /sys/class/gpio/gpio{number}/direction; if it's not there, you might need to export it first by echo {number} > /sys/class/gpio/export) ; that's the deprecated sysfs interface, but I bet on default kernels for the RPi it's still enabled. Alternatively, use the gpio tool that you can install for your Linux distro, with gpio read {id}.

0

Okay so I ended up using the following method, and it seems to have done the trick. Wanted to post this in case anyone out there comes across this issue for themselves and is looking for an answer. In the wiring of the gpio pins, I ended up connecting the switch between 39 (ground) and pin 40.

#!/bin/bash

# Set GPIO pin number
GPIO_PIN=40  # Enter what GPIO pin is to be switched to ground

# Set up GPIO pin as input
echo "$GPIO_PIN" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_PIN/direction

# Read the state of the GPIO pin
GPIO_STATE=$(cat /sys/class/gpio/gpio$GPIO_PIN/value)

# Depending on the GPIO state, choose the appropriate directory
if [ $GPIO_STATE -eq 0 ]; then
    SCOREBOARD_DIR="/home/pi/mlb-led-scoreboard-All-Teams"
else
    SCOREBOARD_DIR="/home/pi/mlb-led-scoreboard-My-Teams"
fi

# Change to the selected directory
cd "$SCOREBOARD_DIR"

# Start the scoreboard
n=0
until [ $n -ge 10 ]
do
    python main.py --led-gpio-mapping=adafruit-hat --led-brightness=50 --led-slowdown-gpio=3 --led-rows=32 --led-cols=64 && break
    n=$[$n+1]
    sleep 10
done

# Clean up GPIO pin
echo "$GPIO_PIN" > /sys/class/gpio/unexport

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.