Help with Adafruit_ST7735 library SPI constructor

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.

It works on my Chinese Red SPI ST7735.
Ok, my CS, DC, RST pins are different and my screen is INITR_BLACKTAB

David.

Hi David,

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.

Regards,
Geoff

Is it actually a Joy-It ?

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.

David.

Hello David,

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.

Regards,
Geoff

The Joy-It documents carefully avoid a schematic or photos of the pcb. However they do imply that it is a 3V board without any level shifters.

So you should not connect Uno or MEGA2560 5V GPIO pins directly. MKRZero has proper 3V GPIO. So it should work fine.

The Joy-It docs also say ST7735R. I have never seen a ST7735R. All my ST7735 screens have a ST7735S controller.

I reported in #2 that your sketch works on a Uno clone (with 3V level shifters)

David.

Hi David,

Well I don't know what to try now.

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.

Regards,
Geoff

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?

David.