Giter Club home page Giter Club logo

adafruit_motor_shield_v2_library's Introduction

Adafruit Motor Shield V2 Library Build StatusDocumentation

This is the library for the Adafruit Motor Shield V2 for Arduino. It supports DC motors & Stepper motors with microstepping as well as stacking-support. It is not compatible with the V1 library!

For use with the Motor Shield https://www.adafruit.com/products/1438 and Motor FeatherWing https://www.adafruit.com/product/2927

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information. All text above must be included in any redistribution.

adafruit_motor_shield_v2_library's People

Contributors

andydoro avatar arminjo avatar caternuson avatar driverblock avatar evaherrada avatar gschandler avatar hoffmannjan avatar kattni avatar ladyada avatar paintyourdragon avatar siddacious avatar tdicola avatar toddtreece avatar tremrej avatar tyeth avatar

Stargazers

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

Watchers

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

adafruit_motor_shield_v2_library's Issues

Implement the reset function

The "Adafruit_MS_PWMServoDriver::reset" function writes the value 0 to the PCA9685_MODE1 register. This does not actually reset the chip.

The docs https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf section 7.6 show how to reset the chip by writing the value 6 to I2C address 0. That's global I2C bus address 0 ... not the 0 register in the chip. This resets all PCA9685s on the bus.

Problem with microstepping code

I have a problem in the Motor shield V2 library. Single, double, interleaved seem to function ok but
the code for microstepping has an error.
It is in the step() function . Specifically the while loop, below, which is executed when the calls to
onestep have finished.

if (style == MICROSTEP) {
while ((ret != 0) && (ret != MICROSTEPS)) {
ret = onestep(dir, style);
delay(uspers/1000); // in ms
steppingcounter += (uspers % 1000);
if (steppingcounter >= 1000) {
delay(1);
steppingcounter -= 1000;
}
}
}

Considering the FORWARD direction only (BACKWARDS will be the mirror image).
ret is equal to currentstep. Currentstep is constrained to 0 to 63 for either direction using the
default 16 microsteps via the statements:

currentstep += MICROSTEPS_4;
currentstep % MICROSTEPS_4;

If a single step had been executed (as in step(1,FORWARD, microstep)) then ret = 16 = MICROSTEPS and the while loop is exited.
If another single step is executed then ret = 32 and a further 32 calls to onestep are executed until
ret = 0.
So we get with multiple calls to step but a single step: 1 step, then 3 steps, then 1 step then 3
steps, and so on.
If 2 steps is repeatedly called then 4 steps will be executed, 3 steps called then again 4 steps
executed, 4 steps called will execute the 4 steps.

So we have:
4n step move will give no extra steps, all ok. So steps of 4,8,12,16,20,24,28,... will function
correctly
4n+1 step repeated move will give the pattern of 1step, 3steps (1 step plus 2 extra), 1step, etc due to the unique position of being able to satisy the (ret != MICROSTEPS) condition of the while loop.
4n+2 step move will give 2 extra steps
4n+3 step move will give 1 extra step

For a 200 step motor 360 and 180 degree moves are ok as the moves are multiples of 4. To see the worst case, move 200 single steps, the motor will do two revolutions not one.

Deleting the block of code removes the problem. The code checks for a condition (currentsteps value returned with a value between 1 and 15) which would not be possible given the constraints on currentstep variable set within the onestep function.

If one wanted to keep the code (it does seem redundant to me) then the while condition could be:
while ((ret != 0) && (ret % 4 < MICROSTEPS))

Regards,
CFJ

Library conflicts with Adafruit-PWM-Servo-Driver-Library

This library implement its own PCA9685 interface with code in the utlility directory. Some of that conflicts with the separate PCA9685 library Adafruit-PWM-Servo-Driver-Library which throws compiler warns when the two are used together in the same sketch. See here for compile warns:
adafruit/Adafruit-PWM-Servo-Driver-Library#95 (comment)

Would it make sense to refactor this library to have the PWM-Servo library as a dependency and used that for PCA9685 support?

Init code leaves pin 6 set to 100%

After instantiating two AF_Steppers and setting their speeds, pin 6 is left high/on. That shouldn't mess with pin 6 AFAIK. I believe this is from servo init code (and we're not using servos), but I'll look around more, and come up with a short example that reproduces it, and probably a patch.

