0

MotorShield v1 work v2 don't work
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MotorShield v1 work v2 don't work

by b0rto on Thu Mar 04, 2021 5:14 pm

hello , i am trying to use a RC controller to move a crawler 4x4 that i bought in the past , the four motors of my tank consume 1,2ah at max power 12V , i have motorshield v1 and v2 , im having problems with motorshield v2 , i have the same code for both and in the v1 the code works fine with my transmitter and in the v2 the code don't move the motors don't do nothing but he get the signals and the board receive the signals also i can for example plug a servomotor and it work on the servo 1 or 2 but motors nope , i use the same code adapted to the new v2 libraries using the right structure i believe.. i checked the serial monitor and the v2 motorshield get the right values the same as the v1 but not move the motors.. is there any difference between both motorshields except the ampers that brings to the motors? my RC trasmitter is PPM/FM and i use the same way to connect both boards pins A0..A3 connected to my receiver 5 channels , i use a Lipo battery 5,2ah 11,1V fully charged give me +/- 12,5V and i power the motorshield V2 and arduino UNO separately 12V/5V without jumper and also the receiver with 5V, if someone can help me i will be very glad because i will be crazy with this , thanks in advance , btw thanks for this big forum full of good things i just discovered it now i am newbye thanks!

code for motorshield V1 that works

Code: Select all | TOGGLE FULL SIZE
#include <AFMotor.h>
#include <Servo.h>

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

 
int ch1,ch2,channel3,ch4, ltrack, rtrack;
const int in1 = A0, in2 = A1, in3 = A2, in4 = A3;
 
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  pinMode(in1, INPUT);
  pinMode(in2, INPUT);
  pinMode(in3, INPUT);
  pinMode(in4, INPUT);

  motor1.setSpeed(255);
  motor1.run(RELEASE);
  motor2.setSpeed(255);
  motor2.run(RELEASE);

  motor3.setSpeed(255);
  motor3.run(RELEASE);
  motor4.setSpeed(255);
  motor4.run(RELEASE);
}
 
void loop() {
  ch1 = pulseIn(in1, HIGH, 35000);
  ch2 = pulseIn(in2, HIGH, 35000);
  channel3 = pulseIn(in3, HIGH, 35000);
  ch4 = pulseIn(in4, HIGH, 35000);
 
  if(ch1 != 0 || ch2 != 0 || channel3 != 0 || ch4 != 0){
    ch1 = constrain(ch1, 970, 1990);
    ch2 = constrain(ch2, 970, 1990);
    channel3 = constrain(channel3, 970, 1990);
    ch4 = constrain(ch4, 970, 1990);
    ch1 = map(ch1, 970, 1990, -100, 100);
    ch2 = map(ch2, 970, 1990, -100, 100);
    channel3 = map(channel3, 970, 1990, -100, 100);
    ch4 = map(ch4, 970, 1990, -100, 100);
   
  Serial.print("canal 1: ");
  Serial.print(ch1);
  Serial.print(", canal 2: ");
  Serial.print(ch2);
  Serial.print(", canal 3: ");
  Serial.print(channel3);
  Serial.print(", canal 4: ");
  Serial.println(ch4);

 
    ltrack = ch2 - ch1;
    rtrack = ch2 + ch1;
    ltrack = constrain(ltrack, -100, 100);
    rtrack = constrain(rtrack, -100, 100);
    if(ltrack > 5){
      motor1.run(FORWARD);
      motor1.setSpeed(map(ltrack, 6, 100, 0, 255));

      motor4.run(FORWARD);
      motor4.setSpeed(map(ltrack, 6, 100, 0, 255));
     
    } else if(ltrack < -5){
      motor1.run(BACKWARD);
      motor1.setSpeed(map(ltrack, -6, -100, 0, 255));

      motor4.run(BACKWARD);
      motor4.setSpeed(map(ltrack, -6, -100, 0, 255));
     
    } else {
      motor1.run(RELEASE);
      motor4.run(RELEASE);
    }
    if(rtrack > 5){
      motor2.run(FORWARD);
      motor2.setSpeed(map(rtrack, 6, 100, 0, 255));

      motor3.run(FORWARD);
      motor3.setSpeed(map(rtrack, 6, 100, 0, 255));
     
    } else if(rtrack < -5){
      motor2.run(BACKWARD);
      motor2.setSpeed(map(rtrack, -6, -100, 0, 255));

      motor3.run(BACKWARD);
      motor3.setSpeed(map(rtrack, -6, -100, 0, 255));
     
    } else {
      motor2.run(RELEASE);
      motor3.run(RELEASE);
    }
  } else {
    motor1.run(RELEASE);
    motor2.run(RELEASE);
    motor3.run(RELEASE);
    motor4.run(RELEASE);

  }
 
 
}



code for motorshield V2 that don't work

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
Adafruit_DCMotor *motor3 = AFMS.getMotor(3);
Adafruit_DCMotor *motor4 = AFMS.getMotor(4);

int ch1,ch2,channel3,ch4, ltrack, rtrack;
const int in1 = A0, in2 = A1, in3 = A2, in4 = A3;

