Giter Club home page Giter Club logo

l298n-module-extended-lib's Introduction

L298N Library

An easy to use L298N library to control DC Motors with Arduino.

NOTICE

As you know, any L298N module has the ability to drive two motors at once, but you may not know that one instance of the library is intended to pilot only one motor. So if you need to drive two motors, you have to instantiate two L298N objects (one for each motor).

To instantiate both motors at once use the L298NX2 variant of the library.

L298NX2 is not a new version of module or IC, but it stands for a double implementation of L298N library.

INSTALL THE LIBRARY

Download this repository as a .zip file and from the Arduino IDE go to Sketch -> Include library -> Add .ZIP Library

IMPORT

You can import the library in your code using the Arduino IDE going to Sketch -> Include library -> L298N or directly writing the include statement in your code:

// For single motor instance
#include <L298N.h>
// For two motors instance at once
#include <L298NX2.h>

INSTANTIATE THE MODULE

To drive a motor the first thing is to create an instance of the library.

// With Enable pin to control speed
L298N myMotor(EN, IN1, IN2);
// Without Enable pin with jumper in place
L298N myMotor(IN1, IN2);
  • EN = is the Arduino pin (requires a PWM pin) connected to the Enable pin of the module
  • IN1 and IN2 are the two digital pins connected to IN1 and IN2 pins of the module

Same thing for L298NX2 variant

// With Enable pin to control speed

                     motor A            motor B
              |------------------||------------------|
L298NX2 myMotors(EN_A, IN1_A, IN2_A, EN_B, IN1_B, IN2_B);
// Without Enable pin and jumper in place

                  motor A      motor B
              |------------||------------|
L298NX2 myMotors(IN1_A, IN2_A, IN1_B, IN2_B);

L298N Methods

Method Params Description
setSpeed unsigned short pwmVal Set the PWM value used to determine the motor speed. Value from 0 to 255.
getSpeed none Get the speed previously set.
forward none Run motor in forward direction (depends on wiring).
forwardFor unsigned long delay Run motor in forward direction for a time specified by delay.
forwardFor unsigned long delay, CallBackFunction callback Run motor in forward direction for a time specified by delay, after moving execute a callback function.
backward none Run motor in backward direction (depends on wiring).
backwardFor unsigned long delay Run motor in backward direction for a time specified by delay.
backwardFor unsigned long delay, CallBackFunction callback Run motor in backward direction for a time specified by delay, after moving execute a callback function.
run uint8_t direction Move motor. To specify the direction use one of L298N::FORWARD, L298N::BACKWARD or L298N::STOP.
runFor unsigned long delay, L298N::Direction direction Like forwardFor or backwardFor but more flexible. To specify the direction use one of L298N::FORWARD, L298N::BACKWARD or L298N::STOP.
runFor unsigned long delay, L298N::Direction direction, CallBackFunction callback Like previous with the ability to execute a callback function.
stop none Stop the motor.
reset none Used to re-enable motor movements after the use of runFor, forwardFor or backwardFor methods.
isMoving none Returns a boolean indicating if motor is running or not.
getDirection none Returns the current L298N::Direction.

Direction

Constant Int Value
L298N::FORWARD 0
L298N::BACKWARD 1
L298N::STOP -1

L298NX2 Methods

L298NX2 have the same methods of L298N identified by A or B suffix to drive each motor. For example setSpeed for motor A is setSpeedA and setSpeedB for motor B.

Methods without suffix, will affects both motors.

Method Params
setSpeed unsigned short pwmVal
forward none
forwardFor unsigned long delay, CallBackFunction callback
forwardFor unsigned long delay
backward none
backwardFor unsigned long delay, CallBackFunction callback
backwardFor unsigned long delay
run uint8_t direction
runFor unsigned long delay, L298N::Direction direction
runFor unsigned long delay, L298N::Direction direction, CallBackFunction callback
stop none
reset none

Examples

Examples can be founds in the examples folder or if installed in Arduino IDE, by the Menu -> File -> Example -> L298N.

Wiring schema can be found in schema folder.

Donations

Coffees are accepted! :coffee: PayPal Donations Here โ˜•

paypal

l298n-module-extended-lib's People

Contributors

andrealombardo avatar ssxxaa avatar beestarbush avatar tomasroj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.