earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.03k stars 422 forks source link

ST7789 Screen (no CS pin) issues getting it working (adafruit GFX + driver + arduino-pico) #1209

Closed fenixsong closed 1 year ago

fenixsong commented 1 year ago

I appreciate the guidance from other related forum posts but can't seem to get anything to work for my SPI Screen. A different screen but similar and common type. GMT130-V1.0 From GoldenMorning (looks the same as many off of Amazon etc.) using ST7789

Could you please show the code you used to get it working (and pin out)? I've tried every combo I can think of but can't get it to display anything.

Also, of important note: The screen does work! and with Arduino. I had a Teensy 3.6 lying around and tried it and it works fine; displaying the whole demo perfectly. So just wanted to clear that up that I know the screen works, just not with the pico and arduino-pico. :(

This is the code that works on the Teensy (tried it and many variations on pico) (commented out stuff attest to what was tried)

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

  // For the breakout board, you can use any 2 or 3 pins.
  // These pins will also work for the 1.8" TFT shield.
#define TFT_CS        -1
#define TFT_RST       0 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC        1

// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.

//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
//#define TFT_MOSI 3  // Data out
//#define TFT_SCLK 2  // Clock out

//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

float p = 3.1415926;

void setup(void) {
  //SPI.setSCK(2);
  //SPI.setRX(4);
  //SPI.setTX(3);
  //SPI.setDataMode(SPI_MODE3);
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("Hello! Teensy ST77xx TFT Test"));

//SPI.begin(true);
  // Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
tft.init(240, 240, SPI_MODE3);           // Init ST7789 240x240
tft.setSPISpeed(1000000);
  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  tft.fillScreen(ST77XX_BLACK);
//  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
//  delay(1000);

  // tft print function!
  tftPrintTest();
  delay(4000);

(it continues but it just mirrors the basic example from adafruit)

Code of what exactly works here (especially regarding any SPI configuration needed here but not in teensy) would be very appreciated and the pinout that is required. I also tried various SPI or SPI1 (&SPI1) combos to no avail - but could use guidance on what really works for that - I could use SPI0 or SPI1...it doesn't matter here - anything that would work. Thank you, please help!

maxgerhardt commented 1 year ago

Could you add a wireup diagram between the Pico and the TFT?

fenixsong commented 1 year ago

Sure, thanks... I've tried various but the current one using shown in the code above is: TFT. ------> pico GND ----- GND VCC ------ 3V3 SCK ------ GPIO2 (SPI0) SDA ------ GPIO3 (SPI0) RESET----- GPIO0 (others tried) DC ------ GPIO1 BCK (backlight) --- currently to 3v3 (always on)

As I've continued to work on this I was able to get https://github.com/Bodmer/TFT_eSPI to fully work with the Pico and this screen. So that's very positive! This could be the solution for me for now... but as I've gone thru this much - maybe I can help see if we can get this to work with Pico and this common screen and help spell out the config needed to get it to work more directly with arduino-pico. In TFT_eSPI there definitely was a big step to configure with the User_Setups folder and file...so maybe that is the missing step here that isn't well documented??? idk.