readsnowpad: code to read multi-touch data

This examples shows you how to read and visualize multi-touch data from Snowpad.

Required Hardware and Software

Hardware

  • Snowpad

  • Microcontroller - In this example, it is assumed that the reader connect Arduino Micro or Snowboard. However, the reader can easily apply information here to his/her microcontroller.

Software

The Snowpad software touchplot is written in Processing environment. There are two ways to start the application - using a pre-compiled binary or a source code.

Use a pre-compiled binary in Snowpad release file (Windows only)

  • The binary is here

  • Download the latest Snowpad release file and unzip it.

Use a source code

Connection

Connect a microcontrolller to Snowpad. Arduino Micro can be directly connected via on-board socket. Snowboard or other microcontroller is connected via the external I2C port of Snowpad.

Upload Firmware (Arduino Micro and Snowboard)

1. Run Arduino IDE

2. In Tools-Board, choose Arduino Micro or Arduino Leonardo if you are using Snowboard.

3. In Tools-Port, choose an appropriate port to which your Arduino Micro or Snowboard is attached.

4. Go to File-Examples-Snowboard and choose snowforce to open the example.

5. Switch to the example readsnowpad

1) If you are using Arduino Micro, uncommnet line 15 and comment out line 16.

2) If you are using Snowboard, comment out line 15 and uncomment line 16.

3) Click upload button.

Visualization

1.Starting Application

For a user who uses the pre-compiled binary

Go to the unzipped folder of the downloaded Snowpad relese file.

Double click touchplot.exe in bin folder.

For a user who uses the code

Go to the unzipped folder you create during the installation find and double click touchplot.pde.

Click Run button in the upper left corner of Processing GUI.

2. Choose an appropriate port number and click start button

The firmware run a calibration procedure during start-up for a few seconds. Do not touch Snowpad during this period.

When you touch the Snowpad, your touches will be visualized as shown below:

Coordinate is defined as shown below.

Arduino Code

/*

readsnowpad.ino

Copyright (c) 2014 Kitronyx http://www.kitronyx.com

GPL V3.0

*/

#include <Wire.h>

#include <Snowpad.h>

unsigned char touchid;

unsigned char pen;

unsigned int touchx;

unsigned int touchy;

Snowpad snowpad(HOST_SNOWPAD_V1R3); // Arduino Micro

// Snowpad snowpad(HOST_SNOWBOARD); // SNOWBOARD

void setup()

{

Wire.begin();

Serial.begin(115200);

#ifdef CMT_DEBUG

// Start system only if any byte is sent from host PC.

while (1)

{

if (Serial.available())

{

break;

}

}

#endif

// Snowpad configuration

snowpad.mutScanTime = 0x07;

snowpad.mutTouchThres = 0x23;

snowpad.numOfAvg = 0x04;

snowpad.selfScanTime = 0x6;

snowpad.selfTouchThres = 0x28;

snowpad.begin();

}

void loop()

{

if (snowpad.read())

{

touchid = snowpad.getTouchID();

pen = snowpad.getPen();

touchx = snowpad.getTouchX();

touchy = snowpad.getTouchY();

#ifdef CMT_DEBUG

Serial.print("Touch ID: ");

Serial.print(touchid);

Serial.print(", Pen State: ");

Serial.print(pen);

Serial.print(", (");

Serial.print(touchx);

Serial.print(", ");

Serial.print(touchy);

Serial.println(")");

#else

Serial.print(touchid);

Serial.print(",");

Serial.print(pen);

Serial.print(",");

Serial.print(touchx);

Serial.print(",");

Serial.println(touchy);

#endif

}

}