Context
While I was trying to use
import RPi.GPIO as GPIO
on a Raspberry Pico, I was experiencing some difficulties. I had successfully installed the RPi.GPIO
package manually in Thonny by clicking: Tools>Manage Plug-ins>Search for:
RPi.GPIO
Ensure that package is found, then manually click: Install
.
Then I rebooted Thonny, and it shows the plugin is available. To verify it exists, also opened a terminal from Thonny by clicking:
Tools>Open system shell
and typed pip install RPi.GPIO
which returns it is already installed. And I opened a python shell to verify it can be imported:
********************************************************************************
Some Python commands in the PATH of this session:
- python -> /home/name/anaconda/bin/python3.7
- python3 -> /home/name/anaconda/bin/python3.7
- python3.7 == /home/name/anaconda/bin/python3.7
- python3.8 == /usr/bin/python3.8
- pip == /home/name/anaconda/bin/pip
- pip3 == /home/name/anaconda/bin/pip3
- pip3.7 == /home/name/anaconda/bin/pip3.7
(base) name@name-Inspiron-3543:~$ pip install RPi.GPIO
Requirement already satisfied: RPi.GPIO in ./anaconda/lib/python3.7/site-packages (0.7.0)
(base) name@name-Inspiron-3543:~$ python
Python 3.7.6 (default, Jan 8 2020, 19:59:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/name/anaconda/lib/python3.7/site-packages/RPi/GPIO/init.py", line 23, in <module>
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
>>>
This output says it runs only on a Raspberry Pi, (and not on a Raspberry Pico).
XY-problem
I'm trying to get a keyboard matrix mapping of a keyboard that I'm connecting to the GPIO pins of the Raspberry Pico. My first step is to try to send a signal to a GPIO pin 8 of the Raspberry Pico for the duration of e.g. 0.5 seconds and then trying to measure the voltage/value of GPIO pin 11 within that timeframe. I expect that the voltage/value of GPIO pin 11 is the default value (I assume 0) when it is not connected to GPIO pin 8, and I expect that the voltage/value of GPIO pin 11 is the value I set at GPIO pin 8 (I assume 1) if I connect a wire between GPIO pin 8 and 11.
In essence that would be connection out of 4x4=16 connections of the following script:
# 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!")
Question
I do not exactly know what each step in that script does, however, the script contains:
# 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)
so I thought, before starting to randomly try to see what does what, I would like to ask:
Can I shortcircuit and break my Raspberry Pico if I make a connection between two GPIO pins and run some silly code? Or does it have some failsafe protection for dummies?