Etiket arşivi: raspberrypi gpio reading

raspberrypi gpio examples with c – part3- reading input gpio

I will explain in this article , reading from input gpio

if you did not read previous articles, some definitions can become to you undefined.

first reading from gpio

gpio pin levels address are below

0x 7E20 0034 GPLEV0 GPIO Pin Level 0 32 R
0x 7E20 0038 GPLEV1 GPIO Pin Level 1 32 R

we have  32 bit+32 bit =64 bit registers. as you know bcm cpu has 54 pins. these 64 bits are enough for us.

#define PIN_LEVEL_START  (13)

calculation of address 0x34/(sizeof(int)=13

int value= *(gpio+PIN_LEVEL_START+PIN_WRITE_POSITION(pin));

we get all 32 bits, now we will lookat, pin bit

int pin= 1 << PIN_WRITE_SHIFT(pin)

if( value & pin) return HIGH else return LOW

now we will create a breadboard test environment;


1 push button

1 count 10k resistor

2 cables.

attach them as below

yellow cable is output, orange cable is input


and the code is here read.c