DirtyLude
Well-Known Member
This is a very simple and cheap interface and has a lot of potential for an input device on projects. It can be mated with a graphical LCD, or simply used on it's own to simulate button points. If you get fancy, you can implement gestures, like swipes and taps... It comes in under $6 for total parts. One limitation is that the NDS touchscreen is really meant for a stylus input, you need to touch the screen with the flat of your finger with a decent amount of force to register a finger touch so beware of this limitation if you're trying to use it to emulate buttons.
You can implement a 4 wire touch screen using your uC and an ADC, and that's certainly an option, but you don't get the simplicity and accuracy of just adding this 2 dollar part. The TSC2046 is a 4 wire touchscreen controller with an SPI interface. In this example I'm using it in differential mode with 12 bit precision, which gives you precise touch points and pressure measurement. You can use 8bit precision if you want faster sampling time.
I'm not going to get into super detail about the interface, but there's no setup for the chip or anything. Every three byte command/response packet is on it's own. You send 1 byte that specifies the reading you want a response for (X position, Y position, Z1, Z2), the mode (12bit or 8bit), whether it's a single ended or differential reading, and the power down mode. I'm not using the Pen touch interrupt line, but if you specify the chip to power down after the current read, the interrupt pin will be activated and will drop low next time it detects a pen press. There's some finicky things with the pen interrupt line, so it's not as simple as it triggers every time a pen presses, but you could use this in a power saving mode if handled correctly. After you send the command byte, you get two bytes back that contain the response. The response is not right justified, so you need to bit shift it 3 bits right to get your 12bit value.
This chip is used in a lot of portable devices, so doing a search you can find at least a couple embedded linux device drivers for it. You can steal code from those for yourself.
Pressure calculation: There's a calculation method in the datasheet that uses X position, Z1, and Z2 data to give a pressure value, which I'm not using. I stole this calculation from one of the linux drivers. It gives fairly course pressure measurements and a higher value means less pressure, but it works. If you want a simple touch/no touch indicator, you can just check Z1, which is 0 on no touch.
Anyway, that's it. Simply continue to poll the chip for location data. This is a sampling of data I get when touching the 4 corners with a stylus.
Datasheet:
https://www.electro-tech-online.com/custompdfs/2009/04/tsc2046.pdf
TSC2046 TSSOP16 $2.00
Digi-Key - 296-15049-1-ND (Texas Instruments - TSC2046IPWR)
(TSC2007 is a very similar part with I2C interface rather than SPI, it is not 5V tolarant, though)
NDS touchscreen $2.74 shipping included.
**broken link removed**
dealextreme.com has other 4 wire touchscreens as well for cheap. Just search for 'touch screen' and check the cell phone section.
Connector 95 cents
**broken link removed**
Possible Connector 91 cents (46 cents for quantity 25) (I have not confirmed that this connector works, so no guarantees here)
Digi-Key - 609-1846-1-ND (FCI - SFV4R-1STE1LF)
Eagle files for my breakout board:
**broken link removed**
You can implement a 4 wire touch screen using your uC and an ADC, and that's certainly an option, but you don't get the simplicity and accuracy of just adding this 2 dollar part. The TSC2046 is a 4 wire touchscreen controller with an SPI interface. In this example I'm using it in differential mode with 12 bit precision, which gives you precise touch points and pressure measurement. You can use 8bit precision if you want faster sampling time.
I'm not going to get into super detail about the interface, but there's no setup for the chip or anything. Every three byte command/response packet is on it's own. You send 1 byte that specifies the reading you want a response for (X position, Y position, Z1, Z2), the mode (12bit or 8bit), whether it's a single ended or differential reading, and the power down mode. I'm not using the Pen touch interrupt line, but if you specify the chip to power down after the current read, the interrupt pin will be activated and will drop low next time it detects a pen press. There's some finicky things with the pen interrupt line, so it's not as simple as it triggers every time a pen presses, but you could use this in a power saving mode if handled correctly. After you send the command byte, you get two bytes back that contain the response. The response is not right justified, so you need to bit shift it 3 bits right to get your 12bit value.
This chip is used in a lot of portable devices, so doing a search you can find at least a couple embedded linux device drivers for it. You can steal code from those for yourself.
Pressure calculation: There's a calculation method in the datasheet that uses X position, Z1, and Z2 data to give a pressure value, which I'm not using. I stole this calculation from one of the linux drivers. It gives fairly course pressure measurements and a higher value means less pressure, but it works. If you want a simple touch/no touch indicator, you can just check Z1, which is 0 on no touch.
Code:
if (locationZ1) //Z1 will always be zero on no touch.
{
pressure = 40 * locationX;
pressure /= 4096;
pressure *= locationZ2 - locationZ1;
pressure /= locationZ1;
}
else
pressure = 0;
Anyway, that's it. Simply continue to poll the chip for location data. This is a sampling of data I get when touching the 4 corners with a stylus.
Code:
nothing X: 4080 Y: 2880 Z1: 0 Z2: 4080 PRS: 0
top left X: 3680 Y: 3696 Z1: 928 Z2: 3904 PRS: 112
bottom left X: 160 Y: 3888 Z1: 48 Z2: 3952 PRS: 81
top right X: 3680 Y: 336 Z1: 816 Z2: 2544 PRS: 74
bottom right X: 256 Y: 240 Z1: 64 Z2: 2032 PRS: 61
Datasheet:
https://www.electro-tech-online.com/custompdfs/2009/04/tsc2046.pdf
TSC2046 TSSOP16 $2.00
Digi-Key - 296-15049-1-ND (Texas Instruments - TSC2046IPWR)
(TSC2007 is a very similar part with I2C interface rather than SPI, it is not 5V tolarant, though)
NDS touchscreen $2.74 shipping included.
**broken link removed**
dealextreme.com has other 4 wire touchscreens as well for cheap. Just search for 'touch screen' and check the cell phone section.
Connector 95 cents
**broken link removed**
Possible Connector 91 cents (46 cents for quantity 25) (I have not confirmed that this connector works, so no guarantees here)
Digi-Key - 609-1846-1-ND (FCI - SFV4R-1STE1LF)
Eagle files for my breakout board:
**broken link removed**