Remarks
St7789 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The ST7789 is a display controller used to drive color displays over SPI using 12, 16 or 18 bbp. These displays require a backlight. These are typically paired with high pixel density displays, the most common being a 1.5" 240x240 display.
ST7789 displays typically use SPI mode 3, but you may find variants that require different modes.
The Meadow.Foundation ST7789 driver currently only supports 16bpp RGB565.
Purchasing
You can get ST7789 displays from the following suppliers:
Code Example
MicroGraphics graphics;
St7789 display;
public override Task Initialize()
{
Resolver.Log.Info("Initializing ...");
var config = new SpiClockConfiguration(new Frequency(48000, Frequency.UnitType.Kilohertz), SpiClockConfiguration.Mode.Mode3);
var spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config);
display = new St7789(
spiBus: spiBus,
chipSelectPin: Device.Pins.A03,
dcPin: Device.Pins.A04,
resetPin: Device.Pins.A05,
width: 240, height: 240, colorMode: ColorMode.Format16bppRgb565);
display.Clear(Color.AliceBlue);
display.Show();
graphics = new MicroGraphics(display)
{
Rotation = RotationType._90Degrees,
IgnoreOutOfBoundsPixels = true
};
return base.Initialize();
}
public override Task Run()
{
graphics.Clear(true);
graphics.DrawRectangle(120, 0, 120, 220, Color.White, true);
graphics.DrawRectangle(0, 0, 120, 20, Color.Red, true);
graphics.DrawRectangle(0, 20, 120, 20, Color.Purple, true);
graphics.DrawRectangle(0, 40, 120, 20, Color.Blue, true);
graphics.DrawRectangle(0, 60, 120, 20, Color.Green, true);
graphics.DrawRectangle(0, 80, 120, 20, Color.Yellow, true);
graphics.DrawRectangle(0, 100, 120, 20, Color.Orange, true);
graphics.Show();
DisplayTest();
return base.Run();
}
Sample project(s) available on GitHub
Wiring Example
To wire a ST7789 to your Meadow board, connect the following:
ST7789 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | SCK |
SDA | MOSI |
RESET | D00 |
DC | D01 |
It should look like the following diagram:
Syntax
public class St7789 : TftSpiBase, IGraphicsDisplay, IRotatableDisplay
Constructors
St7789(ISpiBus, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, Int32, Int32, ColorMode)
Create a new St7789 color display object
Declaration
public St7789(ISpiBus spiBus, IDigitalOutputPort chipSelectPort, IDigitalOutputPort dataCommandPort, IDigitalOutputPort resetPort, int width, int height, ColorMode colorMode = default(ColorMode))
Parameters
Type | Name | Description |
---|---|---|
ISpiBus | spiBus | SPI bus connected to display |
IDigitalOutputPort | chipSelectPort | Chip select output port |
IDigitalOutputPort | dataCommandPort | Data command output port |
IDigitalOutputPort | resetPort | Reset output port |
System.Int32 | width | Width of display in pixels |
System.Int32 | height | Height of display in pixels |
ColorMode | colorMode | The color mode to use for the display buffer |
St7789(ISpiBus, IPin, IPin, IPin, Int32, Int32, ColorMode)
Create a new St7789 color display object
Declaration
public St7789(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, int width, int height, ColorMode colorMode = default(ColorMode))
Parameters
Type | Name | Description |
---|---|---|
ISpiBus | spiBus | SPI bus connected to display |
IPin | chipSelectPin | Chip select pin |
IPin | dcPin | Data command pin |
IPin | resetPin | Reset pin |
System.Int32 | width | Width of display in pixels |
System.Int32 | height | Height of display in pixels |
ColorMode | colorMode | The color mode to use for the display buffer |
Fields
DefaultSpiBusSpeed
The default SPI bus frequency
Declaration
public static Frequency DefaultSpiBusSpeed
Field Value
Type | Description |
---|---|
Frequency |
Properties
DefautColorMode
The default display color mode
Declaration
public override ColorMode DefautColorMode { get; }
Property Value
Type | Description |
---|---|
ColorMode |
Overrides
SupportedColorModes
The color modes supported by the display
Declaration
public override ColorMode SupportedColorModes { get; }
Property Value
Type | Description |
---|---|
ColorMode |
Overrides
Methods
Initialize()
Initalize the display
Declaration
protected override void Initialize()
Overrides
SetAddressWindow(Int32, Int32, Int32, Int32)
Set addrees window for display updates
Declaration
protected override void SetAddressWindow(int x0, int y0, int x1, int y1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x0 | X start in pixels |
System.Int32 | y0 | Y start in pixels |
System.Int32 | x1 | X end in pixels |
System.Int32 | y1 | Y end in pixels |
Overrides
SetRotation(RotationType)
Set the display rotation
Declaration
public void SetRotation(RotationType rotation)
Parameters
Type | Name | Description |
---|---|---|
RotationType | rotation | The rotation value |