Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Re: Accel Stepper and Servo at Same Time on: October 24, 2011, 09:37:12 pm
perhaps this should be under coding issues, but if clarification is needed:  I am running the sparkfun easy stepper on pins 12 and 13.  I thought the Accel stepper library was non-blocking, how can I maintain the accelerations and decelerations while focusing at the same time-- with the AF stepper library it was as simple as something like this in the main loop:
Code:
servo.slowmove(45,10);
stepper.step(1,FORWARD,INTERLEAVE);

however, if I am not mistaken, accelstepper library will not implement accelerations without the run() or other such statements..(e.g. runSpeedToPosition())--

some are blocking most are not--- however, run() sure seems to block my loop... no doubt it is how I am implementing but I have tried to break it up into smaller chunks with no luck... looking for some ideas based on experience that I lack.  Thanks in advance.
2  Using Arduino / Motors, Mechanics, and Power / Accel Stepper and Servo at Same Time on: October 23, 2011, 09:57:13 pm
this code is based on the "overshoot" example... it simply ramps the motor one way, stops and ramps the opposite way.

I would also like to have use of a servo via potentiometer at the same time the motor is stepping ( it is for a camera rig with servo for focusing).

what I get is a complete movement to the new position, then a servo move, then a motor move, rather than both at the same time.

what am I doing wrong?

thanks!

dp


Quote
  
  #include <VarSpeedServo.h>
  #include <AccelStepper.h>
  
  AccelStepper stepper(1,12,13);
  VarSpeedServo fServo;
   int goPos=5000;
  #define APOT A2
  
  void setup()
  {
    fServo.attach(10);
   
  }
  int prevRead;
  void loop()
  {    
     
    int potRead = map(analogRead(APOT),0,1023,0,180);
     stepper.setMaxSpeed(3000);
      stepper.setAcceleration(200);
      stepper.runToNewPosition(0);
      stepper.move(goPos);
      
      while (stepper.currentPosition() !=goPos){
        stepper.run();
        fServo.slowmove(potRead,40);
      }
          
      // cause an overshoot as we whiz past 300
      stepper.setCurrentPosition(0);
      goPos=goPos*-1;
  }

3  Using Arduino / Sensors / Re: Using an HS1101 humidity sensor on: September 13, 2011, 02:50:47 am
(using UNO)
Got this circuit working with code below.  Used a storebought humidity gauge to calibrate, according to Parallax datasheet, the function is linear.  Could have tried to calibrate using the result++, but I found the micros() method gave me better results.  Is this off base?  i am a newb.

 Regardless, using a 2M pull down resistor, I get spot on humidity readings using a script that averages mulitple readings of the capacitor decay time in microseconds and is calibrated using a slope of .1667 and offset of -67.00.   -- The averaging gives much more consistent readings than one-off reads.

don't make readDelay too small or it will affect the sensor readings.  An accurate read could take a few seconds if your sample size is large.

thoughts?  i am sure this script could be tidied up a bit... would love feedback, I am just happy I am getting accurate reads!
Quote
int sensorPin1 = 4;

long result = 0;
unsigned long time1=0;
unsigned long time2=0;

long readingsPer=20.0;
long readDelay=200.0;

#define RH1(time) ((.1667*time)-67)

void setup()                    // run once, when the sketch starts
{

  Serial.begin(9600);
  Serial.println("start");      // a personal quirk
}
void loop()                     // run over and over again
{
  long H=RH1(evalHumid(readingsPer, sensorPin1));
  Serial.println("_____");
  Serial.println(H);
  Serial.println("_____");
  delay(1000);

}

long evalHumid(long samples, int sPin){
  long avgtime=0;
  for (int i=0;i<samples;i++){
    RCtime(sPin);
    avgtime+= decayTime(3);
  }
  avgtime=avgtime/samples; 
  return(avgtime);

}

long RCtime(int sensPin){
  long result = 0;
  pinMode(sensPin, OUTPUT);       // make pin OUTPUT
  digitalWrite(sensPin, HIGH);    // make pin HIGH to discharge capacitor - study the schematic
  delay(1);                       // wait a  ms to make sure cap is discharged

  pinMode(sensPin, INPUT);  // turn pin into an input and time till pin goes low
  digitalWrite(sensPin, LOW);// turn pullups off - or it won't work
  decayTime(1);  
  while(digitalRead(sensPin)){    // wait for pin to go low
    //result++;
  }
  decayTime(2);
  delay(readDelay);
  //return result;                   // report results   
}

long decayTime(int input){
  if (input==1){
    time1=micros();
  }
  if (input==2 ){
    time2=micros();
  }
  if (input==3){
    return (time2-time1);
  }
}

4  Using Arduino / General Electronics / Lead Acid Battery- Arduino UNO on: August 23, 2011, 10:11:11 am
Found a 12v 7Ah lead acid battery.  A multimeter reads it outputting 13v.  Will this damage an Arduino Uno if plugged into the power input?
Thanks in advance.

dp
Pages: [1]