CraftMarine
Posts: 5
Joined: Fri Sep 29, 2017 9:05 pm

Issue using pullUpDnControl

Fri Mar 27, 2020 9:41 am

Hi everyone !

I'm facing some issue with the pullUpDnControl() function.

Below is my code :

Code: Select all

#include <wiringPi.h>
#include <stdio.h>

#define BUTTON 25

void buttonSetup (void)
{
  wiringPiSetupGpio () ;
  pullUpDnControl (BUTTON, PUD_UP) ;
  pinMode (BUTTON, INPUT) ;
}

int main(void){
	while(1){
		if (digitalRead (BUTTON) == HIGH){
			printf("Button: high\n");
		}
		if (digitalRead (BUTTON) == LOW){
			printf("Button: low\n");
		}
		delay(100);
	}
		
}
My circuit :

Image

For now, I only test buttons one by one. I tryed everything, even disconecting my buttons and using jumpers, nothing is working. I always get the "low" values. Do I have to set my own pullup resistor ? Raspberry have and internal 50k one right ? Did I missed something ?

Thank for your answers.

CraftMarine

markkuk
Posts: 179
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: Issue using pullUpDnControl

Fri Mar 27, 2020 10:00 am

You aren't calling the buttonSetup() function from your main(), so your switch is never configured.

CraftMarine
Posts: 5
Joined: Fri Sep 29, 2017 9:05 pm

Re: Issue using pullUpDnControl

Fri Mar 27, 2020 10:34 am

Oh god, feeling so dumb right now... The details I don't see :'(. With this correction it work. But I think I might have some other question with my main program. I'll be posting back soon

CraftMarine
Posts: 5
Joined: Fri Sep 29, 2017 9:05 pm

Re: Issue using pullUpDnControl

Sun Mar 29, 2020 6:48 pm

Thanks for your help, I just didn't checked by myself, everything working fine now ^^

Return to “C/C++”