DFRobot Motorshield L298N and L293

This information works for both the Arduino Motor Shield L298N and L293

Shield connections

There are four shield connections H-Bridge-compatible:
  • Two speed pins D6 for motor 1, D5 for motor 2
  • Two direction pins D7 for motor 1, D4 for motor 2
Some older versions of the L293 uses pin D8 instead of D4

Sample code in C#

// This pin-layout counts for the following DFRobot Motorshields:
// - Arduino Motor Shield (L298N)
// - Arduino Motor Shield (L293)
HBridge MotorDriver = new HBridge(New Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, New Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D4);
// Older versions of the L293 use pin 8 instead of 4. If that's the case, use the line below
// HBridge MotorDriver = new HBridge(New Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, New Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D8);

// Motor 1 half speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -50);
// Motor 2 half speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 50);

// Lets run for 5 seconds
Thread.Sleep(5000);

// Motor 1 full speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -100);
// Motor 2 full speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 100);

// Lets run for 5 seconds
Thread.Sleep(5000);

// Stops both motors
MotorDriver.SetState(HBridge.Motors.Motor1, 0);
MotorDriver.SetState(HBridge.Motors.Motor2, 0);

Sample code in VB

' This pin-layout counts for the following DFRobot Motorshields:
' - Arduino Motor Shield (L298N)
' - Arduino Motor Shield (L293)
Dim MotorDriver As HBridge = New HBridge(New Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, New Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D4)
' Older versions of the L293 use pin 8 instead of 4. If that's the case, use the line below
' Dim MotorDriver As HBridge = New HBridge(New Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, New Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D8)

' Motor 1 half speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -50)
' Motor 2 half speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 50)

' Lets run for 5 seconds
Thread.Sleep(5000)

' Motor 1 full speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -100)
' Motor 2 full speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 100)

' Lets run for 5 seconds
Thread.Sleep(5000)

' Stops both motors
MotorDriver.SetState(HBridge.Motors.Motor1, 0)
MotorDriver.SetState(HBridge.Motors.Motor2, 0)

Last edited Jun 4, 2012 at 8:17 AM by Garrcomm, version 4