Project tutorial
MeArm Controlled by Arduino Uno and TTP229-BSF Touchpad

MeArm Controlled by Arduino Uno and TTP229-BSF Touchpad © CC BY-NC-SA

Instead of using 2-axis joysticks, I decided to use a spare TTP229-BSF capacitive touchpad to control a 4-DoF MeArm robotic arm.

  • 11 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

After returning the MeArm I borrowed from my former company, I wanted to build one for my own and make use of the spare touchpad. This project uses a dusty Arduino Uno Rev3, an old MB102 power supply module and the TTP229-BSF.

There are already many MeArm wiring tutorials and assembling guides exist, so I won't go for these details. Just remember to calibrate your MeArm properly.

Wiring

Servo signal cable:

  • Servo 1 (base servo) -> Pin 3
  • Servo 2 (right servo) -> Pin5
  • Servo 3 (left servo) -> Pin 6
  • Servo 4 (claw servo) -> Pin 9

TTP229-BSF:

  • VCC -> 3.3V
  • GND -> GND
  • SCL -> Pin 13
  • SDO -> Pin 12

The MB102 output 5V (750mA) for Arduino Uno (powered via its 5V pin and another GND) as well as all servos.

Since the whole system is connected together, connecting Arduino and PC with a USB type-B cable also works (the 5V pin is said to be able to output 500mA). However, since mini servos may draw 100-200mA, using MB102 is probably still a better idea.

The MB102 is powered via a 7.5V 1A charger. The MB102 needs at least 6.5V to be able to provide steady 5V output.

In order to minimize the chance of accidentally touching nearby keys, I selected keys in separate places. However it is possible to assign any keys you want in the code. Servo pins and turning speed is also adjustable.

The touchpad should avoid other things too, for it's also sensitive for touches from sides or under.

How to read TTP229-BSF

Unlike its I2C-version brother TTP229-LSF, the BSF version uses a rather simple 2-wire serial protocol.

First you need to set the hardware to enable 16-key / multiple key mode:

Connect P1-3 (TP2), P1-4 (TP3) and P2-5 (TP4) with resistors. Here I used 10KΩ ones.

