Asking for help with writing driver for "LCD TFT 3.5" by C language for( Atmega32)

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to control Arduino Shield "LCD TFT 3.5" Touch for UNO & Support Mega2560"  using atmega32 Microcontroller but with writing C language not C++ or Arduino  

link:https://ram-e-shop.com/product/k...

1-Any one could help with libraries ready for this application (for interfacing and drawing shapes and for detecting that the screen is touched at certain positions?

2-In data sheet of  ILI9486  i couldn't find the driver for touch screen ?

I am living to bring up new earth ,and not to eat and destroy earth.

Last Edited: Wed. Feb 6, 2019 - 04:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well two things:

 

1) have you actually googled that controller number with "AVR" - the chances are someone has done it already

 

2) failing that why can't you use the Arduino library code? Sure it's C++ and maybe you can't use C++ in your project but the actual sequence of steps you output to the controller is going to be fairly agnostic about what language it is done in. Suppose the sequence to fill the panel with red is 1B,37,FF,00,00 then whether you use some C++ or C or Asm or BASIC or Pascal to send those bytes it's still the same sequence of bytes. So study what the C++ code does then just implement the sames steps (algorithm?) in the language of your choice.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup so about 2 minutes in Google got me to UTFT:

 

https://github.com/amperka/UTFT/...

 

Note the ILI9486 support there?

 

The things I read suggest UTFT is a common solution for this kind of LCD.

 

So the LCD init appears to be:

 

https://github.com/amperka/UTFT/...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is good way thanks ,but also i want to control the capactive touch , i can't find pdf for hardware driver for touch screen to write for C module . 

I am living to bring up new earth ,and not to eat and destroy earth.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The touch screen is read through the Adc control.study the Arduino libraries

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go on.   Post a link to the capacitive touch screen controller that you are using.

 

The TFT screen in your link has a simple resistive screen without a controller.

 

Explain why you can't use C++.

If you provide a sensible explanation,  we can probably help you.

 

CodeVisionAVR is a C compiler.  It comes with graphics library and with a library for ILI9486.    And even a Wizard for ATmega32.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am searching for pdf that explains the control of touch screen to program it 

I am living to bring up new earth ,and not to eat and destroy earth.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The details link from the link you gave in #1 gives links to various Arduino software. The "V2.0" one of those says it includes touch support.

 

In that Zip under Arduino there are examples and in that is one for "touch". The code shows it doing:

void loop()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

So that would seem to imply that the "TSPoint" class is providing the touchscreen support.

 

The same .zip file has a \3.5inch_Arduino_ILI9481_Touch_V2.0.zip\3.5inch_Arduino_ILI9481_Touch_V2.0\3.5inch_Arduino_ILI9481_V2.0\Arduino Demo_UNO&Mega2560\Install libraries\TouchScreen\ directory that has TouchSceen.h and TouchScreen.cpp. The header documents the class:

class TSPoint {
 public:
  TSPoint(void);
  TSPoint(int16_t x, int16_t y, int16_t z);

  bool operator==(TSPoint);
  bool operator!=(TSPoint);

  int16_t x, y, z;
};

class TouchScreen {
 public:
  TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym);
  TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);

  bool isTouching(void);
  uint16_t pressure(void);
  int readTouchY();
  int readTouchX();
  TSPoint getPoint();
  int16_t pressureThreshhold;

private:
  uint8_t _yp, _ym, _xm, _xp;
  uint16_t _rxplate;
};

So that looks to be most of what you might want to do with a touchscreen. The .cpp file has the implementation. First the simple version of the c'tor:

TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) {
  _yp = yp;
  _xm = xm;
  _ym = ym;
  _xp = xp;
  _rxplate = 0;
  pressureThreshhold = 10;
}

then the core getPoint():

