GithubHelp home page GithubHelp logo

jmsv / l293d Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 15.0 561 KB

Python module to drive DC motors from a Raspberry Pi using the L293D chip

Home Page: http://l293d.rtfd.io

License: MIT License

Python 97.20% Shell 1.00% Makefile 1.80%
driver-chip python python-library pypi l293d dc-motor raspberry-pi ic jmsv hacktoberfest

l293d's Introduction

Python module to drive DC motors from a Raspberry Pi using the L293D chip

PyPI version Python versions Build Status Documentation Status Requirements Status Contributors Wheel Support


  • This README was formerly used as the complete l293d documentation - it has now been moved to l293d.readthedocs.io

  • If you have any ideas, suggestions or problems, please open an issue.

l293d's People

Contributors

ailuke avatar alxwrd avatar cgreen12 avatar fvlima avatar jamesevickery avatar jmsv avatar patoconnor43 avatar rossdeane avatar senthilkumar-e avatar smithcs avatar surajnarwade avatar the-zebulan avatar tuckerrc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

l293d's Issues

Attribute errors

My code just will not run, I keep getting attribute errors as follows:

L293D driver version 0.2.2
Setting GPIO mode: BOARD
Traceback (most recent call last):
  File "forklift.py", line 35, in <module>
    forkliftSetup()
  File "forklift.py", line 31, in forkliftSetup
    driveLeft = l293d.Motor(22, 18, 16)
AttributeError: 'module' object has no attribute 'Motor'
L293D driver version 0.2.2
Setting GPIO mode: BOARD
Traceback (most recent call last):
  File "forklift.py", line 35, in <module>
    forkliftSetup()
  File "forklift.py", line 31, in forkliftSetup
    driveLeft = l293d.motor(22, 18, 16)
AttributeError: 'module' object has no attribute 'motor'
L293D driver version 0.2.2
Setting GPIO mode: BOARD
Traceback (most recent call last):
  File "forklift.py", line 35, in <module>
    forkliftSetup()
  File "forklift.py", line 31, in forkliftSetup
    driveLeft = l293d.DC(22, 18, 16)
AttributeError: 'module' object has no attribute 'DC'

What am I doing wrong?

GPIO pin X is already in use

When I run:
m1 = l293d.driver.motor(7, 13, 29)
m2 = l293d.driver.motor(15, 16, 31)

I get the error: ValueError: GPIO pin 15 already in use. - however it's not in use. This exception is raised on line 92 of driver.py. I've reproduced this a few times with different values.

I need to go through the pins_are_valid method and see what's going wrong.

More rigorous checking in pins_are_valid()

Hey!

When checking if the pins are valid, it would be worthwhile to also check that GND, VCC, or specialty GPIO pins are not being set (like GPIO 2 or 3 which are the only I2C capable pins on the raspberry pi). This could be done by creating a list of valid pins and then checking that the desired pin is contained in the list. If change #5 is implemented a separate list would also be needed for BCM numberings.

README.md to Wiki

README.md currently hosts:

  • Installation
  • Hardware Setup
  • Python Scripts
  • Test mode
  • Verbosity
  • Sources
  • License

but some of these should probably be in the Wiki instead.

README.md should still hold a basic overview of the program with notes regarding installation etc., but further information about the actual use of the library should be moved to Wiki.

If anyone has any advice about what exactly README.md and the Wiki are supposed to be used for, any information would help.

New spin methods

The two spin_[direction] methods are:

  • motor.spin_clockwise()
  • motor.spin_anticlockwise()

but I want to add the methods:

  • motor.clockwise()
  • motor.anticlockwise()

so less has to be typed. These new methods can just point to the existing corresponding spin_[direction] methods.

Travis CI linting

Tests for this library need to be set up in .travis.yml. This issue is a sequel to issue #16.

Update: Tests should be added in the future, but this issue is now for linting, not tests

Fix linting warnings

@surajnarwade has added linting with flake8, and there are lots of warnings. I've started going through them by running flake8 locally. Most warnings are for driver.py

`setup.py` dependencies check

Before setup.py runs install, there should be a check to make sure the user has installed the dependencies. If they haven't, there can be an option to run install anyway, or abort the setup.