It's not a horrible problem because we can just analogWrite(pin6, 0) after the initialization, but in case it bites someone else, here it is.

Shouldn't INTERLEAVE double steps?

INTERLEAVE vs. MICROSTEP is handled inconsistently. INTERLEAVE gives one "step" per step, even though each "step" only gives half the motion. MICROSTEP considers the steps argument as full steps. Shouldn't steps be doubled in line 223 of Adafruit_MotorShield.cpp so that the steps argument is always treated as a full step?

Points vs. Variables

Not an issue but a question: the code works well, thank you very much.

Reviewing the library I'm wondering what drives the use of pointers as opposed to variable assignment for working with the library (e.g. setting speed, direction, etc). I (generally) understand the role and function of pointers, but I haven't used them extensively in my own code, so I'd like to learn how they help here, and more importantly, if they are required in any way for the functionality of this library.

Thanks in advance.

Stepper motor release hardware bug

This may not be a typical use case but I have noticed the tendency to have an extra step when shutting a stepper down with the release function. I have traced this to the sequencing of the shutdown of the PWM. It occurs after the enable lines are toggled. This continues to modulate the windings as the enables are being released.

Potential bug for method getMotor and getStepper of class Adafruit_MotorShield

In getMotor, to determine if the motor are init'd, you test the value of member motornum (line 72) with zero and assign num to motornum (line 74). In the case of the motor one, num are the value zero when motornum is assigned to num because of the decrement line 70. The first motor is always init'd.
It's the same for getStepper.
However, I haven't yet tested the code.

Pointers vs. Variables

Not an issue but a question: the code works well, thank you very much.

Reviewing the library I'm wondering what drives the use of pointers as opposed to variable assignment for working with the library (e.g. setting speed, direction, etc). I (generally) understand the role and function of pointers, but I haven't used them extensively in my own code, so I'd like to learn how they help here, and more importantly, if they are required in any way for the functionality of this library.

Thanks in advance.

Please remove warnings from code.

Hello
I am using your library with Eclipse and I see some unnecessary warnings.

On line 295 there is
uint8_t ret = 0;
and on line 310
ret = onestep(dir, style);
please just remove ret

On line 328 there is
uint8_t a, b, c, d;
This line can also simply be removed.

In function Adafruit_DCMotor *Adafruit_MotorShield::getMotor(uint8_t num)
on line 126ff there is
if (num > 4) return NULL;
It must be
if (num >= 4) return NULL;
Unfortunately the warnings in Eclipse still show up :-( due to a lack of the parser.

The same holds for function Adafruit_StepperMotor *Adafruit_MotorShield::getStepper(uint16_t steps, uint8_t num) on line 162ff
if (num > 2) return NULL;
must be
if (num >= 2) return NULL;
In this case the warnings vanish :-)

Thank you for you effort
Best regards
Armin

WDT Error and following automatic Reset

  • Arduino board: Feather Huzzah
  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.6.10
  • List the steps to reproduce the problem:
    Just running the standard steppertest.ino example with more steps in one run

I found the solution already see: [https://github.com/esp8266/Arduino/issues/2377 ]
By adding in the library-code the delay(0) command.:
*

  while (steps--) {
    //Serial.println("step!"); Serial.println(uspers);
    ret = onestep(dir, style);
    delayMicroseconds(uspers);
    //Rudy De Volder: to solve WDT problem with the ESP8266 simply add the following line:
    delay(0);
  }

Platformio libraries

Noticed that the version 1 library is on platform io's library registry but not version 2? Just wanted to check if its OK for me to add it. JSON file will be hosted on my own site.

Apologies in advance for the daft question.

Motor library not working with Timer1

Immediately after running AFMS.begin(), I'm running a setup routine that sets up Timer1 as a capture/compare timer to be used for generating 1Hz timed interrupts. It is at this time that my Arduino seems to get stuck. This timer and the rest of my code ran just fine before I added the code to run the motor shield and it also works fine if I comment out the timer initialization.

It doesn't appear that the motor shield library is using timer1, but maybe it is. I can't think of any other reason why this wouldn't work. Anyway, here is my timer initialization routine:

  cli();//stop interrupts

  //set timer1 interrupt at 1Hz
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCNT1  = 0;//initialize counter value to 0
  // set compare match register for 1hz increments
  OCR1A = LOG_INTERVAL;// = (16*10^6) / (interval*1024) - 1 (must be <65536) (interval in seconds)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10);  
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);

  sei();//allow interrupts

