├── Changelog.md
├── LICENSE.md
├── README.md
├── examples
├── MotorControl_Demo
│ └── MotorControl_Demo.ino
└── SerialMotorControl
│ └── SerialMotorControl.ino
├── extras
├── L293_standalone-HW-conf.png
└── L293_twoWire-HW-conf.png
├── keywords.txt
├── library.properties
└── src
├── L293.h
├── L293_base.cpp
├── L293_base.hpp
├── L293_std.cpp
├── L293_std.hpp
├── L293_twoWire.cpp
└── L293_twoWire.hpp
/Changelog.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](http://keepachangelog.com/)
5 | and this project adheres to [Semantic Versioning](http://semver.org/).
6 |
7 | [](http://keepachangelog.com)
8 | [](http://semver.org)
9 |
10 | ## [4.0.2] - 2018-07-19 ##
11 |
12 | ## Fixed ##
13 |
14 | - Keyword highlighting for Arduino IDE
15 |
16 | ## [4.0.1] - 2018-02-28 ##
17 |
18 | ## Fixed ##
19 |
20 | - A bug that prevented the use of the library
21 |
22 | ## [4.0.0] - 2018-02-18 [YANKED] ##
23 |
24 | ### Added ###
25 |
26 | - Platformio library manager support
27 |
28 | ## Changed ##
29 |
30 | - Improved code safety and cleaning
31 |
32 | ### Removed ###
33 |
34 | - The ***getDirection()*** method
35 |
36 | ## [3.1.0] - 2017-06-17 ##
37 |
38 | ### Added ###
39 |
40 | - The following methods to detect the motor's status:
41 | - ***isForceStopped()***
42 | - ***isStopped()***
43 | - ***isForward()***
44 | - ***isReverse()***
45 | - Better Doxigen-style comments
46 |
47 | ### Changed ###
48 |
49 | - This changelog format is now based on [Keep a Changelog](http://keepachangelog.com/)
50 | - Rewrote the changelog to accomplish what about the previous point
51 | - Renamed the changelog file for the same purpose
52 | - **Updated the repository URL**
53 | - Updated **README.md**
54 | - Made the code more modular and extensible
55 | - Made a general cleanup of the code
56 | - Merged the examples that share most code
57 |
58 | ### Deprecated ###
59 |
60 | - The ***getDirection()*** method is now replaced by the methods ***isForward(), isReverse(), isStopped()*** and ***isForceStopped()***
61 |
62 | ## [3.0.0] - 2017-01-04 ##
63 |
64 | ### Added ###
65 |
66 | - Now is possible to change the motor direction without affect the current speed using a dedicated method
67 | - A method to get the direction of the motor
68 | - A method to get the current PWM value
69 | - A method to **"force stop"** the motor
70 |
71 | ### Changed ###
72 |
73 | - Updated **README.md**
74 | - Now the class **L293\_standalone** is named **L293**
75 | - Rewrote the code for the **L293** class
76 | - Now the method **setSpeedOffset()** is named **setPWMOffset()**
77 |
78 | ### Fixed ###
79 |
80 | - A bug about the timing when switching a motor from the forward mode to the reverse mode and viceversa, now it is immediate
81 |
82 | ## [2.0.0] - 2016-10-16 ##
83 |
84 | ### Added ###
85 |
86 | - A new class named **L293\_twoWire**, derived from **L293\_standalone**, that adds support for motor control using only two wires.
87 | - Better comments to the code
88 | - The file **LICENSE.md**
89 | - New examples
90 |
91 | ### Changed ###
92 |
93 | - Corrected some mistakes in **README.md**
94 | - Updated the old examples
95 | - Now the class **L293** is named **L293\_ standalone**
96 | - Now the **speed Offset** can be a value beetween -255 and 255
97 |
98 | ## [1.0.1] - 2016-08-25 ##
99 |
100 | ### Removed ###
101 |
102 | - Some useless code
103 |
104 | ### Changed ###
105 |
106 | - Updated the repository URL
107 | - Rewrited **README.md**
108 |
109 | ## [1.0.0] - 2016-08-11 ##
110 |
111 | ### Added ###
112 |
113 | - Unreleased library files
114 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Attribution-ShareAlike 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More_considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution-ShareAlike 4.0 International Public
58 | License
59 |
60 | By exercising the Licensed Rights (defined below), You accept and agree
61 | to be bound by the terms and conditions of this Creative Commons
62 | Attribution-ShareAlike 4.0 International Public License ("Public
63 | License"). To the extent this Public License may be interpreted as a
64 | contract, You are granted the Licensed Rights in consideration of Your
65 | acceptance of these terms and conditions, and the Licensor grants You
66 | such rights in consideration of benefits the Licensor receives from
67 | making the Licensed Material available under these terms and
68 | conditions.
69 |
70 |
71 | Section 1 -- Definitions.
72 |
73 | a. Adapted Material means material subject to Copyright and Similar
74 | Rights that is derived from or based upon the Licensed Material
75 | and in which the Licensed Material is translated, altered,
76 | arranged, transformed, or otherwise modified in a manner requiring
77 | permission under the Copyright and Similar Rights held by the
78 | Licensor. For purposes of this Public License, where the Licensed
79 | Material is a musical work, performance, or sound recording,
80 | Adapted Material is always produced where the Licensed Material is
81 | synched in timed relation with a moving image.
82 |
83 | b. Adapter's License means the license You apply to Your Copyright
84 | and Similar Rights in Your contributions to Adapted Material in
85 | accordance with the terms and conditions of this Public License.
86 |
87 | c. BY-SA Compatible License means a license listed at
88 | creativecommons.org/compatiblelicenses, approved by Creative
89 | Commons as essentially the equivalent of this Public License.
90 |
91 | d. Copyright and Similar Rights means copyright and/or similar rights
92 | closely related to copyright including, without limitation,
93 | performance, broadcast, sound recording, and Sui Generis Database
94 | Rights, without regard to how the rights are labeled or
95 | categorized. For purposes of this Public License, the rights
96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
97 | Rights.
98 |
99 | e. Effective Technological Measures means those measures that, in the
100 | absence of proper authority, may not be circumvented under laws
101 | fulfilling obligations under Article 11 of the WIPO Copyright
102 | Treaty adopted on December 20, 1996, and/or similar international
103 | agreements.
104 |
105 | f. Exceptions and Limitations means fair use, fair dealing, and/or
106 | any other exception or limitation to Copyright and Similar Rights
107 | that applies to Your use of the Licensed Material.
108 |
109 | g. License Elements means the license attributes listed in the name
110 | of a Creative Commons Public License. The License Elements of this
111 | Public License are Attribution and ShareAlike.
112 |
113 | h. Licensed Material means the artistic or literary work, database,
114 | or other material to which the Licensor applied this Public
115 | License.
116 |
117 | i. Licensed Rights means the rights granted to You subject to the
118 | terms and conditions of this Public License, which are limited to
119 | all Copyright and Similar Rights that apply to Your use of the
120 | Licensed Material and that the Licensor has authority to license.
121 |
122 | j. Licensor means the individual(s) or entity(ies) granting rights
123 | under this Public License.
124 |
125 | k. Share means to provide material to the public by any means or
126 | process that requires permission under the Licensed Rights, such
127 | as reproduction, public display, public performance, distribution,
128 | dissemination, communication, or importation, and to make material
129 | available to the public including in ways that members of the
130 | public may access the material from a place and at a time
131 | individually chosen by them.
132 |
133 | l. Sui Generis Database Rights means rights other than copyright
134 | resulting from Directive 96/9/EC of the European Parliament and of
135 | the Council of 11 March 1996 on the legal protection of databases,
136 | as amended and/or succeeded, as well as other essentially
137 | equivalent rights anywhere in the world.
138 |
139 | m. You means the individual or entity exercising the Licensed Rights
140 | under this Public License. Your has a corresponding meaning.
141 |
142 |
143 | Section 2 -- Scope.
144 |
145 | a. License grant.
146 |
147 | 1. Subject to the terms and conditions of this Public License,
148 | the Licensor hereby grants You a worldwide, royalty-free,
149 | non-sublicensable, non-exclusive, irrevocable license to
150 | exercise the Licensed Rights in the Licensed Material to:
151 |
152 | a. reproduce and Share the Licensed Material, in whole or
153 | in part; and
154 |
155 | b. produce, reproduce, and Share Adapted Material.
156 |
157 | 2. Exceptions and Limitations. For the avoidance of doubt, where
158 | Exceptions and Limitations apply to Your use, this Public
159 | License does not apply, and You do not need to comply with
160 | its terms and conditions.
161 |
162 | 3. Term. The term of this Public License is specified in Section
163 | 6(a).
164 |
165 | 4. Media and formats; technical modifications allowed. The
166 | Licensor authorizes You to exercise the Licensed Rights in
167 | all media and formats whether now known or hereafter created,
168 | and to make technical modifications necessary to do so. The
169 | Licensor waives and/or agrees not to assert any right or
170 | authority to forbid You from making technical modifications
171 | necessary to exercise the Licensed Rights, including
172 | technical modifications necessary to circumvent Effective
173 | Technological Measures. For purposes of this Public License,
174 | simply making modifications authorized by this Section 2(a)
175 | (4) never produces Adapted Material.
176 |
177 | 5. Downstream recipients.
178 |
179 | a. Offer from the Licensor -- Licensed Material. Every
180 | recipient of the Licensed Material automatically
181 | receives an offer from the Licensor to exercise the
182 | Licensed Rights under the terms and conditions of this
183 | Public License.
184 |
185 | b. Additional offer from the Licensor -- Adapted Material.
186 | Every recipient of Adapted Material from You
187 | automatically receives an offer from the Licensor to
188 | exercise the Licensed Rights in the Adapted Material
189 | under the conditions of the Adapter's License You apply.
190 |
191 | c. No downstream restrictions. You may not offer or impose
192 | any additional or different terms or conditions on, or
193 | apply any Effective Technological Measures to, the
194 | Licensed Material if doing so restricts exercise of the
195 | Licensed Rights by any recipient of the Licensed
196 | Material.
197 |
198 | 6. No endorsement. Nothing in this Public License constitutes or
199 | may be construed as permission to assert or imply that You
200 | are, or that Your use of the Licensed Material is, connected
201 | with, or sponsored, endorsed, or granted official status by,
202 | the Licensor or others designated to receive attribution as
203 | provided in Section 3(a)(1)(A)(i).
204 |
205 | b. Other rights.
206 |
207 | 1. Moral rights, such as the right of integrity, are not
208 | licensed under this Public License, nor are publicity,
209 | privacy, and/or other similar personality rights; however, to
210 | the extent possible, the Licensor waives and/or agrees not to
211 | assert any such rights held by the Licensor to the limited
212 | extent necessary to allow You to exercise the Licensed
213 | Rights, but not otherwise.
214 |
215 | 2. Patent and trademark rights are not licensed under this
216 | Public License.
217 |
218 | 3. To the extent possible, the Licensor waives any right to
219 | collect royalties from You for the exercise of the Licensed
220 | Rights, whether directly or through a collecting society
221 | under any voluntary or waivable statutory or compulsory
222 | licensing scheme. In all other cases the Licensor expressly
223 | reserves any right to collect such royalties.
224 |
225 |
226 | Section 3 -- License Conditions.
227 |
228 | Your exercise of the Licensed Rights is expressly made subject to the
229 | following conditions.
230 |
231 | a. Attribution.
232 |
233 | 1. If You Share the Licensed Material (including in modified
234 | form), You must:
235 |
236 | a. retain the following if it is supplied by the Licensor
237 | with the Licensed Material:
238 |
239 | i. identification of the creator(s) of the Licensed
240 | Material and any others designated to receive
241 | attribution, in any reasonable manner requested by
242 | the Licensor (including by pseudonym if
243 | designated);
244 |
245 | ii. a copyright notice;
246 |
247 | iii. a notice that refers to this Public License;
248 |
249 | iv. a notice that refers to the disclaimer of
250 | warranties;
251 |
252 | v. a URI or hyperlink to the Licensed Material to the
253 | extent reasonably practicable;
254 |
255 | b. indicate if You modified the Licensed Material and
256 | retain an indication of any previous modifications; and
257 |
258 | c. indicate the Licensed Material is licensed under this
259 | Public License, and include the text of, or the URI or
260 | hyperlink to, this Public License.
261 |
262 | 2. You may satisfy the conditions in Section 3(a)(1) in any
263 | reasonable manner based on the medium, means, and context in
264 | which You Share the Licensed Material. For example, it may be
265 | reasonable to satisfy the conditions by providing a URI or
266 | hyperlink to a resource that includes the required
267 | information.
268 |
269 | 3. If requested by the Licensor, You must remove any of the
270 | information required by Section 3(a)(1)(A) to the extent
271 | reasonably practicable.
272 |
273 | b. ShareAlike.
274 |
275 | In addition to the conditions in Section 3(a), if You Share
276 | Adapted Material You produce, the following conditions also apply.
277 |
278 | 1. The Adapter's License You apply must be a Creative Commons
279 | license with the same License Elements, this version or
280 | later, or a BY-SA Compatible License.
281 |
282 | 2. You must include the text of, or the URI or hyperlink to, the
283 | Adapter's License You apply. You may satisfy this condition
284 | in any reasonable manner based on the medium, means, and
285 | context in which You Share Adapted Material.
286 |
287 | 3. You may not offer or impose any additional or different terms
288 | or conditions on, or apply any Effective Technological
289 | Measures to, Adapted Material that restrict exercise of the
290 | rights granted under the Adapter's License You apply.
291 |
292 |
293 | Section 4 -- Sui Generis Database Rights.
294 |
295 | Where the Licensed Rights include Sui Generis Database Rights that
296 | apply to Your use of the Licensed Material:
297 |
298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
299 | to extract, reuse, reproduce, and Share all or a substantial
300 | portion of the contents of the database;
301 |
302 | b. if You include all or a substantial portion of the database
303 | contents in a database in which You have Sui Generis Database
304 | Rights, then the database in which You have Sui Generis Database
305 | Rights (but not its individual contents) is Adapted Material,
306 |
307 | including for purposes of Section 3(b); and
308 | c. You must comply with the conditions in Section 3(a) if You Share
309 | all or a substantial portion of the contents of the database.
310 |
311 | For the avoidance of doubt, this Section 4 supplements and does not
312 | replace Your obligations under this Public License where the Licensed
313 | Rights include other Copyright and Similar Rights.
314 |
315 |
316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
317 |
318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
328 |
329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
338 |
339 | c. The disclaimer of warranties and limitation of liability provided
340 | above shall be interpreted in a manner that, to the extent
341 | possible, most closely approximates an absolute disclaimer and
342 | waiver of all liability.
343 |
344 |
345 | Section 6 -- Term and Termination.
346 |
347 | a. This Public License applies for the term of the Copyright and
348 | Similar Rights licensed here. However, if You fail to comply with
349 | this Public License, then Your rights under this Public License
350 | terminate automatically.
351 |
352 | b. Where Your right to use the Licensed Material has terminated under
353 | Section 6(a), it reinstates:
354 |
355 | 1. automatically as of the date the violation is cured, provided
356 | it is cured within 30 days of Your discovery of the
357 | violation; or
358 |
359 | 2. upon express reinstatement by the Licensor.
360 |
361 | For the avoidance of doubt, this Section 6(b) does not affect any
362 | right the Licensor may have to seek remedies for Your violations
363 | of this Public License.
364 |
365 | c. For the avoidance of doubt, the Licensor may also offer the
366 | Licensed Material under separate terms or conditions or stop
367 | distributing the Licensed Material at any time; however, doing so
368 | will not terminate this Public License.
369 |
370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
371 | License.
372 |
373 |
374 | Section 7 -- Other Terms and Conditions.
375 |
376 | a. The Licensor shall not be bound by any additional or different
377 | terms or conditions communicated by You unless expressly agreed.
378 |
379 | b. Any arrangements, understandings, or agreements regarding the
380 | Licensed Material not stated herein are separate from and
381 | independent of the terms and conditions of this Public License.
382 |
383 |
384 | Section 8 -- Interpretation.
385 |
386 | a. For the avoidance of doubt, this Public License does not, and
387 | shall not be interpreted to, reduce, limit, restrict, or impose
388 | conditions on any use of the Licensed Material that could lawfully
389 | be made without permission under this Public License.
390 |
391 | b. To the extent possible, if any provision of this Public License is
392 | deemed unenforceable, it shall be automatically reformed to the
393 | minimum extent necessary to make it enforceable. If the provision
394 | cannot be reformed, it shall be severed from this Public License
395 | without affecting the enforceability of the remaining terms and
396 | conditions.
397 |
398 | c. No term or condition of this Public License will be waived and no
399 | failure to comply consented to unless expressly agreed to by the
400 | Licensor.
401 |
402 | d. Nothing in this Public License constitutes or may be interpreted
403 | as a limitation upon, or waiver of, any privileges and immunities
404 | that apply to the Licensor or You, including from the legal
405 | processes of any jurisdiction or authority.
406 |
407 |
408 | =======================================================================
409 |
410 | Creative Commons is not a party to its public
411 | licenses. Notwithstanding, Creative Commons may elect to apply one of
412 | its public licenses to material it publishes and in those instances
413 | will be considered the “Licensor.” The text of the Creative Commons
414 | public licenses is dedicated to the public domain under the CC0 Public
415 | Domain Dedication. Except for the limited purpose of indicating that
416 | material is shared under a Creative Commons public license or as
417 | otherwise permitted by the Creative Commons policies published at
418 | creativecommons.org/policies, Creative Commons does not authorize the
419 | use of the trademark "Creative Commons" or any other trademark or logo
420 | of Creative Commons without its prior written consent including,
421 | without limitation, in connection with any unauthorized modifications
422 | to any of its public licenses or any other arrangements,
423 | understandings, or agreements concerning use of licensed material. For
424 | the avoidance of doubt, this paragraph does not form part of the
425 | public licenses.
426 |
427 | Creative Commons may be contacted at creativecommons.org.
428 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # L293 #
2 |
3 | 
4 | [](https://github.com/qub1750ul/Arduino_L293/blob/master/LICENSE.md)
5 | [](https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification)
6 | [](https://www.arduino.cc/en/Main/Software)
7 | [](http://keepachangelog.com)
8 | [](http://semver.org)
9 |
10 | An Arduino library that allows to control bidirectional motors using the L293 IC and compatible L298 boards.
11 |
12 | ## Description ##
13 |
14 | This library is designed to make easy the control of bidirectional motors either for beginners or for experts, providing a level of abstraction over the direct "lower-level" management of the MCU I/O ports that drive the H-bridge(s).
15 |
16 | This means that the programmer haven't to care about the implementation of the control code and timings and can focus on the desired behavior.
17 |
18 | The main goal of this library is to be simple to use for beginners but flexible for experts.
19 |
20 | [Checkout the wiki for more information](https://github.com/qub1750ul/Arduino_L293/wiki/)
21 |
22 | ## About the author & license info ##
23 |
24 |
25 |
26 |
27 |
28 | The L293 Library
29 | by Giuseppe Masino
30 | is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
31 |
32 | If you need permissions that are beyond the scope of this license, you can ask me through this contacts,
33 | in order of preference:
34 |
35 | - Telegram : https://telegram.me/qub1750ul
36 | - Twitter : https://twitter.com/qub1750ul
37 | - Facebook page : https://facebook.com/dev.giuseppemasino/
38 |
39 | The license text can be found in the LICENSE.md file
40 |
--------------------------------------------------------------------------------
/examples/MotorControl_Demo/MotorControl_Demo.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Bidirectional Motor Control with standalone L293
3 | *
4 | * Example of using L293 library to control one or more DC Birirectional Motors with the standalone configuration of the L293
5 | *
6 | * Created by Giuseppe Masino, 25 may 2016
7 | * Author URL http://www.facebook.com/dev.giuseppemasino
8 | *
9 | * This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
10 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
11 | * -----------------------------------------------------------------------------------
12 | *
13 | * Things that you need:
14 | * - Arduino\Genuino MEGA2560
15 | * (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino)
16 | * (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled)
17 | * (use of pin 13 is discouraged because it can cause issues when the board resets)
18 | *
19 | * - L293
20 | * - A DC Birirectional Motor (max 5V-4mA)
21 | *
22 | * -----------------------------------------------------------------------------
23 | *
24 | * The circuit ( standalone version ):
25 | * - Arduino pin 2 -> L293 pin 1
26 | * - Arduino pin 3 -> L293 pin 2
27 | * - Arduino pin 4 -> L293 pin 7
28 | * - Arduino GND -> L293 pin 4, 5
29 | * - Arduino 5V -> L293 pin 16, 8
30 | *
31 | * - L293 pin 3 -> a terminal of the motor
32 | * - L293 pin 6 -> the other terminal of the motor
33 | *
34 | * The circuit ( twoWire version ):
35 | * https://github.com/qub1750ul/Arduino_L293/blob/master/extras/L293_twoWire.svg
36 | *
37 | */
38 |
39 | // by default this example uses the standalone version of the library
40 | // comment out the following row to switch to the twoWire version
41 | #define use_standalone
42 |
43 | // import the library in the sketch
44 | #include
45 |
46 | // give a name to the pins that we use
47 | const int speedPin = 2; // that is the pin that we use to control the motor's speed
48 | const int forwardPin = 3; // this is the pin that we use to tell the motor to go forward
49 | const int reversePin = 4; // this is the pin that we use to tell the motor to go reverse
50 |
51 | #ifdef use_standalone
52 |
53 | // make a new instance of the L293 library and call it "motor"
54 | // then show what are the pins used to control speed, to tell the motor to go forward and to tell the motor to go reverse
55 | L293 motor( speedPin, forwardPin, reversePin );
56 |
57 | #else
58 |
59 | // if you using the twoWire version of the library only one pin is required to tell the direction
60 | // the forwardPin can do the job of the directionPin in this case
61 | L293_twoWire motor( speedPin, forwardPin );
62 |
63 | #endif
64 |
65 | void setup()
66 | {
67 | // nothing to do in setup()
68 | }
69 |
70 | void loop()
71 | {
72 | motor.forward( 255 ); // set the direction and the speed of the motor
73 | delay( 1000 ); // wait for 1 second before doing else
74 | motor.back( 255 ); // set a new direction and the speed of the motor
75 | delay( 1000 ); // wait for 1 second before doing else
76 | motor.stop(); // stop the motor
77 | delay( 1000 ); // wait for 1 second before doing else
78 |
79 | // now the loop restarts
80 | }
81 |
--------------------------------------------------------------------------------
/examples/SerialMotorControl/SerialMotorControl.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Serial Bidirectional Motor Control
3 | *
4 | * Example of using L293 library to control one or more DC Birirectional Motors via the Serial line
5 | *
6 | * Created by Giuseppe Masino, 28 may 2016
7 | * Author URL http://www.facebook.com/peppe.masino1
8 | *
9 | * This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
10 | * To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/. *
11 | * -----------------------------------------------------------------------------
12 | *
13 | * Things that you need:
14 | * - Arduino\Genuino MEGA2560
15 | * (any Arduino\Genuino board can be used, the important is that the L293 pin 1 is connected to a PWM-enabled pin of Arduino)
16 | * (on the Arduino MEGA2560 all pins from 2 to 13 are PWM-enabled)
17 | * (use of pin 13 is discouraged because it can cause issues when the board resets)
18 | *
19 | * - L293
20 | * - A DC Birirectional Motor (max 5V-4mA)
21 | *
22 | * -----------------------------------------------------------------------------
23 | *
24 | * The circuit ( standalone version ):
25 | * - Arduino pin 2 -> L293 pin 1
26 | * - Arduino pin 3 -> L293 pin 2
27 | * - Arduino pin 4 -> L293 pin 7
28 | * - Arduino GND -> L293 pin 4, 5
29 | * - Arduino 5V -> L293 pin 16, 8
30 | *
31 | * - L293 pin 3 -> a terminal of the motor
32 | * - L293 pin 6 -> the other terminal of the motor
33 | *
34 | * The circuit ( twoWire version ):
35 | * https://github.com/qub1750ul/Arduino_L293/blob/master/extras/L293_twoWire.svg
36 | *
37 | */
38 |
39 | // by default this example uses the standalone version of the library
40 | // comment out the following row to switch to the twoWire version
41 | #define use_standalone
42 |
43 |
44 | // import the library in the sketch
45 | #include
46 |
47 | // these are constants and won't change
48 | // give a name to the pins that you use
49 | const int speedPin = 2; // that is the pin that we use to control the motor's speed
50 | const int forwardPin = 3; // this is the pin that we use to tell the motor to go forward
51 | const int reversePin = 4; // this is the pin that we use to tell the motor to go reverse
52 |
53 | #ifdef use_standalone
54 |
55 | // make a new istance of the L293 library and call it "motor"
56 | // then show what are the pins used to control speed, to tell the motor to go forward and to tell the motor to go reverse
57 | L293 motor( speedPin, forwardPin, reversePin );
58 |
59 | #else
60 |
61 | // if you using the twoWire version of the library only one pin is required to tell the direction
62 | // the forwardPin can do the job of the directionPin in this case
63 | L293_twoWire motor( speedPin, forwardPin );
64 |
65 | #endif
66 |
67 | void setup()
68 | {
69 | // these istructions will be executed one time
70 |
71 | Serial.begin( 9600 ); //enable serial communication
72 | }
73 |
74 | void loop()
75 | {
76 | if ( Serial.available() > 0 ) //check if there is an incoming command on the serial line
77 | {
78 | String command = Serial.readString(); //store the command in a variable
79 |
80 | // select the proper action
81 | if ( command == "f" ) motor.forward( 255 );
82 | else if ( command == "r" ) motor.back( 255 );
83 | else if ( command == "s" ) motor.stop();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/extras/L293_standalone-HW-conf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qub1750ul/Arduino_L293/647f1e22f35945f39837ca2d8e92ec7d7dd61d26/extras/L293_standalone-HW-conf.png
--------------------------------------------------------------------------------
/extras/L293_twoWire-HW-conf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qub1750ul/Arduino_L293/647f1e22f35945f39837ca2d8e92ec7d7dd61d26/extras/L293_twoWire-HW-conf.png
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | L293 KEYWORD1 DATA_TYPE
2 | L293_twoWire KEYWORD1 DATA_TYPE
3 |
4 | stop KEYWORD2
5 | forceStop KEYWORD2
6 | setPWMOffset KEYWORD2
7 | getRawPWMDC KEYWORD2
8 | getPWMDC KEYWORD2
9 | forward KEYWORD2
10 | back KEYWORD2
11 | isForward KEYWORD2
12 | isReverse KEYWORD2
13 | isStopped KEYWORD2
14 | isForceStopped KEYWORD2
15 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=L293
2 | version=4.0.2
3 | author=Giuseppe Masino (qub1750ul)
4 | maintainer=Giuseppe Masino (qub1750ul)
5 | sentence=A library to control motors with the L293x motor driver and L298x compatible modules
6 | paragraph=
7 | category=Device Control
8 | url=https://github.com/qub1750ul/Arduino_L293.git
9 | architectures=*
10 | dot_a_linkage=true
11 | includes=L293.h
12 |
--------------------------------------------------------------------------------
/src/L293.h:
--------------------------------------------------------------------------------
1 | /*
2 | * L293
3 | * Library for the control of bidirectional motors and by the integrated circuit L293
4 | *
5 | * Created by Giuseppe Masino, 28 may 2016
6 | * Author URL: https://www.facebook.com/dev.giuseppemasino
7 | * Author email: dev.giuseppemasino@outlook.it
8 | * Author GitHub: https://github.com/qub1750ul
9 | *
10 | * License info: http://creativecommons.org/licenses/by-sa/4.0/
11 | */
12 |
13 | #pragma once
14 |
15 | #include "L293_std.hpp"
16 | #include "L293_twoWire.hpp"
17 |
--------------------------------------------------------------------------------
/src/L293_base.cpp:
--------------------------------------------------------------------------------
1 | #include "L293_base.hpp"
2 |
3 | void L293_base :: setPWMOffset( int16_t _PWMOffset )
4 | {
5 | PWMOffset = _PWMOffset;
6 | }
7 |
8 | void L293_base :: stop() const
9 | {
10 | analogWrite( enablePin, 0 );
11 | }
12 |
13 | uint8_t L293_base :: getRawPWMDC() const
14 | {
15 | return RawPWMDC;
16 | }
17 |
18 | uint8_t L293_base :: getPWMDC() const
19 | {
20 | // Take the user-specified PWM value and, if it's set, apply the offset value to it
21 | // make sure that the returned value is within the limits of an unsigned 8-bit integer
22 |
23 | if( ( RawPWMDC + PWMOffset ) > 255 ) return 255;
24 | if( ( RawPWMDC + PWMOffset ) < 0 ) return 0;
25 | return RawPWMDC + PWMOffset;
26 | }
27 |
--------------------------------------------------------------------------------
/src/L293_base.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | /**
6 | * L293_base
7 | * This is an abstract class that contains all the members that other classes
8 | * of the library shares in common.
9 | * So all other classes inherit from this.
10 | */
11 |
12 | class L293_base
13 | {
14 | public:
15 |
16 | void setPWMOffset( int16_t _PWMOffset ) ; ///< Applys an offset over the speed value of the motor
17 | void stop() const ; ///< Stops the motor by power reduction
18 | uint8_t getRawPWMDC() const ; ///< Returns the last set speed value without applying the offset
19 | uint8_t getPWMDC() const ; ///< Return the effective last set speed value
20 |
21 | virtual void forward( uint8_t PWMDC = 0 ) = 0 ;
22 | virtual void back( uint8_t PWMDC = 0 ) = 0 ;
23 | virtual bool isForward() const = 0 ;
24 | virtual bool isReverse() const = 0 ;
25 | virtual bool isStopped() const = 0 ;
26 |
27 | protected:
28 |
29 | int16_t PWMOffset; ///< An offset value for the RawPWMDC
30 | uint8_t enablePin; ///< The MCU pin connected to the H-bridge's ENABLE pin
31 | uint8_t RawPWMDC; ///< The duty-cycle of the PWM signal applied to the enablePin
32 |
33 | };
34 |
--------------------------------------------------------------------------------
/src/L293_std.cpp:
--------------------------------------------------------------------------------
1 | #include "L293_std.hpp"
2 |
3 | L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _PWMOffset )
4 | {
5 | enablePin = _enablePin;
6 | forwardPin = _forwardPin;
7 | reversePin = _reversePin;
8 |
9 | pinMode( enablePin, OUTPUT );
10 | pinMode( forwardPin, OUTPUT );
11 | pinMode( reversePin, OUTPUT );
12 |
13 | PWMOffset = _PWMOffset;
14 | }
15 |
16 | void L293 :: forceStop( uint16_t handlingTime )
17 | {
18 | if ( this->isForward() ) digitalWrite( reversePin, HIGH );
19 | else if ( this->isReverse() ) digitalWrite( forwardPin, HIGH );
20 |
21 | delay( handlingTime );
22 | this->stop();
23 | }
24 |
25 | void L293 :: forward( uint8_t _PWMDC )
26 | {
27 | if( _PWMDC > 0 ) RawPWMDC = _PWMDC;
28 |
29 | this->stop();
30 | digitalWrite( reversePin, LOW );
31 | digitalWrite( forwardPin, HIGH );
32 | analogWrite( enablePin, this->getPWMDC() );
33 | }
34 |
35 | void L293 :: back( uint8_t _PWMDC )
36 | {
37 | if( _PWMDC > 0 ) RawPWMDC = _PWMDC;
38 |
39 | this->stop();
40 | digitalWrite( forwardPin, LOW );
41 | digitalWrite( reversePin, HIGH );
42 | analogWrite( enablePin, this->getPWMDC() );
43 | }
44 |
45 | bool L293 :: isForward() const
46 | {
47 | return digitalRead( forwardPin ) && !digitalRead( reversePin );
48 | }
49 |
50 | bool L293 :: isReverse() const
51 | {
52 | return !digitalRead( forwardPin ) && digitalRead( reversePin );
53 | }
54 |
55 | bool L293 :: isForceStopped() const
56 | {
57 | return digitalRead( forwardPin ) && digitalRead( reversePin );
58 | }
59 |
60 | bool L293 :: isStopped() const
61 | {
62 | return !digitalRead( forwardPin ) && !digitalRead( reversePin );
63 | }
64 |
--------------------------------------------------------------------------------
/src/L293_std.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "L293_base.hpp"
4 |
5 | /**
6 | * L293
7 | * This is the class that provides the standard functionality.
8 | * The hardware abstracted by this class connects to the MCU using three control wires.
9 | */
10 |
11 | class L293 : public L293_base
12 | {
13 | public:
14 |
15 | L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _speedOffset = 0 );
16 |
17 | void forceStop( uint16_t handlingTime ); ///< Stops the motor by electrically braking it
18 | bool isForceStopped() const ; ///< Tells the information about the motor that the name says
19 |
20 | void forward( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go forward and sets a new speed value
21 | void back( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go reverse and sets a new speed value
22 | bool isForward() const override ;
23 | bool isReverse() const override ;
24 | bool isStopped() const override ;
25 |
26 | protected:
27 |
28 | uint8_t forwardPin; ///< The MCU pin connected to one of the H-bridge's inputs
29 | uint8_t reversePin; ///< The MCU pin connected to the other H-bridge's input
30 | };
31 |
--------------------------------------------------------------------------------
/src/L293_twoWire.cpp:
--------------------------------------------------------------------------------
1 | #include "L293_twoWire.hpp"
2 |
3 | L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset )
4 | {
5 | enablePin = _enablePin;
6 | directionPin = _directionPin;
7 |
8 | pinMode(enablePin, OUTPUT);
9 | pinMode(directionPin, OUTPUT);
10 |
11 | PWMOffset = _PWMOffset;
12 | }
13 |
14 | void L293_twoWire :: forward( uint8_t _PWMDC )
15 | {
16 | if( _PWMDC ) RawPWMDC = _PWMDC ;
17 |
18 | this->stop();
19 | digitalWrite( directionPin, HIGH );
20 | analogWrite( enablePin, this->getPWMDC() );
21 | }
22 |
23 | void L293_twoWire :: back( uint8_t _PWMDC )
24 | {
25 | if( _PWMDC ) RawPWMDC = _PWMDC ;
26 |
27 | this->stop();
28 | digitalWrite( directionPin, LOW );
29 | analogWrite(enablePin, this->getPWMDC() );
30 | }
31 |
32 | bool L293_twoWire :: isForward() const
33 | {
34 | return digitalRead( directionPin );
35 | }
36 |
37 | bool L293_twoWire :: isReverse() const
38 | {
39 | return !( this->isForward() ) ;
40 | }
41 |
42 | bool L293_twoWire :: isStopped() const
43 | {
44 | return this->getPWMDC() ;
45 | }
46 |
--------------------------------------------------------------------------------
/src/L293_twoWire.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "L293_base.hpp"
4 |
5 | /**
6 | * L293_twoWire
7 | * This is a variant of the standard L293 class.
8 | * It's designed to accoplish the same result using only two control wires.
9 | * The hardware abstracted by this class needs to be connected to the MCU using
10 | * an additional interfacing circuit.
11 | */
12 |
13 | class L293_twoWire : public L293_base
14 | {
15 | public:
16 |
17 | L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 ) ;
18 |
19 | void forward( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go forward and optionally sets a new speed value
20 | void back( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go reverse and optionally sets a new speed value
21 | bool isForward() const override ;
22 | bool isReverse() const override ;
23 | bool isStopped() const override ;
24 |
25 | private:
26 |
27 | uint8_t directionPin; ///< The MCU pin connected to the circuit's direction control input
28 |
29 | };
30 |
--------------------------------------------------------------------------------