(Originally I used simple wires, but the keypad didn't work well in that case. And the datasheet actually said the modes are "selected via high-value resistor(s)".)

TP2 set it to 16-key mode and TP3/TP4 set it to multiple key mode (that you can press more than one keys at the same time).

The protocol is as below:

So: you pull the SCL pin low than high 16 times, and the SDO pin would respond as pulling low (key i+1 pressed) or high (key i+1 not pressed).

#define SCL_PIN 13
#define SDO_PIN 12
  
int keypad[16];
  
void readKeypad() {
 for (int i = 0; i < 16; i++) {
   digitalWrite(SCL_PIN, LOW);
   keypad[i] = digitalRead(SDO_PIN);
   Serial.print(keypad[i]);
   digitalWrite(SCL_PIN, HIGH);
 }
 Serial.println("");
}
  
void setup() {
 Serial.begin(9600);
 pinMode(SCL_PIN, OUTPUT);
 pinMode(SDO_PIN, INPUT);
}
  
void loop() {
 readKeypad();
 delay(100);
}

The code is based on this sketch (hooray for this nameless hero! There are simply too many over-complicated code online), however it can get only one key as result. I simply read all 16 responses of the SDO pin together and put them into an array.

If you open the serial monitor window you can see live status of all keys:

Code

MeArm controlled by TTP229-BSF 16-key capacitive touchpadC/C++
// MeArm controlled by TTP229-BSF 16-key capacitive touchpad
// by Alan Wang

#include <Servo.h>

// hardware setup for TTP229-BSF:
// use resistors to connect P1-3 (TP2), P1-4 (TP3) and P2-5 (TP4) on the touchpad, 
//   in order to enable 16-key mode and all multiple-key mode.
//   see https://www.sunrom.com/get/611100 for more information.
// VCC -> 3.3V
// GND -> GND
// SCL -> 13
// SDO -> 12
#define SCL_PIN               13
#define SDO_PIN               12

// servo and touchpad settings
#define SERVO1_PIN            3   // base servo (servo 1)
#define SERVO2_PIN            5   // right side servo (servo 2)
#define SERVO3_PIN            6   // left side servo (servo 3)
#define SERVO4_PIN            9   // claw servo (servo 4)
#define SERVO_DEGREE_DELTA    3   // servo 1-3's gradually turning angle (bigger -> faster)
#define LOOP_DELAY_MS         25  // delay time for loop() (smaller -> faster)
#define SERVO_DEFAULT_DEGREE  90  // servo 1-3's default position
#define SERVO_MIN_DEGREE      30  // all servo's min angle
#define SERVO_MAX_DEGREE      150 // all servo's max angle
#define SERVO1_TO_MIN_KEY     11  // Touchpad key for moving servo 1 toward min position
#define SERVO1_TO_MAX_KEY     10  // Touchpad key for moving servo 1 toward max position
#define SERVO2_TO_MIN_KEY     8   // Touchpad key for moving servo 2 toward min position
#define SERVO2_TO_MAX_KEY     4   // Touchpad key for moving servo 2 toward max position
#define SERVO3_TO_MIN_KEY     5   // Touchpad key for moving servo 3 toward min position
#define SERVO3_TO_MAX_KEY     1   // Touchpad key for moving servo 3 toward max position
#define SERVO4_SWITCH_KEY     13  // Touchpad key for cycling servo 4 between min/max position
#define MEARM_TO_DEFAULT_KEY  16  // Touchpad key for turning all servos to default position


// variables
Servo servo[4];
int servo_pin[4] = {SERVO1_PIN, SERVO2_PIN, SERVO3_PIN, SERVO4_PIN};
int servo_degree[4] = {SERVO_DEFAULT_DEGREE, SERVO_DEFAULT_DEGREE, SERVO_DEFAULT_DEGREE, SERVO_MIN_DEGREE};
boolean claw_open = true;
int keypad[16];
int key_mapping[3][2] = {{SERVO1_TO_MIN_KEY, SERVO1_TO_MAX_KEY}, {SERVO2_TO_MIN_KEY, SERVO2_TO_MAX_KEY}, {SERVO3_TO_MIN_KEY, SERVO3_TO_MAX_KEY}};


// read the status of touchpad
void readKeypad() {

  for (int i = 0; i < 16; i++) {
    digitalWrite(SCL_PIN, LOW);
    keypad[i] = digitalRead(SDO_PIN);
    Serial.print(keypad[i]);
    digitalWrite(SCL_PIN, HIGH);
  }
  Serial.println("");
}


// initialization
void setup() {

  Serial.begin(9600);
  pinMode(SCL_PIN, OUTPUT);
  pinMode(SDO_PIN, INPUT);

  // attach servos and turn to default positions
  for (int i = 0; i < 4; i++) {
    servo[i].attach(servo_pin[i]);
    servo[i].write(servo_degree[i]);
  }
  delay(250);
}


// main program
void loop() {

  // read the status of touchpad
  readKeypad();

  // turn all servos back to default if the key is pressed
  if (keypad[MEARM_TO_DEFAULT_KEY - 1] == 0) {
    for (int i = 0; i < 3; i++) {
      servo_degree[i] = SERVO_DEFAULT_DEGREE;
    }
    servo_degree[3] = SERVO_MIN_DEGREE;
    claw_open = true;
    for (int i = 0; i < 4; i++) servo[i].write(servo_degree[i]);
    delay(250);
  }

  // cycle claw servo if the key is pressed
  if (keypad[SERVO4_SWITCH_KEY - 1] == 0) {
    claw_open = !claw_open;
    if (claw_open) servo_degree[3] = SERVO_MIN_DEGREE;
    else servo_degree[3] = SERVO_MAX_DEGREE;
    servo[3].write(servo_degree[3]);
    delay(250);
  }

  // gragually turn other 3 servos if keys are pressed
  for (int i = 0; i < 3; i++) {
    if (keypad[key_mapping[i][0] - 1] == 0) {
      servo_degree[i] -= SERVO_DEGREE_DELTA;
      if (servo_degree[i] < SERVO_MIN_DEGREE) servo_degree[i] = SERVO_MIN_DEGREE;
      servo[i].write(servo_degree[i]);
    } else if (keypad[key_mapping[i][1] - 1] == 0) {
      servo_degree[i] += SERVO_DEGREE_DELTA;
      if (servo_degree[i] > SERVO_MAX_DEGREE) servo_degree[i] = SERVO_MAX_DEGREE;
      servo[i].write(servo_degree[i]);
    }
  }

  delay(LOOP_DELAY_MS);
}

Schematics

MeArm controlled by TTP229-BSF 16-key capacitive touchpad
Sorry, my Fritzing is dead. And here only one servo is shown.
Uploads2ftmp2fe146de85 63ed 408a b455 2ea8d50df2452fcurciut xij8xnhc71

Comments

Similar projects you might like

Bluetooth Controlled Servo

Project tutorial by JANAK13

  • 14,032 views
  • 18 comments
  • 39 respects

Gesture Controlled Robotic Hand

Project tutorial by Rushabh Jain

  • 941 views
  • 0 comments
  • 6 respects

Remote Controlled Pet Feeder

Project tutorial by Amal Mathew

  • 5,767 views
  • 1 comment
  • 30 respects

Make an Enhanced R2-D2 to Be Controlled by an Android App

Project tutorial by Kutluhan Aktar

  • 1,990 views
  • 0 comments
  • 2 respects

RC Rover Controlled by Gest

Project showcase by Salim Khazem

  • 1,672 views
  • 1 comment
  • 15 respects
Add projectSign up / Login