Raspberry Pi GPIO: Difference between revisions
Brian Wilson (talk | contribs) mNo edit summary |
Brian Wilson (talk | contribs) mNo edit summary |
||
Line 44: | Line 44: | ||
== Configure GPIO pins in SVXLINK == | == Configure GPIO pins in SVXLINK == | ||
This is done by setting up /etc/svxlink/gpio.conf and then restarting svxlink. The brief version of the file is | See [[This is done by setting up /etc/svxlink/gpio.conf and then restarting svxlink. The brief version of the file is | ||
GPIO_USER="svxlink" | GPIO_USER="svxlink" | ||
GPIO_GROUP="svxlink" | GPIO_GROUP="svxlink" |
Revision as of 18:44, 28 June 2024
Okay, I need to connect input and output to a Pi to test it for the Repeater Linking project.
- A push button with a 2 pin connector to simulate COR input.
- An LED to simulate PTT output.
The pin can be programmed with a pull up resistor, so I can connect the button to GPIO23 and the adjacent GND. Pushing the button gives me a zero.
The LED can go anywhere. I pull it down so it is between +5V and GPIO18
Python test program
from time import sleep #Set warnings off (optional) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) #Set Button and LED pins Button = 23 LED = 18 #Setup Button and LED GPIO.setup(Button,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(LED,GPIO.OUT) old_button_state = 2 led_on = False delay = .2 while True: button_state = GPIO.input(Button) if button_state != old_button_state: print(button_state) old_button_state = button_state if button_state == 0: delay = .10 else: delay = .3 if led_on: GPIO.output(LED,GPIO.HIGH) led_on = False else: GPIO.output(LED,GPIO.LOW) led_on = True sleep(delay)
Configure GPIO pins in SVXLINK
See [[This is done by setting up /etc/svxlink/gpio.conf and then restarting svxlink. The brief version of the file is
GPIO_USER="svxlink" GPIO_GROUP="svxlink" GPIO_MODE="0664" GPIO_PATH=/sys/class/gpio GPIO_OUT_LOW="gpio18" GPIO_IN_LOW="gpio23"
Before I learned that I could use this file I did it the hard way. Like this.
echo "Setting GPIO pin 18 as an output. (PTT)" echo "18" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio18/direction echo "Setting GPIO pin 23 as an input (COR)." echo "23" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio23/direction
Question: Can I read the state of a pin?? Answer: yes. For example, read the button and show its state once every 2 seconds.
watch cat /sys/class/gpio/gpio23/value
Question, what about the LED? Read its state. Write 1's and 0's. Huh. It is set as input! First set it as
systemctl stop svxlink echo "out" > /sys/class/gpio/gpio18/direction while true; do echo 0 > /sys/class/gpio/gpio18/value; sleep 1; echo 1 > /sys/class/ gpio/gpio18/value; sleep 1; done
Does this code work when I am running svxlink though? Yes, it does. That means I can use "echo" commands to test.
I am wondering why GPIO18 was set as input. Is the gpio.conf getting read? It's "in" again after a reboot. Oops. File was wrong. Fixed. Rebooted.