Products > Embedded Computing

Why? Arduino Servo. Pot. LED

(1/4) > >>

metrologist:
Arduino sets the servo position via a pot. The LED lights when the servo function moves the servo to a new position.

When I physically twist the servo, the LED comes on and I don't know why?

My loop just calls these two functions. The first reads a pot pin 5 times and maps an average to degrees. The second moves the servo.


--- Code: ---void pot3(){ 
  pot = 0;
  for (int i=1; i <= 5; i++){
    pot = pot + analogRead(potpin);
  }
  pot = map(pot/5, 0, 1023, 0, 180);
}

void servo1x(int pos, int dlyx) {
  if (pos < pos1)
  {
    digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
    for(int i = pos1; i >= pos && i >= servo1start; i--)    // goes from degrees to degrees
    {                               
      servo1.write(i);              // tell servo to go to position in variable 'pos'
      delay(dlyx);                      // waits ms for the servo to reach the position
      pos1 = i;
    }
    digitalWrite(13, LOW);  // turn the LED off (LOW is the voltage level)
  }
  else if (pos > pos1) {
    digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
    for(int i = pos1; i <= pos && i <= servo1stop; i++) // goes from degrees to degrees
    {                                  // in steps of 1 degree
      servo1.write(i);              // tell servo to go to position in variable 'pos'
      delay(dlyx);                      // waits ms for the servo to reach the position
      pos1 = i;
    }
    digitalWrite(13, LOW);  // turn the LED off (LOW is the voltage level)
  }
}

--- End code ---

Just because I apply pressure to the servo there is no way Arduino can know about it, so why does LED come on? It is very consistent with pressure too. It goes from a flicker to strong brightness with more pressure.

Also, at the endpoints of my pot, the servo is not stable and twitches constantly.

Finally, I have an LCD function that will print the current angle. If I include a call to that function, none of the above happens and the servo takes consistent coarse steps to any new position.

it's more complex than it needs to be and works fine, but maybe takes a bit of time...?

--- Code: ---void  lcd2(){
  // picture loop
  u8g.firstPage(); 
  do {
    draw2();
  }
  while( u8g.nextPage() );
  xPos = xPos + 14;
  if (xPos >= 128) xPos = 0;
  if (++yPos >= 76) yPos = 0;
}


void draw2() {
  //graphic commands to redraw the complete screen should be placed here 
  //u8g.setFontPosTop();
  //u8g.setFont(u8g_font_unifontr);
  u8g.setFont(u8g_font_fub11); //fub11, 14, 17, 20, 25
  u8g.setPrintPos(0, 12);
  u8g.print(pot);
  u8g.print("deg ");
  u8g.drawStr(xPos, 62, "."); //scrolling marq2uee
}

--- End code ---

Simon:
Does the servo not have any feedback ? like a built in pot that the arduino reads to see it's position? or is the servo a self contained closed loop one?

metrologist:
It is a regular servo, with PWM input pin and two power pins. Arduino just sets PWM on a pin and there is no read function. The servo has a pot to know where it is and some circuit to read that and move the motor to the PWM position.

I take it back, if I include LCD function. I just have to twist servo a lot. AND, the degrees change on my LCD as I fight the servo...

ebastler:
The servo has an internal feedback loop, of course. So as you (try to) turn it manually, it will sense that and drive its motor, to try and stay at the position which the PWM signal from the Arduino requests. I'm wondering whether you might be dealing with a hardware issue here? Spikes from the motor current messing with the local ground level, and hence causing the LED to flicker?

metrologist:
Oh, I think it's simple. The servo is powered from Arduino and loads the supply, changes the ADC reference and thinks the pot moved.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod