I wrote a code that I run in Thonny which detects if a connection is made between the 3.3V output and a GPIO pin on the Raspberry Pico:
print("Hello World!")
import time
import digitalio
import board
print(board.board_id)
btn15_pin = board.GP15
btn15 = digitalio.DigitalInOut(btn15_pin)
btn15.direction = digitalio.Direction.INPUT
btn15.pull = digitalio.Pull.DOWN
while True:
if btn15.value:
print("button 15 pressed")
time.sleep(0.1)
So I thought I could use this to identify which keyboard keys are pressed through by connecting the 20 pins on a FPC connector to the various GPIO inputs on a Raspberry Pico (whilst connecting the ground to the backplate of the keyboard). However, that assumption is wrong, and I have determined that some keyboard matrix is used which creates a connection between various pin pairs within the FPC connections. For example, pressing the left shift button creates a connection between pin 4 and 6. Therefore, I was wondering:
(How) is it possible to detect connections between various GPIO pins (e.g. a connection between GPIO pin 15 and GPIO pin 17) on the Raspberry Pico?
Answer Raspberry PI
I am not able to post an answer to this question. However, this link explains how one can identify connections that are being made between two GPIO connections on a Raspberry (Pi):
Internal wires connect the individual rows and columns of switches so that when a user presses one of the switches, that switch electrically connects a single row to a column.
In the described wiring sceme, these rows and columns are connected to different GPIO pins, resulting in an electrical connection between GPIO pins if a row and a column wire are connected. In particular:
In the connection scheme they describe, they have 4 wires on GPIO pins 1,7,8,25
, and another four wires on GPIO pins: 12,16,20,21
. Next, the following script practically registers if an electrical connection is made between a GPIO pin of the first group and a GPIO pin of the second group:
# import required libraries
import RPi.GPIO as GPIO
import time
these GPIO pins are connected to the keypad
change these according to your connections!
L1 = 25
L2 = 8
L3 = 7
L4 = 1
C1 = 12
C2 = 16
C3 = 20
C4 = 21
Initialize the GPIO pins
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(L1, GPIO.OUT)
GPIO.setup(L2, GPIO.OUT)
GPIO.setup(L3, GPIO.OUT)
GPIO.setup(L4, GPIO.OUT)
Make sure to configure the input pins to use the internal pull-down resistors
GPIO.setup(C1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
The readLine function implements the procedure discussed in the article
It sends out a single pulse to one of the rows of the keypad
and then checks each column for changes
If it detects a change, the user pressed the button that connects the given line
to the detected column
def readLine(line, characters):
GPIO.output(line, GPIO.HIGH)
if(GPIO.input(C1) == 1):
print(characters[0])
if(GPIO.input(C2) == 1):
print(characters[1])
if(GPIO.input(C3) == 1):
print(characters[2])
if(GPIO.input(C4) == 1):
print(characters[3])
GPIO.output(line, GPIO.LOW)
try:
while True:
# call the readLine function for each row of the keypad
readLine(L1, ["1","2","3","A"])
readLine(L2, ["4","5","6","B"])
readLine(L3, ["7","8","9","C"])
readLine(L4, ["*","0","#","D"])
time.sleep(0.1)
except KeyboardInterrupt:
print("\nApplication stopped!")
Answer Raspberry Pico
The following code detects a connection between GPIO pin 0 and 1 on a Raspberry Pico:
from machine import Pin
import time
Do disco if connection is detected
led = Pin(15, Pin.OUT)
Set the output pin to GPIO pin nr 0.
output_line= Pin(0, Pin.OUT)
Set the input pin to GPIO pin nr 1.
input_line = Pin(1, Pin.IN, Pin.PULL_DOWN)
while True:
time.sleep(2)
# Check if the input pin nr 1 has an incoming value.
if(input_line.value()):
# Connection is found, start disco!
led.toggle()
# Not quite time yet, let's hang back.
time.sleep(0.5)
# Celebrate victory.
print("connected")
# Put voltage/value of 1 [-] on GPIO pin 0.
output_line.value(1)
print("Started sending output signal on output pin nr 0.")
Note it is advisable to not set one pin to HIGH and the other to LOW whilst connecting them, as that might fry the board.