Abstract: This page will describe some tests/evaluation of a Touch Pad keyboard
Keywords: TouchPad Arduino NANO
Components: Touch Keypad XC4602 as sold by Jaycar. Arduino NANO
Software. Arduino IDE
Comment/Background: This page came about as I could not get the Touch Pad to work with an ESP8266 Micro-controller. I decided to back track and use an Arduino and the sample code provided and build upon that. This page outlines the steps I took.
The Touch Keypad is sold by Jaycar as part XC4602.
The 16 key touch pad is built around the TTP229 capacitor touch sensor IC. There are two types of TTP229: LSF and BSF. The XC4602 uses the BSF variant with the following pin out.
On the XC4602 the pins TP0/K0 through TP7/K7 become OUT1 through OUT8. TP8 through TP15 are not brought to any extenal pins.
SCL and SDO correspond to SPI (Serial peripheral interface) pins SCL and MISO (Master In Slave Out)**. As shown SCL will be generated by the Master (a micro-controller) and the Slave (the TTP229) will output data on each clock.++
The capacitors CJ0~CJ3 are used to adjust the sensitivity of keys at operation mode. The capacitors CJWA and CJWB are used to adjust the Wake-up sensitivity at sleep mode. These are fixed on the XC4602. (The remaining two capacitors will be power supply bypass(?)).
The XC4602 includes 8 onboard resistors that can be programmed to change the configuration and will be introduced in later sections.
^^ This is my interpretation of what is happening. The XC4602 data was very minimal and I found the TTP229 data sheets quite challenging. A search of the internet indicated I was not alone.
**A complete SPI system would include a SS (Slave Select) signal to select this device and a MOSI (Master Out Slave In) to send data from the master to the slave. For a keypad these is not required.
++The I2C option is not available with the TTP229-BSF.
---------------------------------------------------------
At power up the TTP229 will sense the pins TP0 through TP7 (Key Pads 1 through 8) and depending upon these pins will come up in different modes.**
All TP pins have an internal pull up resistor so will come up as a "1" by default. The XC4602 has povision for connecting TP0 through TP7 to Vss (ie Logic "0") via 820Kohm resistors. With 8 pins there is a choice of 256 combinations which doesn't make it easy for a first time user to become comfortable with the device..
The default options are:
TP0 (OPDEN) TP1 (SAHL)=1,1 8 output pins => CMOS output active-high. 2-wire serial interface => CMOS output active-low
TP2 (KYSEL) = 1 8 input keys mode
TP3 (SKMS1) TP4 (SKMS0) =1,1 All Single-keys:one group(16keys)
TP5 (WPSCT) = 1 8Hz sampling rate for wake-up in sleep mode
TP6 (SLWPTM) = 1 Wake-up sampling length=>about 4.0ms
TP7 (SKSRT) = 1 Maximum key-on time disable=>infinite
In default mode pressing any key from 1 to 8 gave the following result.
The start and stop pulses on the SDO line indicate Data Valid (DV). The data sheets lists these as typically 93uSec - my set up gave 88uSec.
**Don't touch the key pads for about 0.5 seconds during power-up.
-------------------------------------------
In addition to the keypad outputs on pins OUT1-OUT8 the XC4602 has a serial output on pin SDO that is clocked via the user supplied signal SCL. See actual waveforms below.
The Jaycar site supplied the following sample code**:
In this example when a key (top channel) is pressed SDO (centre channel) pulses low. (Data Valid)
Sometime later the SCL line will toggle that in turn generates a response on SDO.
By expanding the trace the activity on the SDO and SCL lines can be examined.
In this case there are 8 clock pulses and SDO goes low on the 5th pulse corresponding to key "5" being pressed.
** The following major change to the sample code was in the loop where there were 8 iterations not 16 as the key pad was being tested in its default mode. Also 115200 baud was used for the monitor and pins 2 and 3 were used for SCL and SDO
-----------------------
To synchronise a reading to a keypress the main program should monitor the SDO line and when a DV signal is detected take the appropriate actions.
As a first step the code was modified as shown:
#define sclpin 2 #define sdopin 3void setup(){Serial.begin(115200);pinMode(sclpin,OUTPUT);digitalWrite(sclpin,HIGH);pinMode(sdopin,INPUT);}void loop( ){The important changes** were in the loop where the program waited until the DV signal was active (LOW). To verify a message was sent to the monitor.
The message was deliberately made relatively long to avoid multiple reads of DV.
Since there is a DV pulse at the start and end of each key press for each keypress the message will be repeated and this was verified.
** Other changes were for my preferences.
------------------
The next step is to include code to read the data.
Observation of the TTP229 timing diagram shows the data valid signal to be active for 93uSec (as per observations in previous sections) and the TTP229 expects a time Tw of 10 uSec before an active clock.
Parameter Min. Typ. Max. Unit
DV - 93 - us
Tw 10 - - us
Tout - 2 - ms
T_resp(for 16-KEYS) - 32 - ms
T_resp(for 8-KEYS) - 16 - ms
F_SCL 1K - 512K Hz
To meet the timing requirement the code could:
(i) wait until SDO goes high then delay a further 10 uSec before attempting to take readings, or
(ii) after the SDO is detected low wait (93+10) 103 uSec before taking the readings.
Since 93 uSec was only a typical value the first option appears a better choice.
The loop( ) function was enhanced as follows:
void loop( ){if (!digitalRead(sdopin)) //exits loop or other actions if no key pressed{ // Serial.println("Key pressed"); //one mess at start, one at end - should take longer than DV pulse (93uS)while (!digitalRead(sdopin));delayMicroseconds(10); //specs call for 10 uS delayfor(int i=1;i<9;i++){ digitalWrite(sclpin,LOW); //toggle clock digitalWrite(sclpin,HIGH);}}}The results were as follows
Obtain: High on touch pad 5. DV low for 88uS, Delay of 10uS then 8 pulses with DDO going low on 5th.**
** At trailing edge there will be no SDO pulse - ie will read 0 - can we have software ignore??
-------------------------------------------------------
The previous section didn't return the key pressed. As per the original code if a key is pressed a variable key will be set with the value of the key pressed and at the completion of the loop the value printed on the monitor. The modified code becomes:
if (!digitalRead(sdopin)) //exits loop or other actions if no key pressed{ // Serial.println("Key pressed"); //one mess at start, one at end - should take longer than DV pulse (93uS)while (!digitalRead(sdopin)); //wait for DV completedelayMicroseconds(10); //specs call for 10 uS delayint key = 0; //default for no keyfor(int i=1;i<9;i++){ digitalWrite(sclpin,LOW); //toggle clock digitalWrite(sclpin,HIGH);if(!digitalRead(sdopin)){key=i;} //valid data found}if (key) Serial.println(key); //the key -ignore '0'}The results were all correct except for the last key (key 8 in default 8 bit mode) where the print out repeats.
Observation of the waveforms for key 8 pressed shows that SDO remains low. Hence on the next loop the code will think its a valid DV signal and make another reading.
Repeating the trace with a longer time base shows SDO remains low for 2.4 mSec
The specifications give Tout of typically 2mSec. Adding a delay of 3mSec should cover possible longer values of Tout.
ie Modify code:
if (key) Serial.println(key); //the key -ignore '0'delay(3);--------------------------------
The previous discussion has been for the 8 bit default mode.
To use the full 16 keys
(i) a link must be added as shown in red**.
(ii) The loop must be changed to 16 iterations
Initially I was unable to get my system to work^^. By chance I removed the probe on an output pin and hey presto it all worked correctly##.
The results for SDO and SCK when key 15 was pressed were++.
** Without the link an internal pull up resistor pulls all inputs high. The link will pull the inputs low via a 820Kohm resistor connected to Vss.
^^ Of note removing link the XC4602 reverted to 8 bit mode (after ~ 4seconds from manual). With the 16 iteration loop the serial monitor displayed the key+8 - ie pressing key 5 was displayed as 13. This is as expected since the TTP229 would loop through its results twice - the first SDO would be when the count reached 5 and the second when the count reached 13. The 13 would overwrite the 5.
## Further testing indicated the touch pad did not work with a mixed signal oscilloscope probe in place. However it then worked again some 15 seconds after the probe was removed. My conclusion is that in 16 bit mode nothing should be connected to the OUT pins.
++ Long term I expect to use a different micro-controller. For reference the low time of SCL was measured as 3.8uS - the high time 9.6 making a total of 13.4 or ~75kHz which is within the specified range of 1 to 512 (kHz).
----------------------------------------------
I started trying a 16 bit system with a different micro-controller and it didn't work. It appears that my mistake may have been that I had a mixed signal oscilloscope probe on an OUT pin. I decided to go back to a sample reference system and move forward in incremental steps.
The final code
(i) waited for the DV (Data Valid) signal on the SDO line to go LOW.
(ii) waited until DV returned HIGH.
(iii) waited a further 10 uSec to allow the TTP229 to prepare the output.
(iv) generated 16 clock pulses**.
(v) on each rising edge of the clock read the value of SDO.
(vi) if SDO was LOW it indicated a pressed key so the count value was stored.
(vii) printed the value of the count as the key pressed.
(viii) waited 3mSec to allow the TTP229 to reset.
** For reference these were ~75kHz which is within the specified range of 1 to 512 (kHz).
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,