Anon ymous
Published © MIT

Servo Control with Capacitive Touch Using XinaBox

Control a servo with a capacitive touch module utilizing XinaBox technology.

BeginnerFull instructions provided30 minutes925
Servo Control with Capacitive Touch Using XinaBox

Things used in this project

Hardware components

XC10
XinaBox XC10
xBus connectors allow various xChips to be interfaced to one another.
×4
IP01
XinaBox IP01
The FT232R is a USB to serial UART interface device which is equipped to power and program other modules via a USB A connector. The IP01 is required for programming the range of CPU Core xChips over the USB-serial bridge provided by the FT232R.
×1
XinaBox OC05
The OC05 xChip is a servo motor controller driver that uses the PCA9685 PWM controller as servo interface supported by a BU33SD5 regulator to drive and accurately control up to 8 servo motors on a single module and act as system power supply. The module has 8 standard 2.54 mm (0.1") servo headers, plus 1 standard 2.54 mm (0.1") battery/BEC input header.
×1
XinaBox SH01
This xChip is based on the CAP1296 which is a multiple channel capacitive touch sensor controller. The CAP1296 includes Multiple Pattern Touch recognition that allows the user to select a specific set of buttons to be touched simultaneously. If this pattern is detected, a status bit is set and an interrupt is generated.
×1
XinaBox CC01
This xChip is a core CPU module, based on the ATmega328P, which is a single-chip microcontroller. The ATmega328P is the same architecture as Arduino Pro Mini, allowing users to program in the Arduino IDE and other IDEs supporting the Arduino Pro/Pro Mini, such as PlatformIO and Mbed.
×1
Servo motor
Servo capable of 90° rotation in both directions.
×1
5V USB Power Supply
Power to xChips.
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

CapTouchServoControl.ino

Arduino
Upload to Arduino Pro Mini board using the Arduino IDE.
// system includes
#include <xCore.h>
#include <xOC05.h>
#include <xSH01.h>

// system defines
#define SERVO_CHANNEL 1   // OC05 channel number. Corresponds with OC05 xChip
// values obtained experimentally 
#define SERVO_MAX 650
#define SERVO_MIN 100
#define SERVO_CENTER 250

// xchip instances
xOC05 OC05;
xSH01 SH01;

void setup() {
  // put your setup code here, to run once:

  // begin serial communication
  Serial.begin(115200);

  // initiate i2c bus
  Wire.begin();

  // start OC05
  OC05.begin();

  // set servo frequency
  OC05.setPWMFreq(50);

  // start SH01
  SH01.begin();
}

void loop() {
  // put your main code here, to run repeatedly:

  // rotate servo to the left if square is touched
  //if (SH01.touchDetected()) {
  if (SH01.squareTouched()) {
    servoLeft();
  }
  // rotate servo to the right if circle is touched
  else if (SH01.circleTouched()) {
    servoRight();
    // rotate servo to the center if triangle is touched
  } else if (SH01.triangleTouched()) {
    servoCenter();
  }
  delay(1000);
}

/*
   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 servoCenter() {
  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
  }
}

Credits

Anon ymous

Anon ymous

10 projects • 2 followers

Comments