Remove driver.py methods

In issue #10 I added methods to the beginning of driver.py, which was l293d.py at the time. I don't think creating these methods actually helped, but just created some problems related to scope etc.

l293d.py methods are needed

Code at the start of l293d.py should be broken into methods. For example:

  • load_config
  • display_version
  • import_dependencies
  • set_board_mode

These can then be run sequentially.

Code comments

I need to comment some of my code.
# I should of done this ages ago

Release 0.1.7

I haven't been testing enough during the development of l293d, so before bumping to 0.1.7 and releasing, I'll try and break/fix it as much as possible.

driver.py tests

I need to add more driver.py tests to tests/test_l293d.py

PWM support

Great stuff. I found out about your project following a link from the original at the tutsplus.com. One thing I would find useful: PWM. Controlling the speed of the motors. Check out this link

Remove Wiki

In issue #29 I copied everything in README to Wiki pages. I've been updating the README but the Wiki isn't being maintained

Simplify driver import statement

At the moment, to import the l293d driver module, import l293d.driver, or import l293d.driver as l293d is used.

By putting from driver import * in the l293d folder's __init__.py file, the import statement: import l293d can be used with the same effect as before. This import statement makes more sense, as the current method has proven to be counter-intuitive (see #57, for example)

Note: I'm not sure whether or not this is good practise - if anyone knows of a better solution, please suggest something

Cannot use two motors at once

Hi, James! I absolutely love this project and I think it needs more attention. However, I have a weird issue: I cannot use two motors at once. The console outputs the same motor twice, but I know 100% sure I am using two different variables. Here's what my code looks like:

import l293d

motor1 = l293d.DC(15, 13, 11)
motor2 = l293d.DC(22, 18, 16)

motor1.clockwise()
motor2.clockwise()

I get this console output:

pi@raspberrypi:~ $ python3 motor.py
L293D driver version 0.2.4
Setting GPIO mode: BOARD
spinning motor at BOARD pins [22, 18 and 16] clockwise.
spinning motor at BOARD pins [22, 18 and 16] clockwise.

But you can clearly see I use different pins and different variables.

Confirmed not working for both Python 3.6 and 2.7.

Do you know why this is happening?

Python3 support

At some point I should try and get this working in Python3 - currently development has all been 2.7

Init before drivers are used

The user should be able to import the module with parameters, such as whether test mode and/or verbosity is wanted.

This could be in the form of being able to run an initiation function before the GPIO board is set up; this is currently attempted on import.

Better cleanup safety implementation

The l293d.driver.cleanup method needs to be made safer by implementing a few things, for example:

  • No more motor calls should be possible after cleanup is run
  • cleanup should print a warning if it's called while motors are still running

Installation directory config

Idea from PR #53 comments:

  • The 'default' .ini config stays where it is without being copied anywhere
  • New methods are made in config.py to let the user modify the parameters' values without having to manually edit the file.
    • For example, the user is prompted for values for each parameter (or they can hit return to leave them the same) and then the new config is written to the file
  • When config.py is run by driver.py, config is loaded from the file in the installation directory.

I like the idea of the config file being in the l293d installation directory but editable by the user - it keeps everything in one place and keeps the user's home tidy.

[Action] motor at TYPE pins [a, b, and c]

spin_clockwise, spin_anticlockwise and stop verbose output needs to specify what board type is being used: BOARD or BCM.

This issue can only be solved after #5 is resolved.

driver.py exception messages

Exception messages in driver.py need to be made more accurate. In some places that might mean that try-catch blocks should be broken into multiple blocks to allow for more specific output. For example, at the start of driver.py where config is loaded: the try block should be shorter.

config.py also needs to raise exceptions if there are problems with the l293d-config.yaml file. This will also mean that there shouldn't be a try around import config in driver.py.

driver.py methods need docstrings

