Using the TFT ILI9341 Touchscreen with an Audio Shield

topicbird

Active member
Hello guys!

I'm planning to use the TFT ILI9341 touchscreen together with an audio shield. To be honest, I don't quite get the table on the page of the TFT... :confused:
For example in the first column D/C corresponds to pin 9 of the teensy and pin 20 of the audio shield. What does that exactly mean?
Thank you in advance!
 
Here's my interpretation (NOTE: I have only used the ILI9341 with a T4.x + Audio Shield, so this may suffer from my misinterpretation):

The first column represents the pins that you would use with a T3.x, but without an Audio Shield, or what pins you would use with a T4.x, regardless of whether you have an Audio Shield (Rev D) or not.

The second column represents the pins that you would use with a T3.x, where you also have an Audio Shield (Rev C).

Hope that helps . . .

Mark J Culross
KD5RXT
 
It depends on which Teensy you have.

If you have a Teensy 4.0/4.1 and the revision D audio shield, you use the first column, i.e.:
  • CS, pin 10 (alternate pins, any not used by the audio shield)
  • D/C, pin 9 (alternate pins, any not used by the audio shield)
  • MOSI, pin 11 (required for the first SPI bus)
  • MISO, pin 12 (required for the first SPI bus)
  • SCK, pin 13 (required for the first SPI bus)
  • T_CS, pin 8 (alternate pins, any not used by the audio shield)
  • T_DIN, pin 11 (required for the first SPI bus)
  • T_DO, pin 12 (required for the first SPI bus)
  • T_IRQ, pin 2 (alternate pins, any not used by the audio shield)

If you are using Teensy 3.2, 3.5, or 3.6 without the audio shield you use the pins as above, with the following restrictions:
  • CS, pin 10 (alternate pins, 9, 15, 20, or 21)
  • D/C, pin 9 (alternate pins, 10, 15, 20, or 21)

If you are using the Teensy 3.2, 3.5, and 3.6 with the revision A-C audio shield, then use the pins from the second column.
  • CS, pin 21 (alternate Pins: 15, or 20)
  • D/C, pin 20 (alternate pins: 15, or 21)
  • MOSI, pin 11 (required for the SPI bus)
  • MISO, pin 12 (required for the SPI bus)
  • SCK, pin 13 (required for the SPI bus)
  • T_CS, pin 8 (alternate pins, any not used by the audio shield)
  • T_DIN, pin 11 (required for the SPI bus)
  • T_DO, pin 12 (required for the SPI bus)
  • T_IRQ, pin 2 (alternate pins, any not used by the audio shield)

In reading the list at pjrc.com, they mention using pins 9 or 10, but these can't be used since they are used by the audio shield. Also, pin 15 may or may not be an issue, since the audio shield has pinouts to hook up a potentiometer to it, and I believe it has extra capacitors and resistors on the line.

The reason is the Teensy 3.2, 3.5, and 3.6 has a set of special pins that can optimize the performance of displays (if the display driver has the optimization). Both CS and D/C must come from those pins. The Teensy 4.0 and LC do not have these optimizations in the hardware. The Teensy 4.0 has only one special pin (10), but to do the optimization you need to use two special pins. The Teensy 4.1 has 3 special pins (10, 36, and 37), but I'm not aware that the Teensy 4.x driver has the support that the Teensy 3.x driver did for the special pins.

