sbcshop / RangePi

Range-Pi is a low cost portable “Plug and Play LoRaTM Dongle” based on Raspberry Pi RP2040 and LoRaTM Modules, comes with an onboard 1.14" LCD that covers 433/868/915 MHz frequency band to enable data transmission up to 5 KM.
MIT License
27 stars 6 forks source link

ST7789 control with C #6

Open amitnjha opened 1 year ago

amitnjha commented 1 year ago

I am looking for some example code as to how I can do similar implementation in C like you have provided examples for Python. The issue I am having is printing out anything to the ST7789 TFT display.

I took example from here and tried adjusting SPI parameters as per SPI configuration you have in python code, but it does not work.

Can you please advice on it? Awesome product by the way 👍. We have bought four so far and are looking to get four more at least.

krislabs commented 1 year ago

This example used with Arduino IDE works for me: https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/examples/graphicstest_st7789/graphicstest_st7789.ino

Modifications needed:

  #define TFT_CS         9 \
  #define TFT_RST        12 // Or set to -1 and connect to Arduino RESET pin \
  #define TFT_DC         8 \
//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 11  // Data out
#define TFT_SCLK 10  // Clock out

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
tft.init(135, 240);

Rotation after initialization:

tft.setRotation(tft.getRotation()+3);