Adafruit Playground is a wonderful place to share what you find interesting. Have a cool project you are working on? Have a bit of code that you think others will find useful? Want to show off your electronics workbench? You have come to the right place.
Adafruit Playground is a safe place to share with the wonderful Adafruit community of makers and doers.
-
SPI on D10-13 using Metro RP2040 and 2.8" TFT Touch Shield v2 ( ADA# 1651 )
My current project requires an ST powerSTEP motor driver UNO R3 shield with the Adafruit Metro RP2040 requiring SPI on the normal D10-13 pins. I am also using the AdaFruit 2.8" TFT Touch Shield in the alternate configuration with SPI on D11-13. Getting these to work turned out a little painful, as SPI on D10-13 doesn't work out of the box. I had used the ST powerSTEP motor shield in other Arduino UNO projects, and was caught by surprise when it's D10-13 SPI didn't work with the Metro RP2040.
Required is a simple hardware hack to swap pins D10 and D13 on the UNO R3 connectors. I did this with some extra headers with D10 and D13 broken out and swapped with blue wires to the Metro RP2040 pins on the back of the board.
The Arduino board files for the Metro RP2040 required enabling SPI1 since D10-13 can not be used with SPI0 on the RP2040, and swapping the D10 and D13 pin configuration to match the hardware header hack.
in rp2040/3.6.2/variants/adafruit_metro/pins_arduino.h, set:
// SPI1
#define PIN_SPI1_MISO (12u)
#define PIN_SPI1_MOSI (11u)
#define PIN_SPI1_SCK (10u)
#define PIN_SPI1_SS (13u)#define SPI_HOWMANY (2u)
in rp2040/3.6.2/variants/generic/common.h, change:
static const uint8_t D10 = (13u); // swapped D10 and D13 at pin headers
static const uint8_t D13 = (10u); // swapped D10 and D13 at pin headersUsing TouchPaint to verify the SPI hardware and configuration hacks, required changing the initialization to SPI1.
Adafruit_ILI9341 tft = Adafruit_ILI9341(&SPI1, TFT_DC, TFT_CS)
I had rewritten TouchPaint to add calibration for the touch function, since the software defined touch values worked very poorly with my board. The touch points with a small X and Y didn't pick up, leaving a good sized unusable area in that corner, and along the all the edges. Lowering the touch pressure from 300 to 100 got the full screen area touch working, but there was a several mm mis-registration between the pen contact, and the drawn pixels. I also cleaned up static defines to use the calibration values, returned hardware values, and dynamic pallet size based on an array of pallet colors.
The debug serial prints for calibration need to be moved below the two calibration calls for debugging. i just moved them into a single ifdef.