Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 (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;
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 (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 |
Comment on lines +77 to +81

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 (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.
Comment on lines +27 to +28
using DCMotor motor = DCMotor.Create(6, 27, 22);
bool done = false;
Console.CancelKeyPress += (o, e) =>
Expand Down
Loading