Show Posts
Pages: 1 [2]
16  Using Arduino / Motors, Mechanics, and Power / Re: Looking for some help in stopping this motorized potentiometer midway on: December 02, 2012, 06:15:13 am
Ah, yeah, that makes sense. Thanks!
17  Using Arduino / Motors, Mechanics, and Power / Re: Looking for some help in stopping this motorized potentiometer midway on: December 01, 2012, 11:45:42 pm
Hey, this looks great and is really helpful. I'm just a bit confused about the buttons, considering my buttons are on a TouchOSC interface and don't necessarily have a HIGH or LOW state. I just have serial communication coming in.
18  Using Arduino / Motors, Mechanics, and Power / Re: Looking for some help in stopping this motorized potentiometer midway on: December 01, 2012, 03:07:43 pm
Thanks for following, I'll be checking this in a bit later this afternoon.

As for the remapping code
Code:
pos = map(pos, 0, 1023, 0, 110); //remap positioning to scale of 0-100

I actually did that on purpose because it was the readings I was getting were a bit under. 100% on the far end read 90, so I just added 10.
19  Using Arduino / Motors, Mechanics, and Power / Re: How can I control speed and position of a motorized slide pot w/ an H-bridge? on: December 01, 2012, 01:14:40 am
Project progress & concerns moved to this thread: http://arduino.cc/forum/index.php/topic,135074.0.html
20  Using Arduino / Motors, Mechanics, and Power / Looking for some help in stopping this motorized potentiometer midway on: December 01, 2012, 01:12:05 am
So I'm controlling this motorized linear pot: (https://www.sparkfun.com/products/10976)
via TI SN754410 H-Bridge.

I'm using TouchOSC (custom interface made thru TouchOSC editor) running through the oscP5 and serial libraries in Processing to communicate with the Arduino.

I've got the main objective down - https://www.youtube.com/watch?v=R4vXC0ugHZA&feature=plcp

What I'm looking for though more specifically is how to get the motor to stop midway based on it's position reading.

Any help's appreciated!

Here's the Arduino code I have so far:

Code:
//=====INITIALIZE PINS========

int switchPin = 7;    // switch input
int motor1APin = 6;    // H-bridge leg 1 (pin 2, 1A) PWM
int motor2APin = 5;    // H-bridge leg 2 (pin 7, 2A) PWM
int enablePin = 9;    // H-bridge enable pin
int lineTrack = 5;    //line track for position reading

int incomingByte;   // for incoming serial data

//=====INITIALIZE PINS========

void setup(){

  Serial.begin(57600);   

  // set the switch pin and line track as inputs:
  pinMode(switchPin, INPUT);
  pinMode(lineTrack, INPUT);

  //set the motor logic pins and enable pin as outputs
  pinMode(motor1APin, OUTPUT);
  pinMode(motor2APin, OUTPUT);
  pinMode(enablePin, OUTPUT);

}

void loop() {

  // set enablePin high so that motor can turn on:
  digitalWrite(enablePin, HIGH);

  if (Serial.available() > 0) {

    // read the incoming byte data from Processing:
    incomingByte = Serial.read();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }

  //Move motor forward if truth is told
  if (incomingByte == 65) {
    motorForward();
  }

  //Move motor forward if lie is told
  else if(incomingByte == 66) {
    motorBackward();
  }

  else if(incomingByte == 67){

    //Obtain position reading
    int pos = analogRead(lineTrack);  //read the line positioning
    pos = map(pos, 0, 1023, 0, 110); //remap positioning to scale of 0-100
    //For proper readings, insert 2 to A5, 3 to 5V, 1 to GND

    if (pos >= 100) {
      motorBackward();
      motorStop();
    }

    else if (pos <= 10) {
      motorForward();
      motorStop();
    }
  }
}

void motorForward(){     
  analogWrite(motor1APin, 30);   
  analogWrite(motor2APin, 150);
}

void motorBackward(){
  analogWrite(motor1APin, 150); 
  analogWrite(motor2APin, 30); 
}

