Touchscreen
MBED Lib ERROR
At the moment you have to use a old version of the mbed lib to use this library, because of a error in using the analog pins. The actual mbed lib is not switching the analog pins to digital mode !
The latest working mbed version is 43 from 26. oct 12.
To connect a resistiv touchscreen to the mbed we need four pins. Two analog inputs and two digital IOs. The connections on the touchscreen are normaly marked as x+,x-,y+ and y-.
The touchscreen is working like two potenciometers. First we have to read the X direction. To get a voltage across the X direction we connect the Y lines one to 0V and one to 3,3V. If the screen is hit we get a voltage between 0 to 3,3V - depending on the position. After that we connect the X lines to 0V and 3,3V and we detect the voltage on one of the Y lines. If there is no hit the line is not connected and we get a low reading.
Library
http://mbed.org/users/dreschpe/libraries/Touch_tft/lx1972
The commands :
- calibrate() ask the user to point onto two point to calibrate the screen
- point get_touch() return analog x and y
- bool is_touched(point) test if the screen is touched
- point to_pixel(point) use the calibration data to calculate the pixel position
The demo code :
#include "mbed.h" #include "SPI_TFT.h" #include "Arial12x12.h" #include "touch_tft.h" // the TFT is connected to SPI pin 5-7 // the touch is connected to 19,20,16,17 touch_tft tt(p19,p20,p16,p17,p5, p6, p7, p8, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset int main() { point p; tt.claim(stdout); // send stdout to the TFT display tt.background(Black); // set background to black tt.foreground(White); // set chars to white tt.cls(); // clear the screen tt.set_font((unsigned char*) Arial12x12); // select the font tt.set_orientation(1); tt.calibrate(); // calibrate the touch while (1) { p = tt.get_touch(); // read analog pos. if (tt.is_touched(p)) { // test if touched p = tt.to_pixel(p); // convert to pixel pos tt.fillcircle(p.x,p.y,3,Blue); // print a blue dot on the screen } }
will print a blue dot if the screen is hit.
Also see the demo :
32 comments on Touchscreen:
Please log in to post comments.
Hello
i have some questions if u may... in the data sheet at mikroelectonika they mention its important to use pull-up resistor .. so my question is do i have to connect resistor or do i connect directly .. and what are the values of the resistors if i have to use any ???
Thanks in advance