Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/devices/DCMotor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. See the Wiring section below.
// 3 pin mode: 6 -> ENA (enable/PWM), 27 -> IN1, 22 -> IN2 on the H-bridge.
using (DCMotor motor = DCMotor.Create(6, 27, 22))
{
bool done = false;
Expand Down Expand Up @@ -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, 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.


| `Create` argument | BCM pin | H-bridge input | Purpose |
| ----------------- | ------- | -------------- | ------- |
| `speedControlPin` | 6 | ENA (enable) | PWM speed control |
| `directionPin` | 27 | IN1 | Motor direction |
| `otherDirectionPin` | 22 | IN2 | 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)
2 changes: 2 additions & 0 deletions src/devices/DCMotor/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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. See README.md for wiring details.
// 3 pin mode: 6 -> ENA (enable/PWM), 27 -> IN1, 22 -> IN2 on the H-bridge.
using DCMotor motor = DCMotor.Create(6, 27, 22);
bool done = false;
Console.CancelKeyPress += (o, e) =>
Expand Down