Welcome to Adafruit-Motor-Hat’s documentation!

Contents:

Adafruit-Motor-Hat

https://img.shields.io/pypi/v/adafruit_motor_hat.svg https://img.shields.io/travis/ferret-guy/adafruit_motor_hat.svg Documentation Status Updates

An improved pip available Adafruit Motor Hat Package

Features

  • Improve the Stepper performance for the original Adafruit-Motor-HAT-Python-Library

Credits

This package is based and mostly contains code from Adafruit-Motor-HAT-Python-Library

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Installation

Stable release

To install Adafruit-Motor-Hat, run this command in your terminal:

$ pip install adafruit_motor_hat

This is the preferred method to install Adafruit-Motor-Hat, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for Adafruit-Motor-Hat can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/ferret-guy/adafruit_motor_hat

Or download the tarball:

$ curl  -OL https://github.com/ferret-guy/adafruit_motor_hat/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

To use Adafruit-Motor-Hat in a project:

import adafruit_motor_hat

Reference

class adafruit_motor_hat.MotorHat.AdafruitStepperMotor(controller, num, steps=200)[source]
align_step(reverse=False)[source]

Align the current step position with a full step

Parameters:reverse (bool) – run in reverse
Returns:None
double_step(steps=1, reverse=False)[source]

Double stepping, 2 coils at once

Parameters:
  • steps (int) – The number of steps to execute
  • reverse (bool) – step in reverse
Returns:

None

interleaved_step(steps=1, reverse=False)[source]

Interleaved stepping, single stepping and interleaved stepping

Parameters:
  • steps (int) – The number of steps to execute
  • reverse (bool) – step in reverse
Returns:

None

micro_step(steps=1, reverse=False)[source]

Microstepping

Parameters:
  • steps (int) – The number of steps to execute
  • reverse (bool) – step in reverse
Returns:

None

set_speed(rpm)[source]

Set the target motor speed in rpm, motor step count is used to calculate the step delay

Parameters:rpm (float) – Target RPM
Returns:None
step(steps=1, reverse=False)[source]

Simple single step

Parameters:
  • steps (int) – The number of steps to execute
  • reverse (Bool) – step in reverse
Returns:

None

class adafruit_motor_hat.MotorHat.AdafruitDCMotor(controller, num)[source]
class adafruit_motor_hat.MotorHat.AdafruitMotorHAT(addr=96, freq=1600, i2c=None, i2c_bus=None)[source]
get_motor(num)[source]

Get a motor instance

Parameters:num (int) – the stepper to get 1-4
Returns::class:`AdafruitDCMotor’
get_stepper(num)[source]

Get a stepper instance

Parameters:num (int) – the stepper to get 1, or 2
Returns::class:`AdafruitStepperMotor’
set_pin(pin, value)[source]

Set a pin output state

Parameters:
  • pin (int) – pin number
  • value (int) – pin state 0, or 1
Returns:

None

class adafruit_motor_hat.Adafruit_PWM_Servo_Driver.PWM(address=64, debug=False, i2c=None, i2c_bus=None)[source]

Adafruit PCA9685 16-Channel PWM Servo Driver

setAllPWM(on, off)[source]

Sets all the pwm outputs to the corresponding outputs

Parameters:
  • on – the portion of the PWM period in 1/4096ths of a period (0 corresponds to the start, 4096 corresponds to the end) to wait before the signal turns on
  • off – the portion of the PWM period in 1/4096ths of a period (0 corresponds to the start, 4096 corresponds to the end) to wait before the signal turns off
Returns:

None

setPWM(channel, on, off)[source]

Set a single pwm channel

Parameters:
  • channel – the channel number from 0-15 inclusive
  • on – the portion of the PWM period in 1/4096ths of a period (0 corresponds to the start, 4096 corresponds to the end) to wait before the signal turns on
  • off – the portion of the PWM period in 1/4096ths of a period (0 corresponds to the start, 4096 corresponds to the end) to wait before the signal turns off
Returns:

None

setPWMFreq(freq, correctionFactor=1.0)[source]

Set the PWM frequency in Hz

Parameters:
  • freq (int) – frequency in Hz
  • correctionFactor (float) – correction factor for drifting pwm putout
Returns:

None

classmethod softwareReset(i2c=None, i2c_bus=None)[source]

Sends a software reset (SWRST) command to all the servo drivers on the bus

adafruit_motor_hat.Adafruit_PWM_Servo_Driver.get_i2c_device(address, i2c, i2c_bus)[source]

Helper method to get a device at the specified address from the I2C bus. If no i2c bus is specified (i2c param is None) then the default I2C bus for the platform will be used.

Parameters:
  • address (hex) – i2c address to get the handle for
  • i2c – GPIO i2c class, None to use the Adafruit_GPIO.I2C class
  • i2c_bus – i2c bus number, passed to busnum, none to autodetect
Returns:

i2c Address

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/ferret-guy/adafruit_motor_hat/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

Adafruit-Motor-Hat could always use more documentation, whether as part of the official Adafruit-Motor-Hat docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/ferret-guy/adafruit_motor_hat/issues.

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up adafruit_motor_hat for local development.

  1. Fork the adafruit_motor_hat repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/adafruit_motor_hat.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv adafruit_motor_hat
    $ cd adafruit_motor_hat/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 adafruit_motor_hat tests
    $ python setup.py test or py.test
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.
  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
  3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check https://travis-ci.org/ferret-guy/adafruit_motor_hat/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ python -m unittest tests.test_adafruit_motor_hat

Credits

Development Lead

Contributors

None yet. Why not be the first?

Original Contributors to Adafruit-Motor-HAT-Python-Library

  • tdicola
  • caternuson
  • ladyada

History

0.1.0 (2017-06-24)

  • First release on PyPI.

Indices and tables