User Tools

Site Tools


arduino:ttp229

Quick prototyping Robotdyn TTP229 LSF touch sensor board

http://www.drbit.nl/2017/08/robotdyn_ttp229_lfs_arduino_example/

#include "Wire.h"
 
#define TTP229_LSF 0x57 // Device address (the addressing without the R/W bit) -> 01010111 = 57
 
void setup()
{
  Wire.begin(); // wake up I2C bus
  Serial.begin(9600);
  Serial.println("*Sensor Num.            111111");
  Serial.println("              0123456789012345");
  Serial.println("              ----------------");
}
 
long ct = 0;
 
void getTTP229data(byte *a, byte *b)
{
 
  Wire.requestFrom(TTP229_LSF, 2);    // request 6 bytes from slave device #2
 
  int dataN = 0;
  while (Wire.available())   // slave may send less than requested
  {
    char c = Wire.read();    // receive a byte as character
    if (dataN == 0) *a = c;
    if (dataN == 1) *b = c;
    dataN++;
  }
}
 
void showTTP229data()
{
  byte aa, bb = 0;
  static  byte aa_, bb_ = 0;
  getTTP229data(&aa, &bb);
 
  if (aa != aa_ || bb != bb_) {
    Serial.print(ct++);
    Serial.print(" data TTP229 = ");
    printByte(aa);
    printByte(bb);
 
    Serial.println(";");
    aa_ = aa; bb_ = bb;
  }
  //delay(10);
}
 
void loop()
{
  showTTP229data();
}
 
void printByte (byte bytePrint) {
  for (unsigned int mask = 0x80; mask; mask >>= 1) {
    if (mask & bytePrint) {
      Serial.print('1');
    }
    else {
      Serial.print('0');
    }
  }
}
arduino/ttp229.txt · Last modified: by aistis