Fireduino Buy

Dual-Core Cortex-M3 processor, integrated high-quality audio Codec and WiFi module, have IOT expansion performance, perfectly compatible with the Arduino interface and Arduino IDE programming, and supports FireBlock graphics programming.

Servo

Update time:2018-04-13 Views:4519

Servo

Fireduino Servo library allows Fireduino control servo board. Servo integrated reduction gear and a spindle can be precisely controlled. Standard servos allows spindle positioning to a different angle, usually in the range 0 to 180 degrees. Continuous rotation servos allow the axis of rotation is set to a variety of different speeds.
Fireduino board supports a maximum of up to 30 servos (each pin can bind with the servo object variable), unbound digital pins and PWM functions do not conflict.

Servo Wiring

Servos have three lines: Power lines, ground and signal lines.Power line is usually red, should be connected to the Fireduino board 5V interface.Ground is usually brown or black, should be connected to the Fireduino  board GND interface.Signal line is usually yellow, orange or white, should be connected to the Fireduino board digital pin interface.
Note that the power steering gear drawings! If you want to drive more than one or two or more servos, you may need an isolated power supply (not Fireduino 5V board).Make sure the ground terminal and the external ground terminal Freeduino power are linked.

Some brands thread color reference
Red, black and white :  White - Signal Red - positive Black - Negative
Orange red and brown  : Orange - Red Signal - brown positive - negative

Servo refer parameter

#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo  #define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo #define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached#define REFRESH_INTERVAL    20000     // minumim time to refresh servos in microseconds

Servo API

attach(...)

   Description 
       The object variable steering gear and pin bindings, Fireduino digital pin member can be bound.
  
   Syntax
       servo.attach(pin)
       servo.attach(pin, min, max)

   Parameter 
       servo : Object servo
       pin: Pins numbered bound
       min : Pulse width, the minimum angle (0 to angle) in microseconds, corresponding to the servo (the default is 544)
       max: Pulse width, maximum angle (angle to 180) in microseconds, corresponding to the servo, the servo (the default is 2400) 

   Returns 
      Internal Number Index

detach()

   Description 
       Unbind SerVo objects and pin.
  
   Syntax
       servo.detach();

   Parameter 
       None

   Returns 
      None

write(...)

   Description 
       Writes an array to the steering gear control corresponding spindle. Standard rudder chance to set the angle of the spindle and move the spindle to the target location.
   For a continuous rotation servo, this will set the servo speed (0 means full speed in one direction, 180 indicates the opposite direction at full speed, said value of about 90 stops).
  
   Syntax
       servo.write(angle);

   Parameter 
       servo: Object variable servo
       angle: Write servo values range from 0 to 180 degrees.

   Returns 
      None

writeMicroseconds(...)

   Description 
       Write a microsecond unit value (uS) to the steering gear control corresponding spindle. Standard rudder chance to set the angle of the spindle.
   Standard steering gear set 1000 is fully counterclockwise position, 2000 is fully clockwise position, while in the middle of 1500 (ie 1.5ms).
  
   Syntax
       servo.writeMicroseconds(uS);

   Parameter 
       servo: Variable servo type
       uS: Microsecond value

   Returns 
      None

read()

   Description 
       Read the current Servo angle.
  
   Syntax
      servo.read();

   Parameter 
       None

   Returns 
      current Servo angle.

readMicroseconds()

   Description 
       Read the current value of the servo microseconds.
  
   Syntax
       servo.readMicroseconds();;

   Parameter
       None

   Returns 
      The current value of the servo microseconds.

attached()

   Description 
      Check servo variable is bound to the pins.
  
   Syntax
       servo.attached();

   Parameter
       None

   Returns
      If the steering gear is already bound to return True, otherwise False

Servo Example

#include <Servo.h>Servo myservo;  // create servo object to control a servo// twelve servo objects can be created on most boardsint pos = 0;    // variable to store the servo positionvoid setup(){
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object}void loop(){
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degreemyservo.write(pos);              // tell servo to go to position in variable 'pos'delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {myservo.write(pos);              // tell servo to go to position in variable 'pos'delay(15);                       // waits 15ms for the servo to reach the position
  }}