Adafruit ILI9341 SPI Mode on Arduino Zero

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sgboy
 
Posts: 10
Joined: Sat Jul 16, 2016 5:54 pm

Adafruit ILI9341 SPI Mode on Arduino Zero

Post by sgboy »

Hey,

I am trying to get ILI9341 TFT Display working in SPI mode on Arduino Zero and I am struggling a bit.

The SPI pins on Zero are on ICSP header, however following the example on TFT I need to define CS and DC pins for the screen. I have tried a few different ones with no luck. Is there are anything I need to do to "enable" SPI communication on the Zero?

Thanks a lot.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

Did you solder closed the ICSP jumpers on the back of the display?

User avatar
sgboy
 
Posts: 10
Joined: Sat Jul 16, 2016 5:54 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by sgboy »

Thanks for your reply.

Yes I have soldered close (shorted) M3, M2 and M1 on the back of the ILI9341 TFT display.

I have it working well on Mega2650, however I can not get it working on Zero.

I have double checked wiring and unless there is some pins swapped on the Zero on the ICSP header or I have to add extra code to the example I can not work out why I cant get the display to work. I do have genuine Zero which I did buy from you guys.

Any help would be greatly appreciated as I am totally baffled by this.

Thanks a lot

EDIT: I have been debugging the code and it appears that it does not execute past the following line in the graphicstest example

Code: Select all

#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 23
#define TFT_CLK 24
#define TFT_MISO 22
#define TFT_RST 11

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() {
  Serial.begin(9600);
  Serial.println("ILI9341 Test!"); 

  SPI.begin();
  Serial.print("SPI.begin()"); 
  tft.begin(); // Code execution stops here.
  Serial.print("tft.begin()");  // Never reaches this line.
}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

It works for me.

Don't use that form of the constructor. Do this instead:

Code: Select all

#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Connect SPI to the ICSP header:
Here's the ICSP pinout:
ICSP pinout.png
ICSP pinout.png (9.88 KiB) Viewed 2094 times

User avatar
sgboy
 
Posts: 10
Joined: Sat Jul 16, 2016 5:54 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by sgboy »

I have also tried the one you suggesting earlier with no luck.

Perhaps its a faulty board (Zero)...

Is there are any obvious checks I can run on the board to see if it is functioning?

And just to be 100% sure:

Display to Zero ICSP Header
CLK to Pin3 (SCK)
MISO to Pin1 (MISO)
MOSI to Pin4 (MOSI)

I have tried different wires and 5V and GND pins as well.

Strange thing is that I am able to use non SPI devices. I have successfully used a GPS module via UART and manually created Serial2 and read from digital pin 11 and 10 serial data. Can SPI controller part of the chip be non functioning?

Thanks a lot for your help

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

You are using the constructor I posted above?

There's no reason why the display won't work on a Zero. As I said, it works for me. You have the display working on a Mega, so there's nothing wrong with the display.
I suppose it's possible that your Zero has a problem. Do you have any other SPI devices you can test with?

Are you powering the display with 3.3V or with 5V? You should be using 3.3V with the Zero

Can you post some pictures of your soldering and wiring?

User avatar
sgboy
 
Posts: 10
Joined: Sat Jul 16, 2016 5:54 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by sgboy »

Yes, I have tried the constructor you posted.

I think the problem isn't with the display as I had it working on an AVR board (Mega2560) and after some digging about I am also thinking that the Zero board isn't a problem.

I use Serial.print() command to see where the code stops. (As I posted in the code before).
The code stops execution inside setup() routine when it hits tft.begin() routine. It appears that it never comes out of it.

What GFX and ILI9341 library versions are you using?

Just do add some more information. I have done further debugging but within Adafruit_ILI9341.cpp file. I am a bit confused by the two default constructors in there:

Code: Select all

// Constructor when using software SPI.  All output pins are configurable.
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t mosi,
				   int8_t sclk, int8_t rst, int8_t miso) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
  _cs   = cs;
  _dc   = dc;
  _mosi  = mosi;
  _miso = miso;
  _sclk = sclk;
  _rst  = rst;
  hwSPI = false;
}


// Constructor when using hardware SPI.  Faster, but must use SPI pins
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) {
  _cs   = cs;
  _dc   = dc;
  _rst  = rst;
  hwSPI = true;
  _mosi  = _sclk = 0;
}
There simply isn't one that accepts only two parameters. The one that relies on using hardware SPI sets _mosi and _sclk to 0, which should not be the case. Anyway, in the associated .h file you do the following Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1) in Adafruit_ILI9341 class definition. When it comes to begin() function inside the cpp file the value to _rst is set to some random value. That is the problem.

Could you please check that the _rst value in overloaded constructor is properly handled?

Thanks a lot
Last edited by sgboy on Thu Jul 21, 2016 3:14 pm, edited 1 time in total.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

ILI9341 v1.0.2
GFX v1.1.4

The only place it could hang in tft.begin would be in SPI.begin, SPI.beginTransaction, or SPI.endTransaction.
Those are all part of the Arduino SPI library.

Do you have anything else connected to the Zero?

User avatar
sgboy
 
Posts: 10
Joined: Sat Jul 16, 2016 5:54 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by sgboy »

Hey,

Made an edit to the post above.

The problem is in the Adafruit_ILI9341.cpp inside the begin() function due to the value for _rst isn't set to anything meaningful.

So when it comes to:

Code: Select all

if (_rst > 0) {
      Serial.print(_rst);
    pinMode(_rst, OUTPUT);
    digitalWrite(_rst, LOW);
  }
Setting pinMode() does not work because the value for _rst is not initialised (just some random number: 4294967295)

To answer your question regarding anything else being connected, no, nothing. Just the display powered up by 3.3V

I have just tried with 1.1.4 and the problem persists. If it helps I am running OSX with Arduino IDE 1.6.9

User avatar
sgboy
 
Posts: 10
Joined: Sat Jul 16, 2016 5:54 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by sgboy »

I actually got it working by using the constructor with three parameters:

Code: Select all

#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 4

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
I have used some unused pin to define TFT_RST.

One thing I notice right away is that it is very slow even compared to Mega2560... Any idea how this can be improved? This was actually the reason why I got the Zero, with the hope of having faster screen refresh.

Thanks

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

That doesn't make any sense. RST is an optional argument, and is set to -1 if omitted. Here's the constructor prototype from the .h file:

Code: Select all

  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
It worked for me without providing a reset argument. I don't understand this at all.

Yes, it is slower on the Zero. The driver sets the SPI speed to 16MHz on the Zero as compared to 24MHZ on a Mega. I set this up, and as I recall, I couldn't get it to operate reliably at higher SPI speeds.

User avatar
medwar65
 
Posts: 11
Joined: Sat Aug 26, 2017 1:38 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by medwar65 »

I do not understand something. How are we using SPI communication with this constructor?

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

We do not declare the MOSI or MISO pins.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

That constructor assumes hardware SPI. The Arduino system knows which are the hardware SPI pins

User avatar
medwar65
 
Posts: 11
Joined: Sat Aug 26, 2017 1:38 pm

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by medwar65 »

Thank you for the quick reply. So, what is the point in using

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

in case you are configuring different pins other than the default ones to use for SPI?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Adafruit ILI9341 SPI Mode on Arduino Zero

Post by adafruit_support_rick »

That constructor sets up *software* SPI. So that's how you configure for software or hardware SPI - you choose one constructor or the other.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”