I bought online this LCD Touchscreen Kuman SC3A-NEW-UK. It uses ILI9486 drivers, but it didn't include any instructions manual, and kumantech.com seems to be devoid of complete technical documentation about SC3A-NEW-UK model.
I am trying to figure out:
- Which are the minimum connections I have to make between Arduino UNO and the LCD screen.
- Which "Arduino's C++" (AKA G++ ?) library I need to use in order to display stuff programatically
To summarize
Just in case it wasn't noticable: I am trying to make a "Hello World" for my SC3A-NEW-UK's LCD Touchscreen from an Arduino UNO board. In other words: just print "Hello World" to see if it works.
What I tried so far
Searching on the Internet wasn't enough. Searching "ILI9486" on Google led me to this Github project:
https://github.com/schreibfaul1/ESP32-TFT-Library-ILI9486
To see if I can use it, I tried downloading a whole ZIP from this Github project, and inside the Arduino IDE, I tried adding the downloaded library using the option "Include .ZIP library". If I copy-paste the code example provided within README.md (the following) and compile:
#include "Arduino.h"
#include "SPI.h"
#include "tft.h"
// defaults can be changed in tft.begin
// CS=22, DC=21, MOSI=23, MISO=19, SCK=18
TFT tft;
//-------------------------------------------------------------------------------------
void setup() {
SPI.begin();
tft.begin();
tft.setRotation(1); //landscape
tft.fillScreen(TFT_BLACK);
tft.setFont(Garamond34x42);
tft.setTextColor(TFT_CYAN);
tft.setCursor(20,30);
tft.print("Hello World!");
}
//-------------------------------------------------------------------------------------
void loop(void) {
for(uint8_t rotation=0; rotation<4; rotation++) {
tft.setRotation(rotation);
tft.fillScreen(TFT_BLACK);
tft.setCursor(20,30);
tft.print("Hello World!");
delay(3000);
}
}
//-------------------------------------------------------------------------------------
...it results in this compile error:
In file included from C:\Users\MyUser\ArduinoProjects\test_external_library\test_external_library.ino:3:0:
C:\Users\MyUser\Documents\Arduino\libraries\Arduino-TFT-Library-ILI9486-master\src/tft.h:5:16: fatal error: FS.h: No such file or directory
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
Line 5 at tft.h
says:
#include "FS.h"
...and I have no idea what this FS library is supposed to be, so I don't think I can use that Github project at all... I am tempted to assume that Github's project is dead.
So, perhaps I am fine just using the IDES's built-in TFT
library, perhaps like this? I don't know...:
#include <SPI.h>
#include <TFT.h>
#define CS 10
#define DC 9
#define RESET 8
#define TFT_CYAN 0x07FF
#define TFT_BLACK 0x0000
// Initialization inspired in code example found at
// https://www.arduino.cc/en/Guide/TFT
TFT tft = TFT(CS, DC, RESET);
int dummy_second_cnt = 0;
void setup() {
// I don't know what's SPI for, anyway...
// just found it in the code example present at GitHub's library's README.md
// ...(which I am not trying to use at this point, so it's useless in this code example... commented-out for reference, just in case)
//SPI.begin();
tft.begin();
tft.background(0,0,0);
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_CYAN);
tft.setCursor(20,30);
tft.print("Hello LCD Screen");
delay(3000);
}
void loop() {
tft.fillScreen(TFT_BLACK);
tft.setCursor(20,30);
tft.print("Seconds: ");
tft.print(dummy_second_cnt);
dummy_second_cnt++;
delay(1000);
}
This compiled in Arduino IDE, no problem, but I still don't know if it will work well with my screen. I am also confused about initialization of the TFT object and how would I have to wire the LCD screen to the Arduino depending on this initialization:
TFT tft = TFT(CS, DC, RESET);
...i mean, my LCD screen has CS and RESET pins, but what is DC supposed to be here? (in this context, I don't think it stands for "Direct Current"... but there's no DC pin reference in my LCD screen written "AS IS"... ?? This brings me more confusion...
...specially having in mind that I don't know how am I supposed to wire the LCD screen to the Arduino yet. It seems the LCD pins have been designed to fit in directly to the Arduino board without thinking too much about it (like the shape is the same), but that would make the screen getting all the Arduino UNO's pins for itself, so I don't think so...
These are the LCD_*
pins present at my LCD screen:
- LCD_RST (Reset I guess)
- LCD_CS
- LCD_RS
- LCD_WR (Write I guess)
- LCD_RD (Read I guess)
(and the following I guess are 8-bit digital pins):
- LCD_D0
- LCD_D1
- LCD_D2
- LCD_D3
- LCD_D4
- LCD_D5
- LCD_D6
- LCD_D7
It also has 5V, 3V3 and GND pins (Which I guess are for power)
...so, powering the screen shouldn't be a big deal, but, how am I supposed to connect everything else? I am completely misguided about how am I supposed to interact with the screen from Arduino code... what is RS pin for? Should I use 4-bit or 8-bit mode? (I think 4-bit would imply connecting 4 digital pins for the screen, and 8-bit the whole 8 pins from screen to the Arduino UNO board)? Should I use LCD_RD and LCD_WR? Well you have a picture of my confusion.
Searching for documentation in the internet only leads me to partial examples. Not even using the model Ref ( SC3A-NEW-UK ) or the driver's ref ( ILI9486 ) as keywords for searching in Google leads me to clear documentation about howto wire stuff, or which specific libraries should I use...
Even though I know how to control Input/Output in Arduino code to interact with analog/digital input and output pins at will with C++ in Arduino code (but even so, I think I'm still an Arduino n00b), this LCD screen's physical interface is very confusing to me...
Can you help me to overcome this confusion, please? I'd rather have my mind clear before making any physical wiring and fry something...
PD: I have read somewhere that this SC3A-NEW-UK Touchscreen is made to shield Arduino MEGA boards (by fitting the PINs directly into it), but mine is an Arduino UNO Board! (perhaps I shouldn't have bought This LCD model, then?)... but I have sets of wires, pinboards and stuff... I don't want to give up the idea of harnessing this LCD screen using an Arduino UNO. I don't care about shielding feature, I just want to wire it and make it work. I will figure out how to shield electronics later on.
EDIT: Based on VE7JRO's answer, I managed to map the connections by seeing where the connections would go if I just fit the connections shielding the Arduino UNO, the way VE7JRO suggested:
+--------------+------------------+
| Arduino UNO | LCD Screen |
+--------------+------------------+
| GND | GND |
+--------------+------------------+
| 5V | 5V |
+--------------+------------------+
| 3.3V | 3.3V |
+--------------+------------------+
| A0 | LCD_RD |
+--------------+------------------+
| A1 | LCD_WR |
+--------------+------------------+
| A2 | LCD_RS |
+--------------+------------------+
| A3 | LCD_CS |
+--------------+------------------+
| A4 | LCD_RST |
+--------------+------------------+
| A5 | NONE |
+--------------+------------------+
| 8 | LCD_D0 |
+--------------+------------------+
| 9 | LCD_D1 |
+--------------+------------------+
| 2 TO 7 | LCD_D2 TO LCD_D7 |
+--------------+------------------+
| 10 | SD_SS |
+--------------+------------------+
| 11 | SD_DI |
+--------------+------------------+
| 12 | SD_DO |
+--------------+------------------+
| 13 | SD_SCK |
+--------------+------------------+
I put NONE
for A5 input, because that pin of LCD screen doesn't have any name on it. There are another ones without name as well, that I didn't include in this table. I believe (perhaps I'm wrong believing it, I don't know) that those pins without name have no use.
The bad thing about this layout is that it consumes almost all the Arduino pins, so I would not be able to attach additional circuits. However, perhaps I should not be worrying about earning connections yet, before testing the screen.
I still don't know much of the details about what pins do what for the screen, but I have read somewhere that LCD_D0
to LCD_D7
are meant to receive digital data in some kind of 8-bit parallel mode. But I also heard that there is a 4-bit mode. If I could use that mode with this screen, I would be able to have 4 free digital pins for anything else...
Ok, I got the connections mapped. Next step would be trying those three libraries that VE7JRO suggested.
EDIT2: I tested VE7JRO's code. LCD Screen did draw the interface as expected. But buttons didn't respond. I found out the code sample needs further calibration.
So, I started printing through the Serial the coordinates of the object TSPoint p
, to find out if there was something wrong with the z
coordinate. And indeed, there was: setting MINPRESSURE
and MAXPRESSURE
according to what I saw in Serial Monitor while I pressed and I didn't pressed, fixed this. However, there's another more issue...
...when I tell Serial to print if the boolean operation down && on_btn.contains(pixel_x, pixel_y)
results in either true
or false
, it prints it is false... while I am touching ON button. down
is true for sure (after I calibrated MINPRESSURE
and MAXPRESSURE
constants); so that must mean on_btn.contains(pixel_x, pixel_y)
is returning false for some reason. If I figure out why, I will be able to accomplish that the ON Button does what it's supposed to when I press it. And that will mean I will have completed calibration process. I would bet perhaps pixel_x
and pixel_y
need calibration as I already did with pressure detection based on z
; or perhaps contains
method is not reliable and I have to figure out some other methodology... I will tell you after I try
All stroken through is based on assumption that Z is depth, and Y is height; Actually, it seems to be the other way around...
After somemore trial-and-error research, it seems that Z is height, and Y is depth (at least within the TSPoint
object's properties x
, y
and z
, which values seem way more reliable than the pixel_x
and pixel_y
values, which purpose seems to be if the pixel is contained in the button's squares and nothing else)... I still don't get why is there the need to use this within the function Touch_getXY(void)
:
if (pressed) {
pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
...because their values when I touch the screen with the touchpen are very weird. I tried to guess which ranges they go, and they don't make sense when I move around the screen. Perhaps it's because this strange "Z instead of Y" mapping from the TSPoint
object. Perhaps pixel_x
and pixel_y
don't need to make an intuitive sense, perhaps it's just some intrincated in-bound logic that only makes sense within electronics' low-level scope, or within Adafruit_GFX_Button.press
method, I don't know... but x
, y
and z
readings from TSPoint
object seem very accurate, despite Y being Z and Z being Y...
...perhaps reading any documentation I can find about Adafruit_GFX_Button
class, its properties and methods (specially contains
) will lead me to comprehend clearly what's wrong...
...also, it might be time to focus on searching those test sketches that VE7JRO talked me about:
There are 22 test sketches that come with the MCUFRIEND_kbv library. One of them scans your display and outputs configuration information (sorry, it's been a while since I tested my screen). Another sketch will draw little boxes in each corner and sides. This is used to get the x y coordinates of the edges of your particular screen (it might be called TouchScreen_Calibr_native.ino).
EDIT3
X is Y? Y is Z? Z is X? I don't know what to think anymore! The last I tried, changing the formula for pixel_x
and pixel_y
to:
pixel_x = map(p.x, 1023, 0, 0, tft.width());
pixel_y = map(p.y, 1023, 0, 0, tft.height());
...and the constants for the pins:
const int XP = 6, XM = A2, YP = A1, YM = 7;
This seems to make z
the pressure axis within TSPoint
object, but ends up in strange behaviours:
x
seems numb (no matter if I press the touchscreen with touchpen or not, neither it's position: it always prints 65 to 70!z
seems indeed sensitive to touch pressure, but it's like its sensitivity is different depending on the touchpen's position on screen (altough I'm not a robot, I think I was using more or less the same amount of force with my hand). It prints 0 when i do not touch the screen.y
seems sensible to both horizontal and vertical position at the same time! This blows my head.
I don't know what to think anymore...
- Did I short-circuit something for not paying attention to the script's constants in my previous tests?
- Was the screen broken from the begginning?
- Is it a calibration error with values in the script?
- Might the libraries I am using be broken, or have some kind of bug with my TFT?
This is becoming overwhelmingly more difficult than I thought...
...according to some article I found(in Spanish, sorry), the Touchscreen
's initialization's params:
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
XP
is supposed to be the pin forLCD_D6
:6
in the Arduino.YP
is supposed to be the pin forLCD_WR
:A1
in the Arduino.XM
is supposed to be the pin forLCD_RS
:A2
in the Arduino.YM
is supposed to be the pin forLCD_D7
:7
in the Arduino.- The fifth parameter is supposed to be the resistance measured between
LCD_D6
andLCD_RS
with the screen unplugged. Unfortunately, my multimeter can't measure it for some reason (I put it in 2000 Ohms mode for reading resistance: I always get '1', the same than when I don't connect anything... like if multimeter's contacts aren't working well, I don't know)... so I left the default 300 value.
I did initializate it well, as far as I know... except the fifth parameter. Would a wrong resistence value make such a big difference in calibration, up to the point this strange behaviours I have seen do happen?
Damn, I am so close... what am I doing wrong?