How To Use Servos; Controlling A Continuous Rotation Servo; Controlling A Standard Servo - Raspberry Pi RoboPi User Manual

Hide thumbs Also See for RoboPi:
Table of Contents

Advertisement

RoboPi v1.00

How to use Servos

#include <stdio.h>
#include "RoboPiLib.h"
#define LEFT_SERVO
#define RIGHT_SERVO
#define SERVO_MIN
#define SERVO_MAX
#define SERVO_REV
int main(int argc, char *argv[]) {
int i;
RoboPiInit("/dev/ttyAMA0",115200);
pinMode(LEFT_SERVO, SERVO);
pinMode(RIGHT_SERVO, SERVO);
while (1) {
for(i=SERVO_MIN;i<=SERVO_MAX;i+=100) {
servoWrite(LEFT_SERVO, i);
servoWrite(RIGHT_SERVO, SERVO_REV-i);
printf("LEFT SERVO = %d\n", servoRead(LEFT_SERVO));
printf("RIGHT SERVO = %d\n", servoRead(RIGHT_SERVO));
sleep(1);
}
}
}

Controlling a Continuous Rotation Servo

If you are using continous rotation servos, the above code will cause the two servos run in one
direction, then the opposite direction, at varying speed.

Controlling a Standard Servo

If you are using standard servos, the above code will turn the servos as far as possible in one direction,
then the other direction.
http://Mikronauts.com
User Manual v0.85
0
1
500
2500
(SERVO_MIN+SERVO_MAX)
Copyright 2014 William Henning
20
2014-01-27

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RoboPi and is the answer not in the manual?

Questions and answers

Table of Contents