Clarify DCMotor sample pin numbering and H-bridge wiring#2583
Conversation
|
|
||
| All pin numbers passed to `DCMotor.Create` use the **logical (BCM/Broadcom)** GPIO numbering scheme, not the physical header positions. See the [Raspberry Pi GPIO pinout](https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#gpio) to map BCM numbers to physical pins. | ||
|
|
||
| The 3-pin sample `DCMotor.Create(6, 27, 22)` connects to an H-bridge (e.g. L298N) as follows: |
There was a problem hiding this comment.
@copilot I would rather prefer that you mention explictly the rpi ping as GPIOxx. It is also better if you print the H-bridge pin numbers, in addition to the pin name
There was a problem hiding this comment.
Done in 98167b3. The Wiring table now uses explicit GPIOxx names for the Raspberry Pi pins (GPIO6/GPIO27/GPIO22) and lists the H-bridge input pin numbers alongside the names (ENA pin 6, IN1 pin 5, IN2 pin 7 on the L298). The sample comments were updated to match.
|
I approved, but don´t know this piece of hardware. |
There was a problem hiding this comment.
Pull request overview
Clarifies the DCMotor sample’s GPIO numbering scheme and documents how the DCMotor.Create(6, 27, 22) arguments map to typical H-bridge control inputs, so readers can wire hardware to match the sample.
Changes:
- Added BCM/GPIO numbering guidance and a pin-to-H-bridge mapping comment in the sample program.
- Added a new Wiring section in the DCMotor README with a mapping table and wiring notes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/devices/DCMotor/samples/Program.cs | Adds comments explaining BCM numbering and the 3-pin wiring mapping. |
| src/devices/DCMotor/README.md | Adds a Wiring section with BCM numbering guidance, mapping table, and wiring checklist. |
| // Pin numbers use the logical (BCM) numbering scheme (GPIOxx). See README.md for wiring details. | ||
| // 3 pin mode: GPIO6 -> ENA (pin 6, enable/PWM), GPIO27 -> IN1 (pin 5), GPIO22 -> IN2 (pin 7) on the H-bridge. |
|
|
||
| ## Wiring | ||
|
|
||
| All pin numbers passed to `DCMotor.Create` use the **logical (BCM/Broadcom)** GPIO numbering scheme (referred to as `GPIOxx`, e.g. `GPIO6`), not the physical header positions. See the [Raspberry Pi GPIO pinout](https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#gpio) to map `GPIOxx` numbers to physical pins. |
| | `Create` argument | Raspberry Pi pin | H-bridge input (pin) | Purpose | | ||
| | ----------------- | ---------------- | -------------------- | ------- | | ||
| | `speedControlPin` | GPIO6 | ENA (pin 6) | PWM speed control | | ||
| | `directionPin` | GPIO27 | IN1 (pin 5) | Motor direction | | ||
| | `otherDirectionPin` | GPIO22 | IN2 (pin 7) | Opposite of IN1 | |
The DCMotor sample uses
DCMotor.Create(6, 27, 22)but never documents that these are BCM (logical) GPIO numbers, nor which argument maps to which H-bridge input — making it impossible to wire the H-bridge to match the code. The maintainer confirmed the pins are BCM numbering.Documentation/comment-only change; no motor control logic touched.
Changes
README.md: Added a Wiring section stating pins use BCM numbering (with a link to the Raspberry Pi pinout), plus a table mapping eachCreateargument to its BCM pin and H-bridge input, and the remaining wiring notes as a bullet list. Kept the embedded code block in sync with the sample.samples/Program.cs: Added comments noting BCM numbering and the pin→H-bridge mapping, pointing to the README.Pin mapping (3-pin mode)
CreateargumentspeedControlPindirectionPinotherDirectionPinNote: the Fritzing diagram (
dcmotor_bb.png) was not regenerated; the docs now explicitly state the numbering scheme so the code and diagram can be reconciled by a reviewer with the hardware.