void motorStop(){
    analogWrite(motor1APin, 255); 
    analogWrite(motor2APin, 255);
  }
}
21  Using Arduino / Motors, Mechanics, and Power / Re: How can I control speed and position of a motorized slide pot w/ an H-bridge? on: November 24, 2012, 07:55:14 pm
Ooh, silly error there. Thanks for noticing that. I'll have to try it back out when I'm at the lab (don't have my Arduino on me). Ideally, I'm trying to have the slider stop midway so I'd have three inputs and three outputs (forward all the way, backward all the way, middle position). I'll read the links you sent over in a bit.
22  Using Arduino / Motors, Mechanics, and Power / Re: How can I control speed and position of a motorized slide pot w/ an H-bridge? on: November 24, 2012, 07:27:51 pm
I've noticed it goes slower if I apply it 9V instead of 12V, so I may just go with that.

Do you have any recommendations about the motorStop? Or am I out of luck with this motor?
23  Using Arduino / Motors, Mechanics, and Power / How can I control speed and position of a motorized slide pot w/ an H-bridge? on: November 24, 2012, 07:09:32 pm
So I'm trying to control this 10k slide pot (https://www.sparkfun.com/products/10976) with a Texas Instruments SN754410 H-Bridge.

I've been using the DC Motor Control Using an H-Bridge tutorial from ITP as a starting point. As you can see below, I've tidied it up a bit to my liking.

http://itp.nyu.edu/physcomp/Labs/DCMotorControl

Basically, I'm looking to control the movements (motorForward and motorReverse) using OSC commands via TouchOSC on an iPad. But what I'm here for is asking:

(1) how can I control the speed of slide pot?

(2) how can I use the motorStop function I've created? It shoots back and forth way too fast and I'd like to have an option that has it stop in the middle.

I figure I may need to switch from digitalWrite to analogWrite and use PWM in order to achieve this but I'm not quite sure the right combination of frequencies between the two logic pins on the H-Bridge, which the tutorial only describes as a combo of highs and lows.

Any help appreciated.

Code:
const int switchPin = 7; // switch input
const int motorPinA = 6; // H-bridge leg 1 (pin 2, 1A) PWM
const int motorPinB = 5; // H-bridge leg 2 (pin 7, 2A) PWM
const int enablePin = 9; // H-bridge enable pin
const int lineTrack = 5; //line track for position reading

void setup(){

  Serial.begin(9600);

  // set the switch pin and line track as inputs:
  pinMode(switchPin, INPUT);
  pinMode(lineTrack, INPUT);

  //set the motor logic pins and enable pin as outputs
  pinMode(motorPinA, OUTPUT);
  pinMode(motorPinB, OUTPUT);
  pinMode(enablePin, OUTPUT);
}

void loop() {
  // set enablePin high so that motor can turn on:
  digitalWrite(enablePin, HIGH);

  //Obtain position reading
  int pos = analogRead(lineTrack); //read the line positioning
  pos = map(pos, 0, 1023, 0, 110); //remap positioning to scale of 0-100
  //For proper readings, insert 2 to A5, 3 to 5V, 1 to GND

  String stringA = "Sensor value: "; //add string for easier debugging
  String stringA1 = stringA + pos;
  Serial.println(stringA1); //print positioning information

  //Move motor forward if switch is on
  if(digitalRead(switchPin) == HIGH) {
    motorForward();
  }

  //Move motor backward if switch is off
  if(digitalRead(switchPin) == LOW) {
    motorBackward();
  }

void motorForward(){ //potentially add int PWM_val as parameter
  digitalWrite(motorPinA, LOW);
  digitalWrite(motorPinB, HIGH);
}

void motorBackward(){
  digitalWrite(motorPinA, HIGH);
  digitalWrite(motorPinB, LOW);
}

void motorStop(){
  digitalWrite(motorPinA, HIGH);
  digitalWrite(motorPinB, LOW);
}


Pages: 1 [2]