Most methods in driver.py have initial comments; these should be converted to docstrings using ''', but only if the comment looks like a summary of what the method does. If in doubt, leave it

Continue README documentation

Issue #2 was closed because I had added information to the main sections of README, and those instructions should make the library usable. This new issue is to outline future ongoing documentation of README.

Motor -> DC class

Issue #20 mentions that I'm planning on supporting stepper motors in the future.

The first step towards this should be renaming the Motor class in driver.py to DC. This means that when stepper motor support is added, a new class called Stepper (or something) can be made.

For a while after the original class is renamed, a new class called Motor should be made to raise an exception asking for DC to be used instead.

I opened a new issue for this as it should be renamed sooner rather than later so nobody becomes too dependant on using l293d.Motor

Stepper motor support

This issue might be a long shot - I've currently never experimented with using the L293D for stepper motors, but I know that this chip does support them.

I'll buy a stepper motor at some point in the (distant) future and have a go at writing something to try and make it work. In the meantime, if you stumble upon this and reckon you could have a go at it, I would be very grateful if you did - just assign yourself and/or comment to say you're having a go.

After a quick Google I found this Adafruit lesson which looks like it might be a good place to start. This tutorial also looks helpful.

Remove l293d.py from folder

To import, at the moment you use import l293d.l293d as l293d which looks stupid and doesn't make much sense.

If I remove the l293d folder and have the l293d.py file in the repo's root (and fix the import statements in other files) then once installed, the import statement would become import l293d.

Python 3 install

When running sudo python3 setup.py install, an ImportError is raised because of the setup.py check: import yaml.

The yaml module might of been named differently in Python 3, causing the ImportError. If this is the case, the same problem will be found in config.py.

Need to find a better config solution

In this commit I used a python file named config.py as a solution to issue #3.

What I forgot at the time was that this config file is just installed with everything else, and compiles to a .pyc - In my case, to /usr/local/lib/python2.7/dist-packages/l293d/.

There needs to be a solution where, for example:

  1. Before running setup.py install, the user can edit the filepath of a config file that defaults to, for example, ~/l293d-config and contains stuff like verbose = true.
  2. When l293d is imported, the config is loaded
  3. The user can edit this file when they want

Travis CI failing with ImportError

Build 64 โŒ

ImportError: No module named l293d.driver
...
The command "python tests/l293d-tests.py" exited with 1.

Not sure why this is happening, as .travis.yml runs sudo python setup.py install earlier in the script.

New method to delete motor

I'm not sure if this is completely plausible, but it might be worth looking in to. This functionality should not be edited until the version is 0.1.8 or later.

A new method should be added to driver.py's motor class to delete the motor. This should remove the motor's pins from pins_in_use, and then future attempts to use the motor should be prohibited. The only way I can think of at the moment to do this is by raising an exception for deleted motors at the start of every motor call.

Default config lost on install

Installing and importing l293d.driver on a fresh install fails with:

No such file or directory: '/usr/local/lib/python2.7/dist-packages/l293d/default_l293d-config.yaml'

README config parameters

The README currently has info about Test Mode (test_mode) and Verbosity (verbose), but these need to be made more detailed and relevant to config. Also, a section for pin_numbering needs to be made.

Remove config file, rely on defaults

After leaving this library alone for ages and coming back to it, I've realised that the idea of a config file is, in this case, a terrible idea.

The defaults should be set when the library is imported, and changed at the user's will.

User configuration methods

The driver.py class, 'Config', has new methods for setting verbose, test_mode and pin_numbering: set_verbose() etc.

These methods need to be made more safe for use, for example:

  • pin_numbering can only be changed before any motors have been defined, so all motors use the same GPIO mode
  • verbose and test_mode are bool

Format 'stopping motor...' more neatly when wait = True

Format 'stopping motor...' more neatly when wait = True:

Fancy threading stuff happens when wait is True to make the method return immediately while the motor keeps spinning until the duration ends. This means that when stop is called at the end, the message printed (if verbose) is formatted badly:

Example output

In this case, the print statement prints to the Python console prompt, which shouldn't happen

Default l293d-config.yaml file

At the moment, the default l293d-config.yaml setup is a big ugly string in config.py. This should be moved to a file: l293d-config_default.yaml' or something, and then written/copied toconfig_pathinconfig.py`.

GPIO warnings

GPIO.setwarnings(True) and GPIO.setwarnings(False) can be used to enable or disable verbose warnings regarding attempts to use pins that are already 'in use'. This should be set to True or False dependant on the Boolean value of verbose.

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.