I built this project to illustrate how a servo can be controlled using a capactive touch input. The servo driver is the OC05 xChip based off the PCA9685 and the capactive touch input is the SH01 based off CAP1296. The operation of the project is such that the user can press a 'button' on the SH01 to manoeuvre a servo 90° and 180° in either direction.
Step 1: Download Necessary FilesYou will need the following libraries and software:
- xCore- XinaBox Core Library
- xOC05 - PCA9685 Servo Driver
- xSH01 - CAP1296 Capacitive Touch Input
- Arduino IDE - Development environment
Click here to see how to install the libraries.
Once you've installed the Arduino IDE, open it up and select the "Arduino Pro or Pro Mini" as the board to upload your program to. Also make sure the ATmega328P (5V, 16MHz) processor is selected. See image below.
Assemble the project as per image below. A user simply needs to click together the xChips (general name for each module) using XC10 bus connectors. Connect the servo to channel 1 on the OC05 or which ever channel is desired as long as you account for the change in the code. The channel numbers are conveniently indicated on the OC05.
Insert IP01 into an available USB port on your computer. The Arduino IDE will detect the a new COM port; select it before trying to upload. Copy and paste the code under the code section into the Arduino IDE and upload the program to CC03 (Arduino Pro Mini clone).
The code below contains the functions responsible for positioning the servo. Comments are added explaining the functionality. View the entire code in the code section for a better understanding.
/*
Rotate servo 180 degree to the left
*/
void servoLeft(void) {
for (uint16_t pulselen = SERVO_MIN; pulselen < SERVO_MAX; pulselen++) {
OC05.setPWM(SERVO_CHANNEL, 0, pulselen);
}
}
/*
Rotate servo 180 degree to the right
*/
void servoRight(void) {
for (uint16_t pulselen = SERVO_MAX; pulselen > SERVO_MIN; pulselen--) {
OC05.setPWM(SERVO_CHANNEL, 0, pulselen);
}
}
/*
Rotate servo 90 degree in either direction
*/
void servoCentre() {
for (uint16_t pulselen = SERVO_CENTER;;) {
if (pulselen < SERVO_MIN) {
pulselen--;
} else if (pulselen > SERVO_MAX) {
pulselen++;
}
OC05.setPWM(SERVO_CHANNEL, 0, pulselen);
if (pulselen == SERVO_CENTER) break; // exit loop when servo positions itself in the center
}
}
Step 4: OperationOnce you've verified that code has been uploaded you may remove it from the computer. Grab a power bank or 5V USB power supply and insert the IP01 into it. By pressing the triangle touch button the servo will position itself upright (rotate 90°), the square button will rotate the servo to the left 90° relative to the center position and the circle button will rotate the servo 180° relative to left position. The video below demonstrates the operation.
Comments
Please log in or sign up to comment.