Skip to content

Clarify DCMotor sample pin numbering and H-bridge wiring#2583

Open
raffaeler with Copilot wants to merge 4 commits into
mainfrom
copilot/improve-dcmotor-example
Open

Clarify DCMotor sample pin numbering and H-bridge wiring#2583
raffaeler with Copilot wants to merge 4 commits into
mainfrom
copilot/improve-dcmotor-example

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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 each Create argument 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)

Create argument BCM pin H-bridge input
speedControlPin 6 ENA (enable/PWM)
directionPin 27 IN1
otherDirectionPin 22 IN2

Note: 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.

Copilot AI linked an issue Jul 1, 2026 that may be closed by this pull request
@dotnet-policy-service dotnet-policy-service Bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jul 1, 2026
Copilot AI changed the title [WIP] Improve clarity on DCMotor example for H Bridge connections Clarify DCMotor sample pin numbering and H-bridge wiring Jul 1, 2026
Copilot AI requested a review from raffaeler July 1, 2026 14:20
Comment thread src/devices/DCMotor/README.md Outdated

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address this review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI requested a review from raffaeler July 1, 2026 14:47
@raffaeler

Copy link
Copy Markdown
Contributor

I approved, but don´t know this piece of hardware.
Is there anyone that knows if the mappings are good?

@raffaeler raffaeler marked this pull request as ready for review July 1, 2026 15:11
Copilot AI review requested due to automatic review settings July 1, 2026 15:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +27 to +28
// 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.
Comment on lines +77 to +81
| `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 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DCMotor example improvement

3 participants