Adafruit shield not turning dc motor

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tman2001
 
Posts: 5
Joined: Tue Jun 13, 2017 1:41 am

Adafruit shield not turning dc motor

Post by tman2001 »

I would also be even more thankful if someone could help me with the new code I'm trying to write.
it's like midnight so you'll have to excuse me being bland (and sadly ....I'm kinda a noob sry).


the code itself seems to work fine, however, after setting it all up, it just won't turn the darn motor. Everything seems to be set up fine and the values in the Serial monitor seem good, but the board won't sends the current to the motor whatsoever.
I have a 12v 60rpm motor that I'm trying to turn and simply control the throttle with a joystick.
I've messed with the code some (probably screwed it up) but everything seems to be going according to plan,,,,,,, except the motor won't turn.
I don't think the board or the shield is malfunctioning, but Idk. I'm open to any suggestions.
THX FOR THE HELP

I got some of the original code from viewtopic.php?f=25&t=11119
----------------------------------------------------------------------------------------------------------------------------------

Code: Select all

#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *motor1 = AFMS.getMotor(2);

void setup()
{
  Serial.begin(9600); //serial library start
  


  // turn on motor
  motor1->setSpeed(250);  
  motor1->run(RELEASE);
delay(3000);
}


void loop()
{  
   int RCval1 = analogRead(8);
   int  adj_val1 = map(RCval1, 510, 1023, 0, 255);  // my observed RC values are between 630-1125.. these might need to be changed, depending on your RC system.

    delay (20);
    //motor1
    if (adj_val1 > 136) {             
    motor1->run(BACKWARD); 
    motor1->setSpeed(255);    //motor1->setSpeed(adj_val1 - 36);
    Serial.print ("   GOING BACK  ");
  }
    else if (adj_val1 < 120) {             
    motor1->run(FORWARD); 
    motor1->setSpeed(adj_val1+adj_val1*2);;    //    motor1.setSpeed(220 - adj_val1);
    Serial.print ("  FORWARD  ");
  }
    else{
    motor1->run(RELEASE);
    Serial.print ("  STOP  ");
  }
    
  
  Serial.print ("val1: ");
  Serial.print (RCval1);  // if you turn on your serial monitor you can see the readings.
  Serial.print ("       ");
  Serial.print ("adjusted:  ");
  Serial.print (adj_val1);
  Serial.println ("  ");
    Serial.print (adj_val1 - 36);
      Serial.print (220 - adj_val1);
}
Last edited by adafruit_support_carter on Tue Jun 13, 2017 11:56 am, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit_support_carter
 
Posts: 29469
Joined: Tue Nov 29, 2016 2:45 pm

Re: Adafruit shield not turning dc motor

Post by adafruit_support_carter »

As a way to test your setup - can you get the motor to work using one of the examples sketches from the library?

User avatar
tman2001
 
Posts: 5
Joined: Tue Jun 13, 2017 1:41 am

Re: Adafruit shield not turning dc motor

Post by tman2001 »

first off thanks for helping

yes , the motor works fine on the "test dc motor "

User avatar
adafruit_support_carter
 
Posts: 29469
Joined: Tue Nov 29, 2016 2:45 pm

Re: Adafruit shield not turning dc motor

Post by adafruit_support_carter »

Looks like you're missing a call to AFMS.begin(); in your setup().
https://learn.adafruit.com/adafruit-mot ... controller

User avatar
tman2001
 
Posts: 5
Joined: Tue Jun 13, 2017 1:41 am

Re: Adafruit shield not turning dc motor

Post by tman2001 »

YES !!!

User avatar
tman2001
 
Posts: 5
Joined: Tue Jun 13, 2017 1:41 am

Re: Adafruit shield not turning dc motor

Post by tman2001 »

it's still a bit buggy ... it won't turn correctly when turning backwards, it kinda stutters after about 150/255 speed... but I think it's just the code which is made for a different joystick.

User avatar
adafruit_support_carter
 
Posts: 29469
Joined: Tue Nov 29, 2016 2:45 pm

Re: Adafruit shield not turning dc motor

Post by adafruit_support_carter »

Looks like you print out the raw joystick value (RCval1) in your loop. You could use that to make sure the values your joystick produces work for the ones used in the map() function.

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

Return to “Arduino Shields from Adafruit”