Motor Driver L298 Module

Last modified August 20, 2014

Motor Driver L298 Module

Required

Tutorials: First NETMF Project, Namespaces

Introduction

This motor driver module controls the speed and direction on 2 DC motors with a rating up to 40V 3A. The module itself is powered and controlled from a Gadgeteer mainboard but the motors are powered from a separate power source. Make sure to properly connect a power source to the green connector on the board so that the motors can receive power. 

The motors are marked M1 and M2 on the pcb, and the enum MotorControllerL298.Motor is matched to the pcb. Make sure to match your wiring and code to get the desired result.

Warning

Make sure not to exceed 40V or 3A or damage could occur to the board, the motors, or the mainboard.

Setting the Speed

You can control the speed of each motor individually. The below code sets the first motor to 100% speed, then 50%, then it stops it, then moves at 50% in reverse, and lastly at 100% in reverse followed by a complete stop.

using Gadgeteer.Modules.GHIElectronics;
using System.Threading;

namespace your_namespace
{
    public partial class Program
    {
        private void ProgramStarted()
        {
            this.motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, 1);
            Thread.Sleep(500);
            this.motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, 0.5);
            Thread.Sleep(500);
            this.motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, 0);
            Thread.Sleep(500);
            this.motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, -0.5);
            Thread.Sleep(500);
            this.motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, -1);
            Thread.Sleep(500);
            this.motorDriverL298.StopAll();
        }
    }
}
Tip

Depending on your motor, you may need to change the Frequency property that controls the frequency of the PWM signal sent to the module.

Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.