0

Adafruit Motor Shield v2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit Motor Shield v2

by lardot on Sun Sep 24, 2017 3:58 pm

I am attempting to switch from M1 to M2, M3 or M4 by editing the test sketch from your library. When I switch to M2 the edited sketch does not make the change. Can someone point out my error in the modified code?

Code: Select all | TOGGLE FULL SIZE
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2
---->   http://www.adafruit.com/products/1438
*/

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

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M2
Adafruit_DCMotor *myMotor2 =AFMS.getMotor(2);



void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Adafruit Motorshield v2 - DC Motor test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
 
  // Set the speed to start, from 0 (off) to 30 (max speed)
  myMotor2->setSpeed(30);
  myMotor2->run(FORWARD);
  // turn on motor
  myMotor2->run(RELEASE);
}

void loop() {
  uint8_t i;
 
  Serial.print("tick");

  myMotor2->run(FORWARD);
  for (i=0; i<30; i++) {
    myMotor2->setSpeed(i); 
    delay(10);
  }
  for (i=30; i!=0; i--) {
    myMotor2->setSpeed(i); 
    delay(10);
  }
 
  Serial.print("tock");

  myMotor2->run(BACKWARD);
  for (i=0; i<30; i++) {
    myMotor2->setSpeed(i); 
    delay(10);
  }
  for (i=30; i!=0; i--) {
    myMotor2->setSpeed(i); 
    delay(10);
  }

  Serial.print("tech");
  myMotor2->run(RELEASE);
  delay(1000);
}
Attachments
Untitled.txt
(1.6 KiB) Downloaded 155 times
Last edited by adafruit_support_bill on Sun Sep 24, 2017 5:30 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums.

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Sun Sep 24, 2017 5:32 pm

That looks OK. Please post details about the motors and power supplies you are using. As well as some photos showing your soldering and connections to the shield.

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Motor Shield v2

by lardot on Mon Sep 25, 2017 11:35 am

Thanx for the feedback Bill, I am glad the sketch looks ok but that might mean I have a worse problem. The motors are Pololu 1000:1 HPCB 6V Item # 3080 and the encoders are Item # 3081. The encoders are not hooked up at the moment, I am just trying to get acknowledgement of the individual motors for now. Currently Motor #1 is disconnected because even though the sketch is edited it wants to run #1 and I have a seperate motor from the hand that I am trying to get acknowledged on M2. I took the photos but I couldn't get the file size small enough so I zipped one and that didn't work either. I also tried scanning but the files are to big and I don't know how to size them down. If you like I could email them to you direct.

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Mon Sep 25, 2017 11:52 am

There is a 1 meg limit on uploads. 800x600 images typically work best. Most photo applications have options for saving photos at smaller sizes. If your does not, there are lots of free on-line re-sizing sites.

The motors are Pololu 1000:1 HPCB 6V Item # 3080

Those are nice little motors. What power supply are you using with them?

Currently Motor #1 is disconnected because even though the sketch is edited it wants to run #1

But your code only has one motor defined. If it is still trying to run #1, that implies that your revised code did not upload successfully.

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Motor Shield v2

by lardot on Mon Sep 25, 2017 12:42 pm

Here are the photos resized.
Attachments
DSC01726.JPG
DSC01726.JPG (186.82 KiB) Viewed 618 times
DSC01724.JPG
DSC01724.JPG (161.9 KiB) Viewed 618 times
DSC01725.JPG
DSC01725.JPG (158.45 KiB) Viewed 618 times

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Mon Sep 25, 2017 12:52 pm

That's a nice looking arm. Is that your own design?

We can't really follow all the wires or see any of the soldering. But if it is running motor #1 OK, the soldering is likely not the problem.

Currently Motor #1 is disconnected because even though the sketch is edited it wants to run #1

That statement suggests that there may be a problem with the upload. Are you sure that your modified program to run motor #2 is uploading without error?

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Motor Shield v2

by lardot on Mon Sep 25, 2017 1:10 pm

Yes, my design but still has a few changes coming. You are probably right that the program didn't load although I am not sure why. Is there a chance that the original test sketch would block the loading of the edited program? If that is the case does the memory have to be cleared first? By the way I wouldn't know how to do that. Thanx again.

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Mon Sep 25, 2017 1:16 pm

You should not need to clear the previous program. The new one should just over-write it. What type of Arduino processor are you using? When you do the upload of the new program, do you see any error messages?

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Motor Shield v2

by lardot on Mon Sep 25, 2017 1:49 pm

I am using the arduino uno and I am not receiving any error messages. Should I be checking voltages to see what is going where?? I am glad they overwrite. Just curious, would a small program overwrite a larger one without something left over? Obviously, I am new to programming so I appreciate your help. Thanx.

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Mon Sep 25, 2017 2:29 pm

The new program should completely replace the previous one - regardless of size. The UNO you are using does not require any special procedure or preparation to upload. Just use the upload button on the IDE.

From the photos, we can't quite follow the wires to the motors. Can you post a diagram of how you have them wired?

If you have a multimeter, you should see the voltage on on the motor terminals ramp up and down to from positive to negative voltages.

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Motor Shield v2

by lardot on Mon Sep 25, 2017 4:24 pm

I will check Voltage after I buy a multimeter. The jpg will show how the wires are connected. From the encoders, wires 1, 2 & 6 (gnd) are connected to M1, M2, M3 & M4. Wires #3, 4 & 5 don't have a home yet.
Attachments
Untitled 1.jpg
Untitled 1.jpg (251.29 KiB) Viewed 570 times

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Mon Sep 25, 2017 4:33 pm

From the encoders, wires 1, 2 & 6 (gnd) are connected to M1, M2, M3 & M4.

Only the M1 and M2 wires from the encoders should be connected to the motor terminal blocks on the shield.

From the photo posted, we can't see what screw terminals each of the wires is going to.

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit Motor Shield v2

by lardot on Tue Sep 26, 2017 11:26 am

Sorry that wasn't a clear picture but M1 & M2 from the encoder are attached to the motor terminal blocks as you have said they should be. I think what you stated earlier in one of your posts was that the edited program was not successfully loaded. I don't know why that is yet but that is what I will try to explore. Thanx again for your help.

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by lardot on Wed Sep 27, 2017 12:01 pm

Hi Bill,
Just a followup for all your effort. The upload problem turned out to be the default port was wrong on the laptop. Once corrected communication works as do the motors. Thanx again.

lardot
 
Posts: 20
Joined: Thu Jul 06, 2017 4:52 pm

Re: Adafruit Motor Shield v2

by adafruit_support_bill on Wed Sep 27, 2017 12:35 pm

That is good to hear. Thank you for the follow-up :)

adafruit_support_bill
 
Posts: 72786
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.