Now to get to the nitty gritty, there are a few more special pins on the Teensy 3.2, 3.5, and 3.6. But these pins have restrictions (if you use one of these other pins, you can't use specific pins). But if you are curious, go here (in particular reply #5):

Now, if you are using Audio shield revision A-C on the Teensy 3.2, 3.5, or 3.6, then you need to use alternate pins for MOSI (7) and SCK (14). The reason is the I2S pins used by the audio shield overlap with 2 of the 3 the SPI pins, and you have to have use the alternate SPI pins. The Teensy 4.0 and 4.1 do not have alternate SPI pins for the first SPI bus.

Because of the difference in the I2S pins and the alternate SPI pins, you must use audio shield revision A-C for the Teensy 3.2, 3.5, and 3.6. For the Teensy 4.0 and 4.1, you must use audio shield revision D.

I believe the Teensy LC does support the same alternate SPI pins that the 3.2, 3.5, and 3.6 do, but since you can't use most of the audio shield functions on the LC, it is likely you wouldn't be using that board.
 
Last edited:
Hello Michael and Mark!

Thank you so much for your super fast responses!
I tried to make an excel overview to show you the way I'd wire everything up. As you can see at pin 11, 12 and 13 there are overlapping pins. Is it not a problem? I don't know about the function about all the different pins, so there may be an obvious answer to it.. Also I'd be happy about every advice regarding a nice resource to learn about things like these kinds of connection and everything around the teensy.
Thank you!

Bildschirmfoto 2022-10-13 um 21.27.17.jpg
 
Hello Michael and Mark!

Thank you so much for your super fast responses!
I tried to make an excel overview to show you the way I'd wire everything up. As you can see at pin 11, 12 and 13 there are overlapping pins. Is it not a problem? I don't know about the function about all the different pins, so there may be an obvious answer to it.. Also I'd be happy about every advice regarding a nice resource to learn about things like these kinds of connection and everything around the teensy.
Thank you!

SPI is a shared bus. This means the 3 SPI control pins (MISO, MOSI, and SCK) are shared among all of the devices on the bus. The CS pin is separate for each device, and it is high or low (depending on the device) when the SPI bus is talking to the device. The device will ignore traffic on the SPI bus unless the CS pin is set appropriately. D/C and reset (if used) in general should also be unique for each device. There are special cases (i.e. uncanny eyes that is driving 2 displays) where you might be able to reuse D/C and reset for different devices, but in general it is better to have unique pins.

If you have more than one device on the SPI bus, you might need to do additional things listed in this document:

Note, the Teensy 4.0 and 4.1 have a second SPI bus (MOSI1 is pin 26, SCLK1 is pin 27, and MISO1 is either pin 1 or pin 39). If you have multiple devices that interfere with each other, you might move one device to the second SPI device. In the past, I recall there have been people that had problems with some touch screens where the touch screen did not work on a shared SPI bus, but I don't remember the details since I've never used the touch screen. You need to check whether the drivers for the two devices (display and touch screen) can work with a second (or third/fourth) SPI bus, and if so, what is the sequence to using it.

The Teensy 4.1 does have two other SPI buses (one attached to the built-in SD card reader, and one available in solder pads underneath the Teensy for use with soldering flash memory and PSram chips to the Teensy).

The Teensy 4.0 has one other SPI bus, designed for hooking a SD card reader, that are on 2mm solder pads under the Teensy. Note, the Teensy 4.0 does not have export pins 34 - 41 like the Teensy 4.1 does, so there is no alternative to using pin 1 for MISO1. It is unfortunate that the original pinout card for the Teensy 4.0 did not list pin 1 being MISO1.

And for extra credit, with the Teensy 4.x can do SPI transfers in the background using DMA and a frame buffer. I don't know if the ILI9341 driver supports it (the ST7789 driver does support it). Using DMA likely plays havoc with using any other SPI device on the bus.

The only alternative pin the Teensy 4.1 has for SPI pins is pin 39 for MISO1. You have to call SPI1.setMISO(39) before the SPI1.begin() call if memory serves.
 
Last edited:
Thank you Michael for explaining it to me! It makes way more sense now.
So just as SPI is a shared bus, it also means that if I'd want to connect a mcp23017 to extend my IOs by using I2C I could use pins 18 and 19 even though the Audio Shield also uses it right? Because its shared just like at the SPI?
Sorry if I'm jumping between all the communication protocols, I just had a deep dive right now and it's starting to make more sense..
 
Thank you Michael for explaining it to me! It makes way more sense now.
So just as SPI is a shared bus, it also means that if I'd want to connect a mcp23017 to extend my IOs by using I2C I could use pins 18 and 19 even though the Audio Shield also uses it right? Because its shared just like at the SPI?
Sorry if I'm jumping between all the communication protocols, I just had a deep dive right now and it's starting to make more sense..

Yes, I2C is also a shared bus. Unlike SPI that uses the CS pins to identify which device is active, with I2C, each device has a unique address. So the I2C master essentially blasts out the message to everybody on the bus, but only the device addressed responds (sort of like the old fashioned party lines on rural telephones).

Hence the tradeoffs. On SPI, you need extra pins to add devices. On I2C, you must have unique addresses for each device, but you don't need extra pins. Thus, if you have two identical devices on the SPI bus, you just use different pins to address each one. For I2C, if you have two identical devices, they will not be able to share the I2C bus.

Many devices have a way to change what I2C address they will listen on. Some do it via solder jumpers that are connected or disconnected which changes the address used. Some have pins that you connect to either ground or 3.3v to change the address. Some use an address stored in the device's flash memory, and you send some sort of command to change the default address.

If you can't change the address, there are I2C multiplexers that have n (usually 8) different downstream connections, and a simple I2C command to change which of the n (8) buses are active. I2C has defined speeds, and not all devices can tolerate higher speeds. Your I2C bus speed will be reduced with longer the wires on the bus or the more devices that you have on the bus.

One other gotcha that trips people up, is on Teensies (and other ARM processors), you need what is called pull-up resistors on the I2C bus to allow the bus to be used. Many newer devices include pull-up resistors, as well as the audio shield (and prop shield before it). All you need is one set of pull-up resistors on the bus. If you don't have pull-up resistors, the I2C bus will likely fail (either if you have nothing connected, or you only have older devices like the MCP23017 that doesn't have pull-up resistors). The more pull-up resistors you have, the slower the potential I2C bus will be. In general, people won't notice, since a lot of I2C drivers just use the slowest I2C bus speed anyway.

The Teensy 4.1 has 3 I2C buses. Not all drivers have ways to utilize secondary and tertiary I2C buses.

The audio shield has two I2C devices on its bus (SGTL5000 on 0x0a and WM8731 on 0x1a).

In terms of speed, I2C has fixed speeds, while SPI can send data at different speeds, independent of the CPU bus speed. However some/many devices cannot handle higher speed transmissions. For example, one of the things I do is run the uncanny eyes program in which two SPI displays are showing eyeballs that move about the screen. I have found with various displays that I've had to lower the speeds of the SPI bus to prevent data corruption. Basically, I would run the program and adjust the SPI speed until both displays ran without data corruption.
 
Hello Michael,

after reading a lot about communication protocols, your answer makes so much sense and fills up the gaps. Thank you for taking your time to write such an understandable, thorough explanation! :)
 
Back
Top