Carpenter
Posts: 3
Joined: Mon Jun 10, 2019 2:23 pm

Wiring Pi in C and Raspberry Pi 2 modle B v1.1?

Fri Jun 21, 2019 2:13 pm

I have simple code
using GPIO 14 for Anode LED and GPIO18 as Input with Pull Up resistor
pinMode(LED, OUTPUT);
swith GPIO14 as output and this work digitalWrite(LED, HIGH); //swith LED ON
problem is in
pinMode(SWITCH, INPUT);
pullUpDnControl(SWITCH, PUD_UP);
First switch GPIO18 as input and
second switch on pull up resistor on this pin, unfortunely voltage on GPIO 18 is still 0V
What am I doing wrong?

I thing GPIO is maped as http://osoyoo.com/wp-content/uploads/20 ... plus-1.jpg


Code: Select all

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>

#define	LED	14
#define	SWITCH 18

static volatile int globalCounter;
void myInterrupt(void) { ++globalCounter; }

int main(void)
{

	globalCounter = 0;

	wiringPiSetupSys();
	pinMode(LED, OUTPUT);
	pinMode(SWITCH, INPUT);
	pullUpDnControl(SWITCH, PUD_UP);
	wiringPiISR(SWITCH, INT_EDGE_FALLING, &myInterrupt);


stevieb9
Posts: 15
Joined: Fri Jan 13, 2017 2:40 pm

Re: Wiring Pi in C and Raspberry Pi 2 modle B v1.1?

Fri Jun 21, 2019 2:24 pm

With

Code: Select all

wiringPiSetupSys()
initialization, you have to manually export the pins before you use them. Per the documentation:
Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface before you run your program. You can do this in a separate shell-script, or by using the system() function from inside your program to call the gpio program.
Did you perform that step?


Carpenter
Posts: 3
Joined: Mon Jun 10, 2019 2:23 pm

Re: Wiring Pi in C and Raspberry Pi 2 modle B v1.1?

Fri Jun 21, 2019 3:11 pm

Yes. I use for programing Visual Studio 2019 and in command line have
gpio export 14 out; gpio export 18 in
In each case
If I type
gpio exports
14: out 1 none
18: in 0 falling

but on pin 18 is still 0V (internal PullUP resistor not active) and therefore it does not work wiringPiISR on INT_EDGE_FALLING if I grouded this pin ove switch.
LED on GPIO 14 in same program works fine and blinks.

If I from command line type
gpio mode 1 up
is pull up resistor switched On an on GPIO 18 is +3,3V and in my program wiringPiISR generata IRQ on faliing edge if I ground pin OK.
More accurately generates multiple interruptions at one push, but that's because I have not capacitor on switch.

Edit:
So I looked at the source code and perhaps understood how it worked.
Anyway, thank you for the directions,
The author could somewhat clarify the description of the library on his website.
thank you all

Return to “C/C++”