How to use touch func in 2.8" tft lcd resistive breakout display using mcp3008

i am working with sifive-Hifive1 microcontroller (Arduino compatible), i have interfaced Adafruit 2.8" tft lcd resistive touch breakout board with my MCU i need to use the touch functionality,so i used ADC MCP3008 as my MCU does not have analog input header pins.I am struggling with the pin connections and also i am using TOUCHSCREEN.H (I port it in C language, made some changes for hifive1 support).How to give connections between the ADC , MCU & Display unit in breadboard and also how to calculate the z coordinate in general? i tried my level best but the touch functionality is not working properly it prints somewhere else( i tried breakout paint example).Kindly help me out.

2nd question: what is the use of these two functions

bool TSPoint::operator==(TSPoint p1) { return ((p1.x == x) && (p1.y == y) && (p1.z == z)); }

bool TSPoint::operator!=(TSPoint p1) { return ((p1.x != x) || (p1.y != y) || (p1.z != z)); }

As far as I can see, the screen 2.8 TFT Touch Shield for Arduino with Resistive Touch Screen : ID 1651 : $34.95 : Adafruit Industries, Unique & fun DIY electronics and kits has a built in STMPE610 touch screen controller which produces a digital output (I2C/SPI) so there should be no need for the ADC. If the tutorial you are following has specified pins A4 and A5 for example , then these are for I2C and are treated as digital pins (also marked SDA and SCL).

Post a link to the tutorial or guide you are following and also the library which you are using.

The two definitions you have included appear to overload the operators == and != so these operators can by used to compare two TSPoint objects.

Incidentally, I had never heard of the sifive-Hifive1 MCU but from a picture I found, it does appear to be of “UNO” format although much better specified (32Bit processor, 16kB Ram etc.) and I’ll spend a few minutes trying to figure out the specification.

sifive-Hifive1 review:

Thanks for your reply,I am using this url= display which is a breakout board and i am using spi channel not 8-bit data channel.

The library that i am using is TouchScreen.H,i will make some changes in the library to run it for Hifive1.

i will show you the picture ,in which it will display the temperature (my recent project).Now i want to enable touch functionality, for that it requires an ADC ,so I chose MCP3008 .

I do not know how to give pin connections in breadboard for X+,X-,Y+ and Y-.

i searched in the internet , i found out a similar case but it is for RASPBERRY Pi.
But it dint give me a good output.

link for the library and sifive-Hifive1

Those links are not properly posted.


RaspberryPi reference

OK. The specific touch screen you have does require 2 analog pins.

I do not know how to give pin connections in breadboard for X+,X-,Y+ and Y-.

I'm not sure I understand your problem here, but the pin mappings for the touch screen are in the constructor for TouchScreen (taken from an example in the library) :

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9 // can be a digital pin
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

So, for example, Y- is connected to digital pin 8 Your problem is going to be the two analog pins which are, in effect, on the MCP3008.

Maybe it is as simple as finding the analogRead() statements in the library and the replacing the statements so these obtain their values from the MCP3008.

Yeah , i did that . I am getting the values also for x and y , but the problem is while calculating Z value, I am not sure about the pin connection , in arduino uno i guess it is capable to do digitalWrite() on analog pins also , but here in Hifive1 i will give 2 pins as analog input to the 2 channels in the ADC , then how could i do digitalWrite() to those pins? since i will be having 2 digital pins from display unit for touch and spi pins from adc in my Hifive1 if you go through the TouchScreen.cpp code in getPoint() you could see that digitalWrite() for analog pins.

Hope you understood my problem.

so my problem is with connections.

This is my code attached below , took touch paint as an example

correct me if am wrong.

touchScreen.c (13.5 KB)

Then should i buy STMPE610 breakout controller instead of using ADC ?

Yes. it does appear that digitalWrite()/pinmode() are also set for the analog pins for XM and YP.

From your sketch, it looks like you are using the following connection for the touch screen

Y+  HiFive pin6 and MCP3008 Chan 1
Y-  HiFive pin7
X+  HiFive pin9
X-  HiFive pin8 and MCP3008 Chan 0

So, for example, in the case of touchscreen pin Y+, you have two connection to it. One to the HiFive and one to the ADC. Is guess that is right and should work.

I didn’t look in too much detail at your code except to work out the pin mappings. I personally would simply have made a copy of the library in the sketch folder and hacked it to add in the “analogRead()” statements as you have e.g.

int z1 = mcp3008_value(0,_sclk_pin,_miso_pin,_mosi_pin,_cs_pin);; // mcp3008read

but keeping the structure otherwise intact, then writing a minimal sketch to test the touch screen part. You have a large monolithic sketch to debug.

Incidentally, you can throw anything dependent on USE_FAST_PINIO out because this is for the AVR architecture:

#if defined (USE_FAST_PINIO)
	   *xp_port &= ~xp_pin;
	   *ym_port |= ym_pin;
           <keep this>

Then should i buy STMPE610 breakout controller instead of using ADC ?

I have no experience here of how easy it would be to integrate with your chosen display. May be you could also ask this question in the “Display” forum here.

6v6gt: May be you could also ask this question in the "Display" forum here.

Sure i will, Thanks anyways.