User avatar
pjjones
Posts: 13
Joined: Sat Feb 22, 2014 9:27 am
Location: Sidney, Australia

GPIO pin for ENTER

Sun May 22, 2016 7:25 am

HI
I am building a small project and I want the user to be able to press a BIG RED BUTTON.
I would like to be able to wire this button so that is "resembles" pressing ENTER.
Does anybody know if there is there a gpio pin and "piece of code" to do this please.
If not (as I am new to this) can you tell me what I am to do in order for a program to recognise this button being pressed.
Thanks very much for your input and help,

PJ
I grew up with punch cards!
A wiseman once told me..."Don't live your life by clever sayings"

User avatar
rpdom
Posts: 15592
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO pin for ENTER

Sun May 22, 2016 7:32 am

Yes, there are a couple of ways to do this.

Of the top of my head I can't remember where the code is, but... hold on a mo... try searching (use a proper search engine, not the forum one, as that isn't great) for "site:raspberrypi.org gpio keyboard" or maybe look for something that uses "uinput", which is a way that a program can trigger key-press or mouse events.

User avatar
pjjones
Posts: 13
Joined: Sat Feb 22, 2014 9:27 am
Location: Sidney, Australia

Re: GPIO pin for ENTER

Sun May 22, 2016 7:51 am

...great
thanks very much


what a speedy reply at 8:30 on a Sunday Morning :¬)
I grew up with punch cards!
A wiseman once told me..."Don't live your life by clever sayings"

User avatar
rpdom
Posts: 15592
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO pin for ENTER

Sun May 22, 2016 8:06 am

pjjones wrote:what a speedy reply at 8:30 on a Sunday Morning :¬)
I'm up early as we're heading off to a spider show today :)

(actually, I'm usually up early anyway. I'm one of those annoying "morning" people. Just don't bother me after 4pm ;) )

User avatar
pjjones
Posts: 13
Joined: Sat Feb 22, 2014 9:27 am
Location: Sidney, Australia

Re: GPIO pin for ENTER

Sun May 22, 2016 8:09 am

he he he

SPIDER SHOW ?? Is that what it sounds like?
I had a 5" tarantula in a frame once (dead!)
Shame, I cant find it anywhere, someone pinched I think.

have a good day and thanx :¬)
(hope you read this before 4pm)
I grew up with punch cards!
A wiseman once told me..."Don't live your life by clever sayings"

User avatar
Ferdinand
Posts: 236
Joined: Sun Dec 01, 2013 2:24 pm
Location: Leiderdorp, NL

Re: GPIO pin for ENTER

Sun May 22, 2016 8:21 am

Hi pj,

This post contains a code for reading a gpio pin. Perhaps you can use it.
viewtopic.php?f=32&t=148932

Success with your project.
Success with your project!
Ferdinand

User avatar
pjjones
Posts: 13
Joined: Sat Feb 22, 2014 9:27 am
Location: Sidney, Australia

Re: GPIO pin for ENTER

Sun May 22, 2016 8:24 am

Ferdinand wrote: viewtopic.php?f=32&t=148932
Gerat thank you very much :¬)

pj
I grew up with punch cards!
A wiseman once told me..."Don't live your life by clever sayings"

User avatar
rpdom
Posts: 15592
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO pin for ENTER

Sun May 22, 2016 9:01 am

pjjones wrote:he he he

SPIDER SHOW ?? Is that what it sounds like?
Pretty much, yes. http://exhibition.thebts.co.uk/ (not for arachnophobes)
I had a 5" tarantula in a frame once (dead!)
Shame, I cant find it anywhere, someone pinched I think.

have a good day and thanx :¬)
(hope you read this before 4pm)
We currently have over 50 (live) tarantulas of various sizes, possibly to be closer to 60 by the end of the day.
The smallest ones are so tiny I can barely see them. The largest are around 6-7" leg span.

They are mostly harmless. Some might give a small bite if they feel threatened, but they are unlikely to use venom and none of ours have ever done that.

Despite my user pic, we don't handle them, as it is bad for them. The pic was an accident when unpacking that particular spider.

User avatar
pjjones
Posts: 13
Joined: Sat Feb 22, 2014 9:27 am
Location: Sidney, Australia

Re: GPIO pin for ENTER

Sun May 22, 2016 9:04 am

WOW! 60 ruddy spiders - he he he - have a good day at the Spider Show
They are mostly harmless. Some might give a small bite if they feel threatened, but they are unlikely to use venom and none of ours have ever done that.
I grew up with punch cards!
A wiseman once told me..."Don't live your life by clever sayings"

fdr4prez
Posts: 17
Joined: Fri May 13, 2016 8:06 pm

Re: GPIO pin for ENTER

Mon May 23, 2016 11:58 pm

Here is some code that I am currently using.

You will need to install uinput and GPIO modules into the Pi

Your button will need to be wired between the ground and GPIO26 pins - or change the code accordingly depending on which GPIO is used.

Code: Select all

import uinput
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)  #GPIO.BCM uses the GPIO port name for reference

GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)

device = uinput.Device([uinput.KEY_ENTER])

# Boolean to keep track of the button
Enter = False

while True:
    if (not Enter) and (not GPIO.input(26)):      # Big Red Button pressed 
       Enter = True 
       device.emit(uinput.KEY_ENTER, 1)       # press ENTER keyboard button
    if Enter and GPIO.input(26):                      # Big Red Button released 
       Enter = False 
       device.emit(uinput.KEY_ENTER, 0)       # ENTER keyboard button released
    time.sleep(0.2)                                           # Poll every 200ms 



User avatar
pjjones
Posts: 13
Joined: Sat Feb 22, 2014 9:27 am
Location: Sidney, Australia

Re: GPIO pin for ENTER

Tue May 24, 2016 6:13 am

Wow that's great - thank you very much :¬)
I grew up with punch cards!
A wiseman once told me..."Don't live your life by clever sayings"

Return to “Python”