TSPoint TouchScreen::getPoint(void) {
  int x, y, z;
  int samples[NUMSAMPLES];
  uint8_t i, valid;

  uint8_t xp_port = digitalPinToPort(_xp);
  uint8_t yp_port = digitalPinToPort(_yp);
  uint8_t xm_port = digitalPinToPort(_xm);
  uint8_t ym_port = digitalPinToPort(_ym);

  uint8_t xp_pin = digitalPinToBitMask(_xp);
  uint8_t yp_pin = digitalPinToBitMask(_yp);
  uint8_t xm_pin = digitalPinToBitMask(_xm);
  uint8_t ym_pin = digitalPinToBitMask(_ym);

  valid = 1;

  pinMode(_yp, INPUT);
  pinMode(_ym, INPUT);

  *portOutputRegister(yp_port) &= ~yp_pin;
  *portOutputRegister(ym_port) &= ~ym_pin;
  //digitalWrite(_yp, LOW);
  //digitalWrite(_ym, LOW);

  pinMode(_xp, OUTPUT);
  pinMode(_xm, OUTPUT);
  //digitalWrite(_xp, HIGH);
  //digitalWrite(_xm, LOW);
  *portOutputRegister(xp_port) |= xp_pin;
  *portOutputRegister(xm_port) &= ~xm_pin;

   for (i=0; i<NUMSAMPLES; i++) {
     samples[i] = analogRead(_yp);
   }
#if NUMSAMPLES > 2
   insert_sort(samples, NUMSAMPLES);
#endif
#if NUMSAMPLES == 2
   if (samples[0] != samples[1]) { valid = 0; }
#endif
   x = (1023-samples[NUMSAMPLES/2]);

   pinMode(_xp, INPUT);
   pinMode(_xm, INPUT);
   *portOutputRegister(xp_port) &= ~xp_pin;
   //digitalWrite(_xp, LOW);

   pinMode(_yp, OUTPUT);
   *portOutputRegister(yp_port) |= yp_pin;
   //digitalWrite(_yp, HIGH);
   pinMode(_ym, OUTPUT);

   for (i=0; i<NUMSAMPLES; i++) {
     samples[i] = analogRead(_xm);
   }

#if NUMSAMPLES > 2
   insert_sort(samples, NUMSAMPLES);
#endif
#if NUMSAMPLES == 2
   if (samples[0] != samples[1]) { valid = 0; }
#endif

   y = (1023-samples[NUMSAMPLES/2]);

   // Set X+ to ground
   pinMode(_xp, OUTPUT);
   *portOutputRegister(xp_port) &= ~xp_pin;
   //digitalWrite(_xp, LOW);

   // Set Y- to VCC
   *portOutputRegister(ym_port) |= ym_pin;
   //digitalWrite(_ym, HIGH); 

   // Hi-Z X- and Y+
   *portOutputRegister(yp_port) &= ~yp_pin;
   //digitalWrite(_yp, LOW);
   pinMode(_yp, INPUT);

   int z1 = analogRead(_xm);
   int z2 = analogRead(_yp);

   if (_rxplate != 0) {
     // now read the x
     float rtouch;
     rtouch = z2;
     rtouch /= z1;
     rtouch -= 1;
     rtouch *= x;
     rtouch *= _rxplate;
     rtouch /= 1024;

     z = rtouch;
   } else {
     z = (1023-(z2-z1));
   }

   if (! valid) {
     z = 0;
   }

   return TSPoint(x, y, z);
}

So the bottom line here seems to be that the four IO involved (_xm,_ym), (_xp,_yp) are energised in turn then the ADC is being used to read the resultant voltage (and hence touch offset)

 

I't a pretty fair bet that in _xm, _yp etc that m=minus, p=plus

 

If you google "resistive touch screen" I think you'll find that the general technique is to set up a potential across the panel in one direction (call it X) then read the other terminals to get a relative voltage. Then to switch things round and set up a potential across the panel in the other direction (Y) and then read any touch offset as a relative voltage the other way.

 

That is pretty much what this code seems to be doing.

 

To be honest the best way to see this in action is to splash the entire $5 and actually buy an Arduino then connect it up and actually use this code. See it in action and once you understand what it's doing take the same technique to the environment where you really want to work (if Arduino is not the easy answer after all).

 

EDIT: I googled "resistive touch screen" expecting Wikipedia to have the full description of how they work (indium tin oxide etc) and how they are read but actually Wikipedia was a bit sad in its description. However a load of the other google results looked really good. I particularly like the look of:

 

https://www.dmccoltd.com/english...

https://www.dmccoltd.com/english...

 

Last Edited: Wed. Feb 6, 2019 - 05:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am writing in C program because all my MCAL layer in this language.

I am living to bring up new earth ,and not to eat and destroy earth.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

C++ is just C with knobs on. The actual stuff you do (like setting up a potential between two IO lines then reading back an ADC reading on another two lines) is the same whatever language you choose to do it in. Look at the C++ I quoted above - the vast majority of that getPoint() function (which is the key function in the entire thing) just looks like plain old C (basically because it is!)

 

Sure Arudino/C++ dress up the setting of things like DDR registers in fancy function calls like pinMode() but when you read something like:

   pinMode(_xp, INPUT);
   pinMode(_xm, INPUT);

hopefully it's fairly obvious this is (ultimately) doing little more than clearing a couple of bits in a DDR register?