diff --git a/src/devices/DCMotor/README.md b/src/devices/DCMotor/README.md index 3ac8330371..fa455bb2f7 100644 --- a/src/devices/DCMotor/README.md +++ b/src/devices/DCMotor/README.md @@ -37,6 +37,8 @@ static void Main(string[] args) // using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 0, frequency: 50), 23, 24)) // Start Stop mode - wrapper with additional methods to disable/enable output regardless of the Speed value // using (DCMotorWithStartStop motor = new DCMotorWithStartStop(DCMotor.Create( _any version above_ ))) + // Pin numbers use the logical (BCM) numbering scheme (GPIOxx). See the Wiring section below. + // 3 pin mode: GPIO6 -> ENA (pin 6, enable/PWM), GPIO27 -> IN1 (pin 5), GPIO22 -> IN2 (pin 7) on the H-bridge. using (DCMotor motor = DCMotor.Create(6, 27, 22)) { bool done = false; @@ -66,6 +68,26 @@ static void Main(string[] args) } ``` +## 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. + +The 3-pin sample `DCMotor.Create(6, 27, 22)` connects to an H-bridge (e.g. the L298 IC) as follows: + +| `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 rest of the wiring: + +- The H-bridge outputs drive the motor. +- The motor power supply connects to the H-bridge (never directly to the board). +- The board and H-bridge grounds are connected together. + +See the diagram below. + ![schematics](./dcmotor_bb.png) ![BiDirectional Pin schematics](./DCMotor2pinWithBiDirectionalPin_bb.png) diff --git a/src/devices/DCMotor/samples/Program.cs b/src/devices/DCMotor/samples/Program.cs index 4abf66f6d3..b294faf386 100644 --- a/src/devices/DCMotor/samples/Program.cs +++ b/src/devices/DCMotor/samples/Program.cs @@ -24,6 +24,8 @@ // using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 0, frequency: 50), 23, 24)) // Start Stop mode - additional methods to disable/enable output regardless of the Speed value // using (DCMotorWithStartStop motor = new DCMotorWithStartStop(DCMotor.Create( _any version above_ ))) +// 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. using DCMotor motor = DCMotor.Create(6, 27, 22); bool done = false; Console.CancelKeyPress += (o, e) =>