How to troubleshoot pesky digital wiring
This weekend, I had the pleasure of working with Roberto Mendoza, an ECE freshman with a burning passion to become fluent in MCU projects. His project, a virtual cat, which will display on a screen, and include a distance sensor and a speaker, so that you can virtually pet this fuzzy friend!
Anyways, after Roberto found out how to read from the distance sensor using his Pi Pico, step two was to get the display working, to show his virtual cat. The display in question is the ILI9341, a 2.8 inch touchscreen, with a strong similarity to that of a Nintendo DS screen. Now, when the screen was picked, it had a rather large amount of pins, and inevitably wiring the screen to work with the MCU would be no easy task. The day it would finally be wired up would be met with some anxiety, but the day had eventually come, and we got to work.
There pins on the board are as follows:
VCC
GND
CS - SPI Chip select, used for selecting a specific device on an SPI bus
RESET - Required for the SPI communication, although not standard
DC - Data control, tied either high or low for data vs. command
MOSI - Transmit from MCU SPI
SCK - SPI clock
LED - Tied high to illuminate the backlight
MISO - Receive from MCU SPI
T_CLK - Tied to CLK, but this is for touchscreen
T_CS - SPI Chip select for touchscreen
T_DIN - Touchscreen receive
T_DO - Touchscreen transmit
T_IRQ - Unused
Now, we gave it an initial wiring and the screen came to life, but we couldn’t seem to communicate with it. No matter how many examples we gave the IDE to program it, so we decided to check the wiring to make sure nothing has gone amiss. Enter the logic analyzer!
This is the output of the logic analyzers we have at M5. This shows you the logic levels as a function of time of whatever circuit you have built. In this case, I was checking the levels of the SPI bus going to the display, to make sure they all looked fine. That’s when we quickly realized that we had miscounted the pins when connecting the CS and DC pins to the MCU. I was off by one, and after correcting this, the screen came right to life!
Now all that’s left in the code is to upload different states of the virtual cat based on user input from the distance sensor, and M5’s project roster will have a new pet you can come in and pet when it is around!