Hi, and again thank you for your time. I'm using an Arduino Uno and an Adafruit motor shield. I am working on a project for mechanical engineering and I need lots of amps for lots of torque for my mechanism. I'm including my code although I know it doesn't work, I haven't had the chance to debug it yet, and I'm really not sure if I'm on the right track.
So I know that it's possible to draw more amperage than is strictly allowed from the arduino. What I don't know for sure is how to code it. Attached is my preliminary attempt.. I kind of assumed that the maximum speed would be the maximum allowable speed of the motor, regardless of the arduino's capabilities, and scaled the output MAXampDrawSpeed as a function of that. To be specific, my motor can draw up to 20 amps, which would be too much for the arduino to handle, so I scaled it down accordingly, with 255 being that maximum 20 amp output. I'm not sure if I'm on the right track there.
So the other problem is - the TA for my class made a simplified code reference file, sort of predefining a lot of the things that I manually defined in my code (or tried to at least). I didn't realize this, and when I asked him a question, he sort of shot me down and said "you should use my reference code" --- but his code doesn't compile for me. I had some problems with libraries (I fixed them!), but this isn't a library.. it's a reference file, like the tabs up at the top. But it won't even compile for me. My feeling is that I may have annoyed him with my many many stupid questions up til this point and he's just kind of like "girl get it together"... So the question there is -- am I almost there with my track or should I figure out what's wrong with his code and try to fix it his way so that I can ask him questions without being such a bother to him? And also is that likely to be a hindrance on drawing the extra amperage that I really really want? I am prepared to use heat dissipation methods as are necessary, and any advice you could give me there would also be appreciated.
If you need any more information, about my mechanism or anything I'd be glad to share that as well. I'm parallel mounting one motor to the four dc motor mounts on my arduino in order to draw maximum current in that way as well. I have two switches controlling the output, one of the switches will engage the program for the maximum distance competition and the other for the accuracy competition.
So again, this code isn't right.. I haven't even started on debugging it.. because I didn't want to waste my time. Maybe you'll be able to follow my logic.. i know there aren't many notes. If you need me to add notes for clarity I would also be glad to take the time to do that.
Thanks!
<#include <Stepper.h>
#include <AccelStepper.h>
#include <Servo.h>
#include <Adafruit_MotorShield.h>
#include <Wire.h>
#include "Arduino.h"
#define STEP_TYPE_1 SINGLE
#define STEP_TYPE_2 SINGLE
#define STEPS_1 200
#define STEPS_2 200
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *DC1 = AFMS.getMotor(1);
Adafruit_DCMotor *DC2 = AFMS.getMotor(2);
Adafruit_DCMotor *DC3 = AFMS.getMotor(3);
Adafruit_DCMotor *DC4 = AFMS.getMotor(4);
Servo Servo1;
void setup() {
digitalWrite(A0, HIGH); //Turns on the pullup resistor for A0
int i = analogRead(A0); //Reads the value on the analog pin and saves this as variable "i"
AFMS.begin(); //Initializes the motorshield board
int motorPin1 = 1;
int motorPin2 = 2;
int motorPin3 = 3;
pinMode(A0, INPUT); //Sets the Analog Pin 0 as an input
digitalWrite(A0,HIGH);
pinMode(A1, INPUT);
digitalWrite(A1,HIGH);
pinMode(A1, INPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
Servo1.attach(9);
}
void loop() {
int distancepin = 0; //Just integer quantities, i like to have too many of them
int accuracypin = 0;
int inPin1 = 0; //switch pin values
int inPin2 = 0;
int MAXampDrawTime = 75;
int MAXampDrawSpeed = 178;
int NORMampDrawTime = 225;
int NORMampDrawSpeed = 61.2;
int DrawTime = MAXampDrawTime+NORMampDrawTime;
int ServoTime = 450;
long previousMillis =0;
long intervalMAXamps = 100;
long intervalNORMamps = 400;
DC1->setSpeed(MAXampDrawSpeed);
DC2->setSpeed(MAXampDrawSpeed);
DC3->setSpeed(MAXampDrawSpeed);
DC4->setSpeed(MAXampDrawSpeed);
inPin1 = digitalRead(A0);
inPin2 = digitalRead(A1);
if (inPin1 == HIGH){
unsigned long time_zero = millis();
unsigned long current_time = millis();
digitalWrite(1,HIGH); //turn motor on to maximum draw amperage
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
while((millis()-time_zero)<(400000)){
if( millis() >= (time_zero+NORMampDrawTime)){
DC1->setSpeed(NORMampDrawSpeed); //set motor on to normal draw amperage
DC2->setSpeed(NORMampDrawSpeed);
DC3->setSpeed(NORMampDrawSpeed);
DC4->setSpeed(NORMampDrawSpeed);
digitalWrite(1,HIGH); //turn motor on to normal draw amperage
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
if ( millis() >= (time_zero+DrawTime));
{
digitalWrite(1,0); //turn off motors
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
}
if (millis() >= (time_zero+ServoTime));{
Servo1.write(0);
delay(400);
Servo1.write(90);
}
}
}
if (inPin2 = HIGH);{
int MAXampDrawTime = 75;
int MAXampDrawSpeed = 59;
int NORMampDrawTime = 225;
int NORMampDrawSpeed = 20;
int DrawTime = MAXampDrawTime+NORMampDrawTime;
int ServoTime = 250;
unsigned long previousMillis =0;
unsigned long intervalHIamps = 100;
unsigned long intervalNORMALamps = 400;
DC1->setSpeed(MAXampDrawSpeed);
DC2->setSpeed(MAXampDrawSpeed);
DC3->setSpeed(MAXampDrawSpeed);
DC4->setSpeed(MAXampDrawSpeed);
unsigned long time_zero = millis();
unsigned long current_time = millis();
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
while((millis()-time_zero)<(500)){
if( millis() >= (time_zero+MAXampDrawTime)){
DC1->setSpeed(NORMampDrawSpeed);
DC2->setSpeed(NORMampDrawSpeed);
DC3->setSpeed(NORMampDrawSpeed);
DC4->setSpeed(NORMampDrawSpeed);
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
}
else( millis() >= (time_zero+DrawTime));
{
digitalWrite(1,0);
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
}
if (millis() >= (time_zero+ServoTime));{
int time_check = millis();
while (millis() - time_check < 400000) {
inPin1 = digitalRead(A0);
if (inPin1 == HIGH ) {
Servo1.write(0);
delay(400);
Servo1.write(90);
}
}
}
}
}}