Code Monkey home page Code Monkey logo

mcp3017accelstepper's Introduction

MCP23017 I2C AccelStepper library for Arduino

Extension for the AccelStepper library.

With this library AccelStepper can be used to control steppers using a MCP23017 I/O Expander over I2C interface. This requires only two pins to be used A4 SDA and A5 SCL on the Arduino Uno. MCP23017AccelStepper extends AccelStepper which means that all the functionality of AccelStepper is still there.

  • I2C support using a MCP23017 I/O Expander.
  • When used with the driver interface the third pin for the constructor can be used to set the enable pin.
  • By not calling setMcp it will fallback to the Arduino pins.

Example

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <AccelStepper.h>
#include <MCP3017AccelStepper.h>

#define STEPPER_COUNT 4

Adafruit_MCP23017 mcp1;

MCP3017AccelStepper steppers[STEPPER_COUNT] = {
    // interface, step, dir, en
    MCP3017AccelStepper(AccelStepper::DRIVER, 15, 14, 8),
    MCP3017AccelStepper(AccelStepper::DRIVER, 4, 5, 6),
    MCP3017AccelStepper(AccelStepper::DRIVER, 12, 11, 10),
    MCP3017AccelStepper(AccelStepper::DRIVER, 3, 1, 2),
};

void setup() {
  mcp1.begin();

  for (int i = 0; i < STEPPER_COUNT; i++) {
    steppers[i].setMcp(mcp1);
    steppers[i].enableOutputs();
    steppers[i].setMaxSpeed(150.0);
    steppers[i].setAcceleration(100.0);
    steppers[i].moveTo(200);
  }
}

void loop() {
  if (steppers[0].distanceToGo() == 0) {
    steppers[0].moveTo(-steppers[0].currentPosition());
  }

  for (int i = 0; i < STEPPER_COUNT; i++) {
    steppers[i].run();
  }
}

Making things run smooth

Ones you have a couple of steppers running you might notice that they're a bit slow. To make them run smooth you can change the clock frequency of the I2C bus. More on this here http://playground.arduino.cc/Code/ATMELTWI#line7

mcp1.begin();
TWBR = 12;  // 400 kHz 
// TWBR = 72;  // 100 kHz (default)

Dependencies

External dependencies, the Wire library is also needed but is bundled with the Arduino software.

License

GPL V2, same as AccelStepper http://www.airspayce.com/mikem/arduino/AccelStepper/

Author

2013 Johan Nilsson http://www.markupartist.com

mcp3017accelstepper's People

Contributors

johannilsson 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.