void setup() {
  AFMS.begin();  // create with the default frequency 1.6KHz
   
  Serial.begin(9600); // set up Serial library at 9600 bps
  pinMode(in1, INPUT);
  pinMode(in2, INPUT);
  pinMode(in3, INPUT);
  pinMode(in4, INPUT);

  motor1->setSpeed(255);
  motor1->run(RELEASE);
  motor2->setSpeed(255);
  motor2->run(RELEASE);

  motor3->setSpeed(255);
  motor3->run(RELEASE);
  motor4->setSpeed(255);
  motor4->run(RELEASE);
}
void loop() {
  ch1 = pulseIn(in1, HIGH, 35000);
  ch2 = pulseIn(in2, HIGH, 35000);
  channel3 = pulseIn(in3, HIGH, 35000);
  ch4 = pulseIn(in4, HIGH, 35000);
 
  if(ch1 != 0 || ch2 != 0 || channel3 != 0 || ch4 != 0){
    ch1 = constrain(ch1, 970, 1990);
    ch2 = constrain(ch2, 970, 1990);
    channel3 = constrain(channel3, 970, 1990);
    ch4 = constrain(ch4, 970, 1990);
    ch1 = map(ch1, 970, 1990, -100, 100);
    ch2 = map(ch2, 970, 1990, -100, 100);
    channel3 = map(channel3, 970, 1990, -100, 100);
    ch4 = map(ch4, 970, 1990, -100, 100);
   
  Serial.print("canal 1: ");
  Serial.print(ch1);
  Serial.print(", canal 2: ");
  Serial.print(ch2);
  Serial.print(", canal 3: ");
  Serial.print(channel3);
  Serial.print(", canal 4: ");
  Serial.println(ch4);

 
    ltrack = ch2 - ch1;
    rtrack = ch2 + ch1;
    ltrack = constrain(ltrack, -100, 100);
    rtrack = constrain(rtrack, -100, 100);
    if(ltrack > 5){
      motor1->run(FORWARD);
      motor1->setSpeed(map(ltrack, 6, 100, 0, 255));

      motor4->run(FORWARD);
      motor4->setSpeed(map(ltrack, 6, 100, 0, 255));
     
    } else if(ltrack < -5){
      motor1->run(BACKWARD);
      motor1->setSpeed(map(ltrack, -6, -100, 0, 255));

      motor4->run(BACKWARD);
      motor4->setSpeed(map(ltrack, -6, -100, 0, 255));
     
    } else {
      motor1->run(RELEASE);
      motor4->run(RELEASE);
    }
    if(rtrack > 5){
      motor2->run(FORWARD);
      motor2->setSpeed(map(rtrack, 6, 100, 0, 255));

      motor3->run(FORWARD);
      motor3->setSpeed(map(rtrack, 6, 100, 0, 255));
     
    } else if(rtrack < -5){
      motor2->run(BACKWARD);
      motor2->setSpeed(map(rtrack, -6, -100, 0, 255));

      motor3->run(BACKWARD);
      motor3->setSpeed(map(rtrack, -6, -100, 0, 255));
     
    } else {
      motor2->run(RELEASE);
      motor3->run(RELEASE);
    }
  } else {
    motor1->run(RELEASE);
    motor2->run(RELEASE);
    motor3->run(RELEASE);
    motor4->run(RELEASE);

  }
 
 
}

b0rto
 
Posts: 3
Joined: Thu Mar 04, 2021 4:43 pm

Re: MotorShield v1 work v2 don't work

by adafruit_support_bill on Thu Mar 04, 2021 5:22 pm

im having problems with motorshield v2 , i have the same code for both

That is the problem. The V2 shield is a completely different design and requires the V2 library.
https://learn.adafruit.com/adafruit-mot ... l-software

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

Re: MotorShield v1 work v2 don't work

by b0rto on Thu Mar 04, 2021 5:42 pm

hello and thanks for your fast answer , i readed about this 3 intensive days and if you check both codes aren't equal , the v1 uses the V1 libraries and the V2 uses the v2 libraries i believe.. correct me if im wrong the really problem that i have is that the v1 shield give low ampers to my four motors and i need more ampers.. because they work too low and without force while if i connect 1,2 ampers to them you can't stop them with your fingers is a very big difference otherwise i use v1 motorshield and solved.., thanks in advance.

b0rto
 
Posts: 3
Joined: Thu Mar 04, 2021 4:43 pm

Re: MotorShield v1 work v2 don't work

by adafruit_support_bill on Thu Mar 04, 2021 6:18 pm

Please post the electrical specifications for the motors and power supply you are using.

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

Re: MotorShield v1 work v2 don't work

by b0rto on Thu Mar 04, 2021 6:40 pm

motors:

working voltage: 5 ~ 12v

weight capacity: 6kg

speed out: 150 +/- 10% RPM

current no load: 200mA (Max)

stall current: 4500mA (max)

locking torque: 9,5kg-cm

nominal speed: 100 +/- 10% RPM

nominal torque: 3kg-cm

rated current: 1200mA (max)

noise: 56DB

working voltage: 12V

POWER SUPPLY:

Turnigy High Capacity 5200mAh 3S 12C Lipo Pack w/XT60 from hobbyking

https://hobbyking.com/es_es/turnigy-hig ... -xt60.html

im not sure if i can post links from external webs , if im wrong please remove this link , thanks.

and again thanks for your expended time answering me , valious time that i get from you.

greetings.

b0rto
 
Posts: 3
Joined: Thu Mar 04, 2021 4:43 pm

Re: MotorShield v1 work v2 don't work

by adafruit_support_bill on Thu Mar 04, 2021 7:45 pm

the four motors of my tank consume 1,2ah at max power 12V

I believe you are misunderstanding the specs.
rated current: 1200mA (max)

This is the maximum current that the motor can handle continuously without overheating. It is not the maximum current that the motor will draw.
stall current: 4500mA (max)

This is the maximum current that the motor will draw when powered with the maximum rated voltage (12v). Powered with 11.1V, the stall current will be proportionally lower: 4163mA. This is more than 3x the maximum continuous rating for the V2 motor shield. It is also more than the 3A peak rating for the V2 motor shield.

Startup current is the same as stall current - at least until the motor starts moving. Based on those motor specs, it is likely that you have overloaded the motor shield.

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

Please be positive and constructive with your questions and comments.