Add GPIO beginners guide and fix incorrect API references in libgpiod docs#2493
Add GPIO beginners guide and fix incorrect API references in libgpiod docs#2493
Conversation
… docs Agent-Logs-Url: https://github.com/dotnet/iot/sessions/125709c9-1313-48ad-8388-a71a2989a941 Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
… button logic Agent-Logs-Url: https://github.com/dotnet/iot/sessions/125709c9-1313-48ad-8388-a71a2989a941 Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
|
@copilot please preserve paths from the original PR |
….md, fundamentals/gpio-basics.md, fundamentals/choosing-drivers.md) Agent-Logs-Url: https://github.com/dotnet/iot/sessions/c24b48b9-932c-4ad1-a39d-b2fca64a84a2 Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
|
|
||
| ## What You Need | ||
|
|
||
| - A **Raspberry Pi** (3, 4, or 5) running Raspberry Pi OS |
There was a problem hiding this comment.
any gpio board should be ok as long as it has unix and libgpiod installed
There was a problem hiding this comment.
One of the Raspberry Pis can be mentioned as an example though
There was a problem hiding this comment.
Updated in 7f680f7 — "What You Need" now says "A Linux single-board computer with GPIO headers and libgpiod installed" with Raspberry Pi mentioned as an example.
| using System.Device.Gpio; | ||
| using System.Threading; | ||
|
|
||
| const int ledPin = 18; // GPIO 18 = physical pin 12 on Raspberry Pi |
There was a problem hiding this comment.
would be nice to point to https://pinout.xyz/ for reference
There was a problem hiding this comment.
Added in 7f680f7 — the quick-start code comment now includes a link to pinout.xyz: // GPIO 18 = physical pin 12 on Raspberry Pi (see https://pinout.xyz/)
| controller.OpenPin(18, PinMode.Output); | ||
|
|
||
| // Input with pull-up resistor (default HIGH, button press = LOW) | ||
| controller.OpenPin(17, PinMode.InputPullUp); |
There was a problem hiding this comment.
there is no background on what input is and how it works or connect but we're going straight from output tutorial to pull downs/ups
There was a problem hiding this comment.
Added a new "Digital Input" section in 7f680f7 that introduces what input is, shows a basic read example, illustrates button wiring, and explains why InputPullUp is needed — all before presenting the pin modes table.
| 4. **Use resistors with LEDs** — Calculate the value or use 220 Ω as a safe default | ||
| 5. **Check pin assignments** — Some GPIO pins are shared with I2C, SPI, or UART; using them for general GPIO disables those interfaces | ||
| 6. **Document your pin usage** — Especially in projects using multiple pins | ||
|
|
There was a problem hiding this comment.
@copilot you should mention that this will lead to 15mA current. Therefore a normal 20mA led is expected in this example and that high-brightness leds should not be attached to GPIO directly.
There was a problem hiding this comment.
Added in 7f680f7 — both the "Driving an LED" section and the best practices list now mention the ~15 mA current with a 220 Ω resistor, that this is fine for standard 20 mA indicator LEDs, and that high-brightness/power LEDs should not be connected to GPIO directly.
…uction, add LED current notes Agent-Logs-Url: https://github.com/dotnet/iot/sessions/c7565b37-f74a-44ad-8f38-5993f685f665 Co-authored-by: raffaeler <5183152+raffaeler@users.noreply.github.com>
| | `LibGpiodDriver` | Modern Linux with libgpiod v1 — the recommended default | | ||
| | `LibGpiodV2Driver` | Modern Linux with libgpiod v2 | | ||
| | `RaspberryPi3Driver` | Raspberry Pi 3/4 — auto-selected, legacy direct memory access | | ||
| | `SysFsDriver` | Very old Linux kernels (pre-4.8) only — **deprecated** | |
There was a problem hiding this comment.
should probably also mention that it's very slow but also supported on any linux version
There was a problem hiding this comment.
Updated in b1791c7 — SysFsDriver now reads: "Very slow but works on any Linux version — deprecated".
| | --- | --- | | ||
| | `LibGpiodDriver` | Modern Linux with libgpiod v1 — the recommended default | | ||
| | `LibGpiodV2Driver` | Modern Linux with libgpiod v2 | | ||
| | `RaspberryPi3Driver` | Raspberry Pi 3/4 — auto-selected, legacy direct memory access | |
There was a problem hiding this comment.
it should focus on "very fast because of direct memory access" but also requires root permissions and it's not recommended way. For certain cases it's necessary to use it
There was a problem hiding this comment.
Updated in b1791c7 — RaspberryPi3Driver now reads: "very fast (direct memory access) but requires root permissions; not recommended unless you specifically need the performance".
|
|
||
| ## Raspberry Pi 5 Note | ||
|
|
||
| Raspberry Pi 5 moved its GPIO to a different chip number. If you are explicitly constructing a driver, use chip **4** instead of 0: |
There was a problem hiding this comment.
This has been fixed in the recent versions of the kernel, no need to mention that really or mention that if 0 doesn't work and you're on pi 5 then occasionally it may be 4 but it's recommended to update kernel instead. You may also add tiny bash snippet how to detect it by looking at number of pins on each chip
There was a problem hiding this comment.
maybe troubleshooting section for this
There was a problem hiding this comment.
Reworked in b1791c7 — removed the dedicated Pi 5 section and moved it to a "Wrong GPIO Chip on Raspberry Pi 5" troubleshooting entry. It now recommends updating the kernel first, and includes a bash snippet to detect the correct chip by counting lines on each /dev/gpiochip*.
| @@ -0,0 +1,292 @@ | |||
| # GPIO (General-Purpose Input/Output) | |||
There was a problem hiding this comment.
Added in b1791c7 — table of contents with links to all sections.
|
@copilot please fix the comments |
…sue to troubleshooting Agent-Logs-Url: https://github.com/dotnet/iot/sessions/150e5c2f-9425-4ea1-8bb6-d2655685087e Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/iot/sessions/150e5c2f-9425-4ea1-8bb6-d2655685087e Co-authored-by: krwq <660048+krwq@users.noreply.github.com>
Extracts GPIO documentation from #2438, rewritten for newcomers to IoT. Preserves the directory structure from the original PR (
protocols/,fundamentals/). Removes irrelevant topics (Docker, deployment, systemd). Also fixes incorrect API references in the existinggpio-linux-libgpiod.md.New:
Documentation/protocols/gpio.mdMain GPIO protocol guide covering:
New:
Documentation/fundamentals/gpio-basics.mdDeep dive on GPIO fundamentals:
New:
Documentation/fundamentals/choosing-drivers.mdDriver selection guide:
Fixed:
Documentation/gpio-linux-libgpiod.mdThe existing doc had three references to API surface that doesn't exist:
Also fixed variable name mismatch (
gpioControllervscontroller) in the blink example, and documented thatLibGpiodDriverandLibGpiodV2Driverare separate classes (not selected via an enum).Updated:
Documentation/README.mdAdded links to all new GPIO guides in the GPIO section.