I would like to use TFTs with my ESP6266 "Arduinos", e.g. Wemos D1 R2, Wemos D1 mini, NodeMCU.
The only SPI TFT that has arrived yet is a LinkSprite 2.8 Seedstudio compatible.
But the libraries I currently use for Arduino Due do not compile for ESP8266.
Any help or link to useful information is highly welcome. Thank you.
The "cd=6" for Ucglib is unclear to me, because the tft does not connect to A6 on MEGA and Due.
Maybe not important, as long as only output needed, no touch input.
Needs some wiring. This shield can't be used directly on Wemos D1, because two pins are duplicated to the Arduino connectors: D5 is SCK and digital 5, D6 is MISO and digital 6.
Same reason as why parallel connection TFTs can't be used, ESP8266 has not enough free IO pins.
Your link shows a regular Blue 2.8" Mcufriend Shield. It has an 8-bit parallel interface.
It should work with MCUFRIEND_kbv library. Obviously it has too many pins for the Wemos D1.
If it contains an ILI9341, there are several other libraries that will work.
There are several ILI9341 libraries that work with SPI interface. e.g. ILI9341_due, Adafruit_ILI9341, ...
The Wemos has got 3.3V logic. 5V Arduinos must have level shifters. i.e. 5V to 3.3V
Note that they all have constructors that accept a RESET pin. I suggest that you wire up the Reset pin to GPIO and use it.
Your link shows a regular Blue 2.8" Mcufriend Shield. It has an 8-bit parallel interface.
It should work with MCUFRIEND_kbv library. Obviously it has too many pins for the Wemos D1.
If it contains an ILI9341, there are several other libraries that will work.
Hi David,
I tried one of the examples from the link, which is grahicstest_featherwing.ino
The .ino file cannot be compiled, giving this statement instead:
'TFT_CS' was not declared in this scope
I reviewed the code and found that TFT_CS is already declared
There's something that I missed?
ZinggJM:
Needs some wiring. This shield can't be used directly on Wemos D1, because two pins are duplicated to the Arduino connectors: D5 is SCK and digital 5, D6 is MISO and digital 6.
Same reason as why parallel connection TFTs can't be used, ESP8266 has not enough free IO pins.
... and then there is the ISCP connector missing on Wemos D1.
The pins to use for cs and dc on Wemos D1 are D3 and D4.
// This example uses the either the Bodmer's library here with a ST7735 based TFT display:
// https://github.com/Bodmer/TFT_ST7735
// (don't forget to edit the User_Setup.h file inside that library to define pins etc)
// OR you can use the standard Adafruit_GFX library, see line 15 below
// When using the Adafruit_GFX library update line 61 to suit your display and lines
// 32-34 to define the pins used. Use of hardware SPI lines is assumed.
// Other TFT_xxxxx libraries that could be used can be found here:
// https://github.com/Bodmer?tab=repositories
//
// changed for Wemos D1, configuration part from Bodmers source removed
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
//Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
//Adafruit_ILI9341 tft = Adafruit_ILI9341(5, 6); // on UNO
Adafruit_ILI9341 tft = Adafruit_ILI9341(D3, D4); // on Wemos D1
int x[6][3];
int y[6][3];
//====================================================================================
// Setup
//====================================================================================
void setup()
{
Serial.begin(115200);
tft.begin();
tft.setRotation(0); // portrait
}
//====================================================================================
// Loop
//====================================================================================
void loop()
{
tft.fillScreen(ILI9341_BLACK);
int w = tft.width();
int h = tft.height();
for (int n = 2; n < 8; n++) {
int layer = n - 2;
x[layer][0] = w / 2;
y[layer][0] = n * h / 8 - h / 6;
x[layer][1] = w / 2 - n * w / 16;
y[layer][1] = n * h / 8;
x[layer][2] = w / 2 + (n * w / 16);
y[layer][2] = n * h / 8;
}
tft.fillRect(w / 2 - w / 20, h - h / 6, w / 10, h / 6, ILI9341_DARKGREY);
for (int layer = 0; layer < 6; layer++) {
tft.fillTriangle(x[layer][0], y[layer][0], x[layer][1], y[layer][1], x[layer][2], y[layer][2], ILI9341_DARKGREEN);
}
while (1) {
for (int layer = 0; layer < 6; layer++) {
for (int corner = 0; corner < 3; corner++) {
tft.fillCircle(x[layer][corner], y[layer][corner], w / 40, rainbow(random(128)));
delay(10);
}
}
tft.fillCircle(x[5][0], y[5][1], w / 40, rainbow(random(128))); // Last light
}
}
//====================================================================================
// Produce a rainbow colour
//====================================================================================
unsigned int rainbow(int value)
{
// Value is expected to be in range 0-127
// The value is converted to a spectrum colour from 0 = blue through to red = 127
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
Look at the schematic for your display. If it has a hard-wired pullup resistor on the Reset line, you can use the shortform constructor i.e. omit the Reset pin.
Many displays do NOT have a pullup on the Reset pin. So you MUST connect Reset to a GPIO pin and specify it in the constructor.
Adafruit examples all seem to omit the Reset pin. This may be fine for Adafruit displays. It certainly causes problems with most Chinese displays.
i.e. you should always put the Reset pin under program control. (by using the full constructor)
Thank you, David, for pointing to this issue, it may be important for the TFTs I should receive soon.
The LinkSprite TFT has a reset button switch, that also resets the Arduino; so I may safely assume it is connected to the reset pin on the ISCP connector, and also resets the display. I'm going to look for the schematics from LinkSprite, they have good documentation on their wiki pages.
This was really a good suggestion, to look at the schematics. There are open solder bridges for the SPI connection for the Arduino header, so there is no need to use the ISCP connector, just need to close the bridges!