Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Problem With Array on: July 20, 2014, 01:58:00 pm
Ah, possibly. It's the pro mini 5v.
2  Using Arduino / Programming Questions / Re: Problem With Array on: July 19, 2014, 06:01:07 pm
Ok, thanks for the heads up about i reseting it back to 0, I completely forgot to do that.  I'm planning on multiplying those floats by 10 so that they're ints before coming into arduino, I just haven't done it yet, so I let the arduino round it for me just for testing. Serial monitor is 9600, and the analogWrite function works fine if I'm just using it in the loop without the array business.  I've never had to initiate analogWrite pins as output, and when I have it causes problems.  Also, just to be sure it wasn't the library screwing with things, I removed it and I'm having the same issue.
3  Using Arduino / Programming Questions / Re: Problem With Array on: July 19, 2014, 05:36:51 pm
Here's the semi-full sketch.  The full one has two sets of arrays, each with 1200 numbers.

Code:
#include <PWM.h>

int dir = 12;   
int motorSpeedPin = 9;
int32_t frequency = 20000; //frequency (in Hz)

int forward = LOW;
int reverse = HIGH;

int motorSpeed = 180;


int numDensityReading = 1200;
int protonDensity[] = {
  1.5, 1.5, 1.2,
  1.1,
  1.2,
  1.6,
  1.4,
  1.6,
  -9999.9,
  -9999.9,
  1.8,
  2.1,
  1.5,
  1.8,
  1.7,
  1.3,
  1.5, };


int numSpeedReadings = 1200;
int bulkSpeed[] = {
  3346, 3320, 3340,
  3334,
  3301,
  3287,
  3188,
  3156,
  2836,
  2875,  };

int i = 0;
int ii = 0;
int bS;
int pD;


long lastReadingDelay = 0;
long readingDelay = 10000;

void setup(){
  Serial.begin(9600);
  InitTimersSafe();
  bool success = SetPinFrequencySafe(motorSpeedPin, frequency);
  if(success) {
    Serial.println("Frequency Successfully Set.");
  }
  pinMode(dir, OUTPUT);
  //  pinMode(button0, INPUT_PULLUP);
  //  pinMode(button1, INPUT_PULLUP);
  digitalWrite(dir, forward);

}

void loop(){

  if(millis() - lastReadingDelay > readingDelay){
    i = i ++;
    //    ii = ii ++;

    bS = bulkSpeed[i];
    //     pD = protonDensity[i];
    bS = constrain(bS, 2883, 3000);
    bS = map(bS, 2883, 3000, 180, 255);
    lastReadingDelay = millis();
    //    Serial.print("bulkSpeed = ");
    Serial.println(bS);
    //    Serial.print(",");
    //    Serial.println(pD);
    analogWrite(motorSpeedPin, bS);

  }




}






4  Using Arduino / Programming Questions / Problem With Array on: July 19, 2014, 05:17:50 pm
Code:
  if(millis() - lastReadingDelay > readingDelay){
    i = i ++;
    //    ii = ii ++;

    bS = bulkSpeed[i];
    //     pD = protonDensity[i];
    bS = constrain(bS, 2883, 3000);
    bS = map(bS, 2883, 3000, 180, 255);
    lastReadingDelay = millis();
    Serial.println(bS);
    analogWrite(motorSpeedPin, bS);

  }

Anyone know why this doesn't work?  I can't get the analogWrite to us the bS variable.  Further, whenever I try to Serial.print anything other than Serial.println(bS), i.e. Serial.print("bulkSpeed = "), I just get a bunch of jibberish in my Serial monitor.
5  Using Arduino / Programming Questions / Re: Help with easing/smoothing DC motor on: July 03, 2014, 09:48:05 am
I agree, but at the moment that's not an option.
6  Using Arduino / Programming Questions / Re: Help with easing/smoothing DC motor on: July 02, 2014, 09:14:55 pm
My mechanism is similar to this:



The buttons are at the uppermost and lowest point of that green dot.

The idea is to just slow it down when it's near the start and end of it's max and min reach.
7  Using Arduino / Programming Questions / Help with easing/smoothing DC motor on: July 02, 2014, 08:19:39 pm
I've been working on this for a bit, and going in circles, so I'd like to ask you guys for help on something that's out of my knowledge.

I have a large DC motor that I've attached a linkage to.  As the motor turns, and the linkage is at its maximum distance it hits a button, button0, and at its minimal distance it hits another button, button1.  My code records the amount of time it takes to go from button0 to button1, and from button1 to button0 (they are along a sprocket) and stores it as two independent variables.  What I would like to do is use those variables to smooth the speed of my motor as it reaches the maximum and minimal distance for the linkage.  i.e. if it takes 3000 milliseconds to go from button0 to button1, I would like the motor to start slow at millisecond 0, ramp up to maximum speed at say 1500 milliseconds, then ramp down as it approaches the 3000 millisecond mark.  Thoughts? 

Here's my code:

