micro paint

demo to show the touchscreen and TFT use

/media/uploads/dreschpe/touch.jpg

http://www.youtube.com/watch?v=spCLFkKMMS4

the updated code:

http://mbed.org/users/dreschpe/programs/touch/lwzg7l

The touchscreen lib:

http://mbed.org/users/dreschpe/notebook/touchscreen/

The TFT lib:

http://mbed.org/users/dreschpe/notebook/qvga-tft-with-hx8347d-controller/

Connection to the mbed

The connection to the TFT : http://mbed.org/users/dreschpe/notebook/qvga-tft-with-hx8347d-controller/

To use the touchscreen we need 4 additional pins - 2 IO and 2 Analog Input pins. The pins on the tft are labeled with x+ x- y+ and y-. The x+ and y+ signal has to be connected to a analog input pin of the mbed. (Pin 15 - 20).

The lib is using the pullups inside the mbed pins, so we do not need resistors.

Use the touch

The x- and y- signals can also connected to a digital io pin. In my demo i use the four analog pins p19,p20,p16 and p17.

If you use the SPI on pin 5 to 7 to control the TFT like the schematic on http://mbed.org/users/dreschpe/notebook/touchscreen/ please change the next line

touch_tft tt(p19,p20,p16,p17,p11, p12, p13, p14, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset 

tt is the touch screen objekt. To get the position on the screen we have to calibrate the touch screen first. The function

calibrate();

first draw a cross in the left corner. You have to touch this cross and after that the cross on the right. Both analog values are calibrated and we can calcuate the position x,y coresponding to the pixel address.

To use positions we have to declare a variable from type point fist. This variable has a x and y member :

point p;

Then we ask for the position:

p = tt.get_touch();

p hold the analog x and y position. With the function

if(tt.is_touched(p)) ...

we can test if the screen is touched. If so, we use the function

 p = tt.to_pixel(p);  

to convert the point to a pixel address. p.x and p.y are the pixel address now. This is the input to use inside our program.

We can draw a circle at the point

tt.fillcircle(p.x,p.y,4,Red);

Have fun, Peter


4 comments on micro paint:

14 Jul 2011

Looking good!

19 Jul 2011

very nice . I have just seen that this screen controller ( himax hx8347d ) is purposed for mobile applications mainly http://www.himax.com.tw/en/product/pd121.asp Does anybody know of any mobile phone that uses it ? this should cost less than 5 euro , without the pcb , as a phone screen .

I have found this screen as well , I dont know if it has spi on the connector or touchscreen , but seems to be using the same chip . i think it is priced at 21 yuan ( <3 euro ) (I am not sure if I translate well , I dont speak chinese ) . < fixed link dec 2011 , price around 5 euros , just screen , no pcb, no touch > http://item.taobao.com/item.htm?id=12888692018

14 Nov 2011

Hi, I try this code but I have a grey screen. Anybody have an idea ? I note that "SPI_TFT library" works great.

It's OK I solved my problem. I used the new version of "SPI_TFT library"

But I have a new problem : When I touched the screen the position is always X=0 and Y=0.

The Pencil is mandatory for this ? Or I can do it with other thing ?

01 Sep 2014

Hi Peter,

Is there a version of this that can be downladed and working?

I have the same screen and have used your code to get the display working but cannot get the Touch working?

Please log in to post comments.