Add a way to check if a shield is attached at an address

Add a function that checks if a shield is attached at an address.


The current solution is to add a function to Adafruit_MS_PWMServoDriver.cpp, ....h which returns 0 == WIRE.endTransmission() (after a beginTransmission on an address). This output will then be passed through another function in Adafruit_Motorshield.cpp, ....h. This solution is taken from the arduino I2CScanner tutorial.

Request, 12 bit resolution for DC motors?

I noticed this hardware can do 12 bit resolution for DC motors but that this library doesn't support it. I made a mod to support it and found it worked much better in my project.

It is very easy to support, you just need to add another function, for example.

void Adafruit_DCMotor::setSpeed12bit(uint8_t speed) {
  MC->setPWM(PWMpin, speed);
}

This is identical to the existing setSpeed function, but the *16 has been removed. This change wouldn't effect existing projects that use the existing setSpeed function, both would still work.

You would think the difference between 8 and 12 bits wouldn't be noticeable on a DC motor, but I've measured it and at 12 bits every step does make a measurable change in RPM.

yield

i keep getting this when when ever i verify any of the example

/home/disappear/sketchbook/libraries/AdafruitMotorShieldV2/Adafruit_MotorShield.cpp: In member function ‘void Adafruit_StepperMotor::step(uint16_t, uint8_t, uint8_t)’:
/home/disappear/sketchbook/libraries/AdafruitMotorShieldV2/Adafruit_MotorShield.cpp:237:11: error: ‘yield’ was not declared in this scope
yield(); // required for ESP8266
^

AFMS.begin(); never returns

Hi,

I've just got my Arduino UNO and the Adafruit Motor Shield.
I've installed standard headers, Power to the Motor Shield (4 AA batteries about 5.4V) and 1 motor in position M3.

Then I try DCMotorTest and it prints only

Adafruit Motorshield v2 - DC Motor test!

The power LED is on, but the motor never runs (I changed the code to use M3)

I tried to add prints in setup() after AFMS.begin() but they never trigger.

What could be happening?

I am using 1.6.5

Compile error

Hey just downloaded this (11/7/2013 5:30pm MST) and tried to run the DC Motor test sketch. I get a compile error:

In file included from DCMotorTest.ino:11:
C:\Arduino\libraries\Adafruit_MotorShield/Adafruit_MotorShield.h:56: error: expected unqualified-id before 'break'

Getting a error compiling code. Can anyone help?

Arduino: 1.8.0 (Mac OS X), Board: "Arduino/Genuino Uno"

cory_upwork:17: error: expected ',' or ';' before 'void'
void forwardstep()
^
cory_upwork:27: error: 'forwardstep' was not declared in this scope
AccelStepper Astepper(forwardstep,backwardstep);
^
exit status 1
expected ',' or ';' before 'void'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

18641835_1820797877949781_271338971_o

Please expose existing "all on or off" functionality

  • Arduino board: Uno
  • Arduino IDE version: Any

The Motor Shield library includes the following 'all on or off' functionality for the motor controllers.

/**************************************************************************/
/*!
    @brief  Helper that sets the PWM output on a pin and manages 'all on or off'
    @param  pin The PWM output on the driver that we want to control (0-15)
    @param  value The 12-bit PWM value we want to set (0-4095) - 4096 is a special 'all on' value
*/
/**************************************************************************/
void Adafruit_MotorShield::setPWM(uint8_t pin, uint16_t value) {
  if (value > 4095) {
    _pwm.setPWM(pin, 4096, 0);
  } else 
    _pwm.setPWM(pin, 0, value);
}

However, there's no way to access this feature from the sketch level. The public setSpeed function, which calls setPWM, only accepts a uint8_t.

void Adafruit_DCMotor::setSpeed(uint8_t speed) {
  MC->setPWM(PWMpin, speed*16);
}

255 * 16 = 4080, so the user can't get 4096 to setPWM. This functionality should be exposed for rare cases when PWM causes too much electrical noise and 12V DC is all that's needed.

artificial index?

Warning;There is an artificial index in library of 'Adafruit Motor Shield library'
i always receive this warning when i upload my codes !!! help me please

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.