I have a Joy-IT 1.8 inch TFT with 128X160 pixels. It uses an ST7735 chip.
I am unable to get the Adafruit_ST7735 default hardware SPI constructor to work, on Uno or Mega2560 or MKRZero.
However the software SPI constructor works on each board.
I haven't included a wiring diagram but my test sketch below lists the pins to which I'm connecting the TFT on each of the three Arduino boards I've tried.
Is there something I'm missing in trying to use the hardware SPI?
[code]
/*####################################################################
test_Adafruit_ST7735.ino
#######################################################################*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
// define Uno pins for the tft screen
#if defined __AVR_ATmega328P__
#define cstft 6
#define dctft 7
#define rsttft 5
#define mositft 11
#define scktft 13
// define Mega2560 pins for the tft screen
#elif defined __AVR_ATmega2560__
#define cstft 6
#define dctft 7
#define rsttft 5
#define mositft 51
#define scktft 52
// define Micro pins for the tft screen
#elif defined __AVR_ATmega32U4__
#define cstft 6
#define dctft 7
#define rsttft 5
#define mositft 16
#define scktft 15
// define MKRZero pins for the tft screen
#elif defined __SAMD21G18A__
#define cstft 6
#define dctft 7
#define rsttft 5
#define mositft 8
#define scktft 9
#endif
void setup()
{
Serial.begin(9600);
while (!Serial) {}
Adafruit_ST7735 *ptft;
// Instantiate Adafruit ST7735 driver with software SPI
Serial.println("Using software SPI constructor");
ptft = new Adafruit_ST7735(cstft,dctft,mositft,scktft,rsttft);
ptft->initR(INITR_GREENTAB);
ptft->fillScreen(ST7735_BLACK);
ptft->setRotation(1);
// draw a rectangle
ptft->drawRect(1,1,159,127,ST7735_WHITE);
// fill it
ptft->fillRect(2,2,157,125,ST7735_RED);
Serial.println("Deleting software SPI object");
delete ptft;
ptft= NULL;
// Instantiate Adafruit ST7735 driver with default hardware SPI
Serial.println("Using default hardware SPI constructor");
ptft = new Adafruit_ST7735(cstft,dctft,rsttft);
ptft->initR(INITR_GREENTAB);
ptft->fillScreen(ST7735_BLACK);
ptft->setRotation(1);
// draw a rectangle
ptft->drawRect(1,1,159,127,ST7735_WHITE);
// fill it
ptft->fillRect(2,2,157,125,ST7735_RED);
Serial.println("Deleting default hardware SPI object");
delete ptft;
ptft= NULL;
}
void loop()
{}
[/code]
When I run this code the software SPI constructor draws and fills the rectangle but the hardware SPI constructor does nothing.
Thank you for your comment. It prompted my to try the other INITR parameters. On Uno and Mega only INITR_GREENTAB Software SPI works, on MKRZero INITR_GREENTAB, INITR_REDTAB and INITR_BLACKTAB work but on the latter the standard ST7735_RED colour is rendered blue.
My TFT screen is not an Adafruit one but it DOES have a green tab stuck to it and these results indicate that INITR_GREENTAB is the best of a bad bunch.
But none of the hardware SPI constructors work with this screen.
Life is much safer if you post a link to the actual screen that you have bought e.g. Ebay sale page.
Then we can identify it. And I don't have to guess.
"Joy-It" may or may not describe a screen. A sale page generally has a photo of the pcb. A photo is better than 1000 words.
You can compare your pcb with the photo. Ideally the shop has delivered the item in their advert. Describe any differences.
Yes, it is a Joy-It. I initially posted a plea for help in the MKRZero forum because I thought my hardware SPI problem was related to that board, but when I discovered it applied to Uno and Mega2560 as well then I reposted here but I didn't include the link from my first post.
This is the supplier's page
This is the manufacturer's page
When I was first developing the sketch for my project I used the TFT library's hardware SPI constructor, and was developing on a Uno. That constructor worked correctly.
Now I'm trying to change to the Adafruit libraries and to use a MKRZero because my sketch exceeded the program space on Uno. I can survive with the software SPI constructor but I'd rather use hardware SPI if possible.
The Joy-IT page says "The display can be operated with 3.3V (Raspberry PI & Microbit) as well as with 5V (Arduino)" and the Go Tronic supplier's schematic shows the screen connected straight to Uno 5V. But the Joy-IT schematics show level shifters which seems at odds with their statement above.
In any case, the hardware SPI constructor doesn't work with 3.3V on MKRZero so I don't think voltage is the issue.
In Adafruit_ST7735.h the class Adafruit_ST7735 is described as a subclass of Adafruit_77xx and the initialising functions are initB() for ST7735B displays and initR( INITR_GREENTAB) for ST7735R displays, so I think I'm using the correct function for the Joy-IT display.
It looks as though software SPI may be the way to go.
Seriously. It is easy to see whether a board accepts VCC=5V or whether the logic signals are 5V or 3V.
You only have to look at the pcb. What are the chip numbers ? Or post a clear photo of the pcb so that we can read the chip numbers.
Regarding shops. They just lie. It gives them more sales.
I would be pretty confident that Adafruit_7735 works with a MKRZero. I have an M0 Pro. And it has SAMD21G18 chip which works with hardware SPI.
If you have a problem with the MKRZero SPI have you tried other SPI examples?
To view the pcb and chips I’d need to prise up the screen and I don’t wish to do that.
I don’t have any other SPI devices but a loopback test indicated that the MKRZero SPI on pins D8, D9, D10 works, and I know that the inbuilt SD card reader on SPI pins PA12, PA13, PA15 works.
I’ve given up on the default hardware SPI constructor and have finished my project using the software SPI constructor.
You don't prise up the screen at all.
You simply view the front of the screen. i.e. where the pixels are.
Or you view the back. i.e. the pcb with the header pins.
Look at it as a sandwich. Top slice of bread is the screen. Bottom slice of bread is the pcb. You never disturb the jam in the middle. It is too sticky.
The MKRZero contains a SAMD21G18 just like a Zero or M0.
Ok, the MKRZero might allocate different SERCOM# for SPI0, SPI1 than the Zero does. The "SPI.h" library will look after the details.
Surely the MKRZero works with SPI OLEDs, SPI Flash chips, SPI ADC chips, ...
If it didn't there would have been a lot of whingeing. There are more sales of MKRZero than Zero boards.
Since you are happy with SW SPI you can just live with it.
However I would be interested in the chip numbers that are visible on the Joy-It pcb.
Q1 may be a voltage regulator or perhaps a transistor.
R1, R2 are resistors
UR1, UR2 are resistor packs.
Please can you read the part number on Q1.
Please can you read the value number on UR1, UR2 e.g. 472
The convention is U1 for integrated circuit e.g. regulator
And Q1 normally means transistor.
But the Chinese do not always follow convention. Which is why a part number helps e.g. 662K
Q1 is a 3.3V voltage regulator. You can connect VCC = 3.3V - 5V
VR1 is a 10k resistor pack. You can safely connect the TFT logic signals to a 3V MCU or a 5V Uno.
VR2 is a 10R resistor pack. You can connect the microSD signals to a 3V MCU or a 5V Uno.
Since they have used series resistors (VR1) you can read the bidirectional SDA pin.
So if you really want to know the make and model of TFT controller I can post or link some diagnostic sketches.