Motorshield V2 + 2 stepper (Ada #324) wiring

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bambuino
 
Posts: 26
Joined: Fri Apr 18, 2014 8:03 am

Motorshield V2 + 2 stepper (Ada #324) wiring

Post by bambuino »

Hello --

Can someone confirm my wiring of two bipolar steppers (Ada #324, NEMA-17, 200 step...) onto Ada Motorshield V2 (Ada# 1438), via the attached Fritzing diagram?
MotorshieldV2+2stepperwiringdiagramFritzed
MotorshieldV2+2stepperwiringdiagramFritzed
StepperWiringx2b.jpg (245.54 KiB) Viewed 1185 times
I browsed this forum and found some verbal description of wiring, and the stepper's product page, but nothing explicit to wiring a pair to the shield. From some tests with one of the library examples (Accel_ConstantSpeed.ino), and by creating the second stepper in the sketch, I found the above wiring scheme gave me the desired result of both motors turning in same direction, forward. In the reference/tutorial, of the three links provided in re reverse engineering the wiring scheme of the bipolar stepper, nothing was explained to my satisfaction. I have seen a good method outlined somewhere, but the original source eludes me.

The wiring scheme is, verbose:
Port 1, in direction of M1-GND-M2 -- Green, Grey, (skip GND), Red, Yellow
Port 2, in direction of M3-GND-M4 -- Grey, Green, (skip GND), Yellow, Red

I did find, though, several useful posts in re increasing motor revs via increase I2C bus speed, and a couple other things. This shield (Motorshield V2) should be answer to my needs, as I am looking to control the steppers by dropping a Nordic nRF24L01+ module onto the proto pads, what with all these freed up pins. (Scratches head) I think, right?

A hui hou, Mark

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by adafruit_support_bill »

Your wiring looks correct. The recommended connections (from the product description) are:
To connect to our shield, put the wires in this order: Red, Yellow, skip ground, Green, Brown (or Gray)
You can reverse the order of the red/yellow or green/gray pairs to alter the rotation direction if desired.

I don't have any experience with the Nordic modules, but I don't see any reason why they wouldn't work.

User avatar
bambuino
 
Posts: 26
Joined: Fri Apr 18, 2014 8:03 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by bambuino »

Hi Bill --

Thank you for the follow up, and for the insight on the wiring. As wired, the motors performed as written to the sketch, fulfilling somewhat my needs at present.

I have some further questions in re setSpeed() in that the max RPM I have achieved is approximately 60, when in the sketch I had specified 250. When specifying setSpeed(100) the motors achieveabout 30 RPM, for 125 I get about 34 RPM, for 200 about 52 RPM, &c. I have changed I2C bus speed via library, and in the setup(), and with AFMS.begin(n), alternatively, without significant change in motor RPMs. And, only slightly more confounding, is that when I tied in the nRF24l01+ 2.4GHz module to control these motors remotely, motor RPM dropped to about 10 RPM when specified in sketch for 50+. I suspect that the radio functions in the sketch somehow block up the motors in some manner, though I presently lack experience to say for sure. I have attached below the two sketches, transmitter and receiver, if you might take a look-see, perhaps suggest something I may keep my eyes open for as I continue my review of the literature in re coding for these steppers.

A few project details. The steppers are replacing continuous rotation servos I got from you folks. Those worked wonderfully, providing sufficient RPMs, but lacking the torque and an all metal construction. Now that I know this rig can increase my production rate, I am upgrading the components where I see fit. The nRF24L01+ modules provide for fewer headaches as I can control the motors while more closely monitoring the process at hand. With these steppers, obtaining motor RPMs up to 60-80 would be great. Power supplies used in testing have been a 12V 7Ah AGM battery and a pile of NiMHs outputting about 8V. I neglected to pull the jumper on the shield when USB'd for a few moments, with no untoward effects. The motive components (with servos) currently span about 40 feet, and am looking to double this distance which will require an increase in motor RPMs with the steppers.

In brief, physical description of components coded by below sketches:
Transimitter - two pairs of an SPDT/POT combo, individually controlling head and tail motor components over RF. Head is comprised of two motors, tail by a single motor. POT has mapped values, and SPDT essentially swaps these mapped values for instantaneous forward/reverse control of motor at speed dictated by POT. Sketched onto a Micro and stuffed into a small plastic box. In future, very near future, I want to map value of POT and insert in setSpeed(get_val) function of receiver (stepper).
Receiver - receives instructions and, formerly, wrote values to servos, but now have upgraded to NEMA-17-sized 12V steppers. Sketched onto UNO R3 and Motorshield V2.

I have let remain the commented out lines to show progression of work.
Transmitter:

Code: Select all

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t unoServo = 0xE8E8F0F0E1LL;
const uint64_t dueServo = 0xE8E8F0F0D2LL;

int aSW = 2;              //SPDT mini-toggle for aSW (D2) & bSW (D3)
int bSW = 3;              //Provides for forward and reverse
int lPOT = A0;            //10k small pot for aSW & bSW
int cSW = 4;              //SPDT mini-toggle for cSW (D4) & dSW (D5)
int dSW = 5;              //Provides for forward and reverse
int rPOT = A1;            //10k small pot for cSW & dSW
int val = 0;

void setup(void){
  pinMode(aSW, INPUT_PULLUP);
  pinMode(bSW, INPUT_PULLUP);
  pinMode(lPOT, INPUT);
  pinMode(cSW, INPUT_PULLUP);
  pinMode(dSW, INPUT_PULLUP);
  pinMode(rPOT, INPUT);
  radio.begin();
//  radio.openWritingPipe(pipe);
}

void loop(void){
  {  //2-servo piece
    if (digitalRead(aSW) == LOW)
    {
      motorForward();
    }
    else if (digitalRead(bSW) == LOW)
    {
      motorReverse();
    }
//    else
//    {
//      motorStop();
//    }
  }
  {  //1-servo piece
    if (digitalRead(cSW) == LOW)
    {
      motorRForward();
    }
    else if (digitalRead(dSW) == LOW)
    {
      motorRReverse();
    }
    else
    {
      motorRStop();
    }
  }
}

/*--------MOTOR CONTROL---------*/
void motorForward()
{
  radio.openWritingPipe(dueServo);
//  unsigned long val = analogRead(lPOT);
//  val = map(val, 0, 1023, 0, 179);
//  radio.write( &val, sizeof(unsigned long) );
  msg[0] = 000;
  radio.write(msg, 1);
//  delay(1);
}

void motorReverse()
{
  radio.openWritingPipe(dueServo);
//  unsigned long val = analogRead(lPOT);
//  val = map(val, 0, 1023, 179, 0);
//  radio.write( &val, sizeof(unsigned long) );
  msg[0] = 111;
  radio.write(msg, 1);
//  delay(1);
}

void motorRForward()
{
  radio.openWritingPipe(unoServo);
  unsigned long val = analogRead(rPOT);
  val = map(val, 0, 1023, 0, 179);
  radio.write( &val, sizeof(unsigned long) );
}

void motorRReverse()
{
  radio.openWritingPipe(unoServo);
  unsigned long val = analogRead(rPOT);
  val = map(val, 0, 1023, 179, 0);
  radio.write( &val, sizeof(unsigned long) );
}

void motorStop()
{
  radio.openWritingPipe(dueServo);
  unsigned long val = 90;
  radio.write( &val, sizeof(unsigned long) );
}

void motorRStop()
{
  radio.openWritingPipe(unoServo);
  unsigned long val = 86;
  radio.write( &val, sizeof(unsigned long) );
}
Receiver:

Code: Select all

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(9,10);
const uint64_t dueStepper = 0xE8E8F0F0D2LL;
int msg[1];

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(200, 2);

void setup(){
  radio.begin();
  radio.openReadingPipe(1,dueStepper);
  radio.startListening();

  AFMS.begin();
 
//  TWBR = ((F_CPU /400000l) - 16) / 2;
}


void loop(){
  
  myStepper1->setSpeed(50);
  myStepper2->setSpeed(50);
  
  if (radio.available()){
    bool done = false;
    while (!done){
      done = radio.read(msg, 1);
      if (msg[0] == 000){
  myStepper1->onestep(FORWARD, SINGLE);
  myStepper2->onestep(FORWARD, SINGLE);
      }
      else if (msg[0] == 111){
  myStepper1->onestep(BACKWARD, SINGLE);
  myStepper2->onestep(BACKWARD, SINGLE);
      }
     }
  }
//  delay(10);
}

Assistance from anyone knowledgeable in these matters is welcome and appreciated. I make a natural fiber cordage, the materials of which are suspended betwixt the motive endpeices.

Me ke aloha, Mark

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by adafruit_support_bill »

SetSpeed() has no effect if you are calling oneStep() on the motors. The motors will take one step whenever the call is made - regardless of the timing.

What that means is that your loop timing will determine your motor speed. I'm not sure I understand the intent, but it seems that the motor will move forward exactly one step if there is a 000 available from the radio and move backwards exactly one step if there is a 111 available. The motor will not move of there is no data. It will not move it the data is anything other than 000 or 111 either.

It would seem that the primary factor in the rotation speed is what you are receiving via the radio.

User avatar
bambuino
 
Posts: 26
Joined: Fri Apr 18, 2014 8:03 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by bambuino »

Thanks Bill for clarifying the setSpeed and onestep, although at present am still somewhat in bewilderment.

Yes, the simple command of forward and reverse rotation is governed by the broadcast msg of 0's and 1's, respectively. How might I achieve continuous rotation of the motors, not stepwise, responding to the aforementioned RF instructions? Perhaps that is where this is failing me. In retrospect, When in testing, if I inserted a delay after the TX instruction, the stepper responded with likewise delay in making that next stepwise progression. So, I have a bit more of an idea what is going on here following your response.

Thanks again for continued support. Mark

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by adafruit_support_bill »

If I understand correctly, you want to separate the motor rotation speed from the radio transmission rate? A little more definition of the requirements would be helpful.

User avatar
bambuino
 
Posts: 26
Joined: Fri Apr 18, 2014 8:03 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by bambuino »

Hi Bill --

The radio TX'er continuously sends instructions to the RX'er, in this case, the two steppers. These instructions are forward, reverse, and in the lack of instructions from the TX'r, when my TX'er's SPDT is centered, to cease turning. I have achieved this level of control over the receiving steppers. What is confounding to me is the low RPM's (about 8-12 RPM) achieved by the steppers when receiving instructions over RF. My thoughts about the coding of my sketches, given my lack of experience, had me thinking that somehow the motors were further slowed in the loop(). These low RPM's are even lower than that obtained than by simply running some of the example sketches out of the Motorshield V2 library without RF, which seem on average some 25% that of what is coded into the example sketch. I have loaded into libraries the AccelStepper, and run some of those examples, but still low revs. Certainly nothing approaching that boasted of on the product info page for the #324 stepper (250 RPM! Do tell.)

I am reading what I can find following a post from you earlier, and am gaining a very slow grasp of the topic.

What I am looking for is similar performance by steppers that I had previously obtained from the continuous rotation servos I employed, which was speed-variable, bidirectional control (over RF, no less). The mod up to the steppers I believe can offer benefits greater than the servos, such as increased torque, improved pair-wise motor speed synchronization, and more robust construction of motors. What is eluding me is how to up the revs of these steppers to a useful rate.

Simply put, when I turn on a switch, I would like to have a pair of stepper shafts revolve somewhere between 50-80 RPM. More important, I would like to understand how to make this all happen.

Thanks again Bill.

A hui hou, Mark

User avatar
bambuino
 
Posts: 26
Joined: Fri Apr 18, 2014 8:03 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by bambuino »

Say Bill --

I got a little ahead here in the reading, and am a bit smarter. Drawing from the Motorshield V2 library with StepperTest.ino edited for brevity below, I am achieving approximately 120 RPM with a setSpeed(200), which is a usable maximum speed for my application. Is there a manner of specifying an infinite number of steps, for non-stop rotation? Say, until I instruct at will to either stop or reverse direction? I will also be modding up a motive piece that will be a single stepper, in place of a single servo. But, for the present, what I would like to do is have two steppers perform in the above manner, and the oneStep() function seems the ticket, I think.

But, some more questions. Can you help me understand the discrepancy between what is coded for in setSpeed(), and that which is realized at the motor shaft? There seems a proportional decrement in shaft speed when setSpeed() is lowered. When I tried a setSpeed(250) the results were all over with skipped steps. Also, I notice an increase in motor noise at lower setSpeed(). I am using a 12V supply, so perhaps this is due to the increased torque provided by the 12V? I notice lower motor noise with the 9V pile of NiMHs, but no discernible decrease in holding torque at this juncture.

Code: Select all

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

void setup() {
  AFMS.begin();
  myMotor->setSpeed(200);
  TWBR = ((F_CPU /400000l) - 16) / 2;
}

void loop() {
  myMotor->step(4000, FORWARD, DOUBLE); 
  delay(1000);
  myMotor->step(4000, BACKWARD, DOUBLE);
  delay(2000); 
}
A hui hou, Mark

What has gotten me behind in the research here is your folks' shipment arriving several days earlier than anticipated...and now, with all this shiny new gear...

User avatar
adafruit_support_bill
 
Posts: 88095
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by adafruit_support_bill »

The "step()" function as used in the example code is a 'blocking' call. You can't interrupt it, and you can only run one motor at a time that way.

Using "oneStep()", you have complete control, but setSpeed() is irrelevant. The motors will step exactly when you tell them to. If you want to implement speed control, you will need to control the step timing yourself.

AccelStepper is sort of a compromise. You can control 2 motors simultaneously. AccelStepper will take care of the step timing. That may be the most appropriate solution for your application.
Can you help me understand the discrepancy between what is coded for in setSpeed(), and that which is realized at the motor shaft?
The step timing does not take into account the communication overhead with the motor controller. With high-step-count motors such as the one you are using, the per-step communication overhead becomes a significant fraction of the step time and causes that error in speed.

User avatar
bambuino
 
Posts: 26
Joined: Fri Apr 18, 2014 8:03 am

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by bambuino »

Thanks for you kind support Bill.

A hui hou.

User avatar
ssteinerx
 
Posts: 1
Joined: Wed May 18, 2011 6:11 pm

Re: Motorshield V2 + 2 stepper (Ada #324) wiring

Post by ssteinerx »

A little off-topic, but where did you get the Fritzing components for the stepper motors? I loaded the entire adafruit library but don't have those.

Thanks,

Steve

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”