Code:
void loop()  {

  //  int potValue = analogRead(analogInPin);
  //  motorSpeed = map(potValue, 0, 1023, 180, 255);
  //  analogWrite(motorSpeedPin, motorSpeed);

  analogWrite(motorSpeedPin, 252);

  //Debounce code for the two buttons

  int button0Reading = digitalRead(button0);
  int button1Reading = digitalRead(button1);
  int section0;
  int section1;

  if( (millis() - lastDebounceTime0) > debounceDelay0){
    if(button0Reading == LOW){
      lastDebounceTime0 = millis();
      Serial.print("button0 activated  |  ");
      reading0 = millis();
      //time from button1 to button0
      section0 = (reading0 - reading1);
      Serial.print("Time from button1 to button0 (section0) = ");
      Serial.print(section0);
      Serial.print("  |  Motor speed = ");
      Serial.println(motorSpeed);
      isSection0 = true;
    }
  }

  if( (millis() - lastDebounceTime1) > debounceDelay1){
    if(button1Reading == LOW){
      lastDebounceTime1 = millis();
      Serial.print("button1 activated  |  ");
      reading1 = millis();
      //time from button0 to button1
      section1 = (reading1 - reading0);
      Serial.print("Time from button0 to button1 (section1) = ");
      Serial.print(section1);
      Serial.print("  |  Motor speed = ");
      Serial.println(motorSpeed);
      isSection0 = false;   
    }
  }
}
8  Using Arduino / Motors, Mechanics, and Power / Re: Trouble with H-Bridge on: May 31, 2014, 03:36:14 pm
Awesome.  Thanks for all the info, this is steering me in the right direction for sure!
9  Using Arduino / Motors, Mechanics, and Power / Re: Trouble with H-Bridge on: May 27, 2014, 12:33:28 am
Got it.  So the cap on the 5V/gnd will hold a small amount of current and possibly stave off a voltage drop, as well as eliminate some excess noise. 
10  Using Arduino / Motors, Mechanics, and Power / Re: Trouble with H-Bridge on: May 26, 2014, 08:12:07 pm

Using separate power supplies solves the problem, but I'm eventually going to need to use only one power supply, so I'd rather fix the problem.

I purchased one of these opto-isolators from SparkFun, and hopefully that will do the trick? :

https://www.sparkfun.com/products/9118

The reason I originally replaced the diode is because it only handles one amp, and in my previous circuit, using the Vin to power my motors was pulling 3 amps through it.

Zoomkat - Why do you recommend putting a cap between 5V & ground?

MarkT - Are you suggesting that the MOSFETs I'm using could potentially be generating a magnetic field and interfering with the Arduino because they're too close?

Thanks for the help, it's much appreciated!
11  Using Arduino / Motors, Mechanics, and Power / Re: Trouble with H-Bridge on: May 23, 2014, 11:44:03 pm
Thanks, although that was a pretty obnoxious way help.
12  Using Arduino / Motors, Mechanics, and Power / Trouble with H-Bridge on: May 23, 2014, 10:22:21 pm
So I just built this H-Bridge with some MOSFETs from Sparkfun:



A&D go HIGH for forward
B&C go HIGH for reverse

Here's my code:

Code:


int forward0 = 5;   //input A
int forward1 = 6;    //input D
int reverse0 = 10;    //input B
int reverse1 = 11;    //input C

int analogInPin = A0;  //potentiometer (motor speed selector)

int sensorValue = 0;
int motorSpeed = 0;

void setup()  {
  Serial.begin(9600);
  digitalWrite(A1, HIGH);  //can't reach the 5v pin, using A1 for a positive voltage
}

void loop()  {

  sensorValue = analogRead(analogInPin);

  motorSpeed = map(sensorValue, 0, 735, 0, 255);

  analogWrite(forward1, motorSpeed);
  analogWrite(forward0, 255);
  analogWrite(reverse0, 0);
  analogWrite(reverse1, 0);

  Serial.print("sensor value = ");
  Serial.print(sensorValue);
  Serial.print("  |  motor speed = ");
  Serial.println(motorSpeed);
  delay(100);
}

Everything works fine with a small 3V toy motor, but when I hook it up to my 9/12V - 3 amp car seat motor, the Arduino crashes, and can't control the H-Bridge.  It just turns the motor off and the Serial Monitor stops reading.  I am using the Vin to power my Arduino and motor from a bench top power supply.  I replaced the small protection diode by the barrel jack with one that can handle high current, but I'm still having the same issue.  Any recommendations?
13  Using Arduino / Project Guidance / Re: Using Arduino with a Voltage Regulator on: May 14, 2014, 11:12:04 pm
Yeah, I'm just trying to avoid dropping $40 on a high amp motor driver.
14  Using Arduino / Project Guidance / Re: State change without input change. (Leonardo) on: May 14, 2014, 11:10:18 pm
Try using the Arduino's internal pullup resistors and play around with setting out1 to LOW.  Also, switch  the LED over to the onboard debugging LED - pin 13.  That way you can test your code and your wiring separately. 


In setup change:

pinMode(in, INPUT);

to:

pinMode(in1, INPUT_PULLUP);
15  Using Arduino / Project Guidance / Using Arduino with a Voltage Regulator on: May 14, 2014, 10:50:32 pm
I've been looking for a solid way to regulate voltage for large motors (i.e. 12v 3 amp) using Arduino.  I've used PWM with transistors and mosfets, but I've noticed that as you lower voltage, you're also lowering current, and with motors, that's overall torque.  Also, PWM can get pretty loud at different frequencies. 

So...I just tried using a digital pot in conjunction with the LM317.  That doesn't seem to work because I'm limited by the voltage that powers the digital pot - 5V, and I'm looking to get 9V on the high end.

Anyone have suggestions on how to use Arduino to create a linear voltage regulator?

Thanks
Pages: [1] 2 3