5.5.2 · D1 · HinglishEmbedded Systems & Real-Time Software

FoundationsGPIO — input - output, pull-up - pull-down, interrupt on pin change

2,664 words12 min read↑ Read in English

5.5.2 · D1 · Coding › Embedded Systems & Real-Time Software › GPIO — input - output, pull-up - pull-down, interrupt on pin

Yeh D1 foundations page hai. Parent note (GPIO topic) bahut saare symbols ek saath throw karta hai: , , HIGH/LOW, , , "Hi-Z", "edge", volatile. Neeche hum inme se har ek ko bilkul zero se build karte hain — pehle plain words, phir picture, phir kyun yeh topic iske bina nahi chal sakta.


1. Voltage — wire ki "height"

Picture yeh hai: har wire ko ek paani ki tank ki tarah imagine karo jo kisi height par rakhi ho. Paani (charge) ek unchi tank se ek chhoti tank ki taraf bahta hai. Voltage hai floor ke comparison mein tank kitni unchi hai.

Hum height hamesha kisi cheez ke relative measure karte hain. Us reference floor ko ground kehte hain.

Yeh topic inka kyun use karta hai: pin ke "HIGH" ya "LOW" hone ke baare mein har ek sentence secretly matlab hai "close to " ya "close to ". Floor () aur ceiling () ke bina, HIGH aur LOW ke words meaningless hain.


2. HIGH / LOW aur logic 1 / 0

Picture yeh hai: ek light switch ke sirf up aur down hote hain. Koi "half-on" nahi hota jise digital world respect kare.

Yeh topic iska kyun use karta hai: button padhna, LED drive karna, interrupt fire karna — yeh sab CPU ka yeh decide karna hai ki "kya yeh wire 1 hai ya 0?"


3. Input vs Output — feel vs push

Yeh topic iska kyun use karta hai: poora note "output half" (push-pull, open-drain) aur "input half" (pull resistors, floating, interrupts) mein split hota hai. Yeh root fork hai.


4. Resistance , current , aur Ohm's Law

Yeh topic iska kyun use karta hai: pull resistor value choose karna kuch nahi hai sirf is equation ke siwa.


5. High-impedance (Hi-Z) — "disconnected" state

Picture yeh hai: ek pipe mein ek valve itna tight band ki koi paani nahi hilt. Pipe wahan hai, lekin electrically aise hai jaise aapne use kaat diya.


6. Floating aur pull resistor

Yeh topic iska kyun use karta hai: yeh "#1 beginner bug" ka fix hai — ek button jo press hone par read hota hai jab chhua nahi gaya ho.


7. Active-LOW — "pressed" often 0 kyun hota hai

Picture yeh hai: "alarm" wire ka ceiling se gir ke floor par jaana hai, upar uthna nahi.

Yeh topic iska kyun use karta hai: kyunki internal pull-ups common hain aur grounding electrically clean hai, real hardware "pressed = 0" read karta hai, jo beginners ko surprise karta hai. Isko naam dene se surprise door ho jaata hai.


8. Edges — time ke saath height mein badlaav

Picture yeh hai: time ke against plot ki gayi wire ki height ek staircase jaisi dikhti hai. Vertical step edge hai — jump ka woh instant.

Yeh topic iska kyun use karta hai: interrupts edges par fire karte hain. "Edge" ka concept nahi, toh "interrupt on pin change" ka concept bhi nahi.


9. Interrupt & ISR — kandhe par tap

Yeh topic iska kyun use karta hai: note ka poora "interrupt on pin change" wala half yahi idea hai. Rule "ISR chhota rakho, flag clear karo" — yeh sab yahaan se aata hai.


10. volatile — "apni memory par trust mat karo"

Yeh topic iska kyun use karta hai: iske bina, ek optimized build shared flag ko cache karta hai aur main loop kabhi ISR ka update nahi dekhta — parent ka "debug mein kaam karta hai, -O2 ke saath toot jaata hai" wala bug.


Yeh sab topic ko kaise feed karte hain

Voltage and Ground

HIGH LOW logic 1 0

Supply VDD

Input vs Output

Ohms Law V equals I R

Pull-up Pull-down

High impedance Hi-Z

Floating problem

Active-LOW wiring

Rising Falling edge

Interrupt and ISR

volatile flag

GPIO topic


Equipment checklist

Right side cover karo aur parent note padhne se pehle har ek ka jawaab do:

Voltage kya hai, ek picture mein?
Wire ke electrical push ki height, ground (floor) ke relative measure ki gayi.
ka kya matlab hai aur uski voltage kya hai?
Ground — agreed zero-height reference, V ke roop mein define kiya gaya.
kya represent karta hai?
Chip ki supply voltage — top rail / ceiling (jaise 3.3 V ya 5 V).
HIGH aur LOW kaunsi logic values aur kaunsi heights se correspond karte hain?
HIGH = logic 1 = ke paas; LOW = logic 0 = ke paas.
Input pin aur output pin mein kya fark hai?
Output wire ko ek chosen level par drive (push) karta hai; input wire ko sense (feel) karta hai bina use force kiye.
Ohm's Law aur uska rearranged form batao jo topic use karta hai.
, rearranged to .
3.3 V pin ke liye 100 µA capped ho toh kaunsi pull-up value milegi?
.
High-impedance (Hi-Z) ka kya matlab hai?
Resistance itni badi ki essentially koi current flow nahi karta — wire disconnected act karti hai.
Floating pin kya hai aur yeh bura kyun hai?
Ek undriven input jo noise pick up karta hai aur random 1 ya 0 read karta hai.
Pull-up vs pull-down: dono kaunsa idle level dete hain?
Pull-up → idle HIGH (1); pull-down → idle LOW (0).
Button ke liye "active-LOW" ka kya matlab hai?
Idle 1 read karta hai; press event pin ko 0 par drive karta hai.
Rising edge aur falling edge define karo.
Rising = ; falling = — woh instant jab level change hota hai.
ISR kya hai?
Interrupt Service Routine — woh function jisme CPU jump karta hai jab interrupt fire hota hai.
ISR-shared flag volatile kyun hona chahiye?
Taaki compiler ise har baar memory se re-read kare na ki stale copy cache kare.