Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Raspberry Pi / RPi GPIO Pins With AGK

Author
Message
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 22nd Feb 2018 23:43
Hello AppGameKit programmers,

I am running into some problems with the GPIO pins and the input functions for simple buttons.

The I2C, UART AND SPI are working ok and AppGameKit detects the pressing. But on thr other pins such as GPIO:17, the button press is not detected at all.

Did anyone encountered this kind of problem?

If so, please kindly provide some info regarding this problem

Thank you very much, community!
www.alexmatei.com
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 26th Feb 2018 20:37 Edited at: 26th Feb 2018 20:38
GPIO inputs are reading fine for me. Ive just quickly checked the GPIO example project that is shipped with AppGameKit and read GPIO17 without a problem.

How are you wiring your input?
Exactly which pin do you think GPIO17 is?
Typically the inputs have the internal pull up resistors enabled so you have to pull them low to set the input to low and it floats high without any input. I tend to use an external pull up as well if it is a noisy environment or long input cables.

You say you have I2C, UART and Spi working? I assume they are working as you have tried some python or C code to control them or have a HAT that you know works?
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 3rd Mar 2018 10:59
Hi Bengismo,

I am writing on GPIO 17 which is PIN 11 as the following:



It's on a fresh install of raspbian stretch. So no previous compiles. On python it worked fine.

Thank you!
www.alexmatei.com
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Mar 2018 14:10
Quote: "I am writing on GPIO 17 which is PIN 11 as the following:

previoussongpin as integer
previoussongpin = OpenToRead("gpio:17")"


Firstly, Your NOT writing...you are reading as you opened the pin to read it with OpenToRead()

Secondly, You opened the pin but you still need to call ReadByte to actually get the status of the pin


You may also have issues with libraries being renamed on Stretch creating problems in AppGameKit where as Jessie doesnt have the issue.
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 3rd Mar 2018 14:45
Sorry, i meant Read not Write.

The pin state remains at 0 even when i am pressing it. So the state must be 1 if it's not pressed and 0 if it's pressed.

Sample code of a button:

www.alexmatei.com
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Mar 2018 15:05
Try using the GPIO sample program that comes with AppGameKit so you can check that you have a working button and it is wired correctly. You havent said how you have your button wired so it might be that it is not changing state at all. Check that first

Also, your sample button code seems quite buggy as "cnt" doesnt seem to be rest to zero anywhere? It makes little sense.

Your button being 1 or 0 in each state will depend on your wiring.
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 3rd Mar 2018 15:42
Still the same with the example.

Photo attached with the pins:

White cable for current and black for ground.

Thank you!
www.alexmatei.com

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Mar 2018 17:33 Edited at: 3rd Mar 2018 18:43
Ahh...I see the problem. you are attempting to ground an input that is already grounded internally with a pull down enabled. You aren't using ANY pull up or pulldown resistors

If you connect your black wire to pin 1 (3.3V) then the input will be 3.3V when the button is pressed and 0V when it isnt pressed.

You should really be using resistors and have a bit of knowledge of what your doing electronics wise so you dont damage your pi.


This is not a good way of wiring it up
MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 3rd Mar 2018 20:18
And that's available for the rest of the pins? (Not UART and I2C included)
www.alexmatei.com
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Mar 2018 19:16
You should do some reading on how to correctly apply input voltages as well as what the pull up and pull down options do. this will hellp you understand how to do this correctly.

https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/



MateiSoft
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location:
Posted: 5th Mar 2018 09:07
I will definetly do that!

Btw, in python it worked with the same wiring. Maybe because of the declaration in the code "pull_up_down" for the button?

Again i might be wrong.

Thank you!
www.alexmatei.com

Login to post a reply

Server time is: 2024-03-28 13:01:32
Your offset time is: 2024-03-28 13:01:32