// ------------------------------------------------------------
// STM32 Nucleo-C031C6 SPI LCD Example (ILI9341)
// Simulation link:
// https://wokwi.com/projects/365549388158011393
// ------------------------------------------------------------
// Include SPI library → Enables SPI communication
#include "SPI.h"
// Include Adafruit graphics core library
// Provides basic drawing functions like text, lines, shapes
#include "Adafruit_GFX.h"
// Include ILI9341 LCD driver library
// Handles commands specific to ILI9341 TFT display
#include "Adafruit_ILI9341.h"
// ------------------------------------------------------------
// Pin definitions for TFT display
// ------------------------------------------------------------
// Data/Command pin of TFT connected to STM32 pin 2
#define TFT_DC 2
// Chip Select pin of TFT connected to STM32 pin 3
#define TFT_CS 3
// Create TFT display object
// Parameters: CS pin, DC pin
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// ------------------------------------------------------------
// SETUP FUNCTION
// Runs once when the board is powered ON or reset
// ------------------------------------------------------------
void setup() {
// Initialize Serial communication at 115200 baud rate
// Used for debugging messages in Serial Monitor
Serial.begin(115200);
// Print a message to Serial Monitor
Serial.println("Hello, WOKWI");
// Initialize the TFT LCD
// This sets SPI, resets the display, and configures it
tft.begin();
// ---------------- Display First Text ----------------
// Set cursor position (X = 20 pixels, Y = 120 pixels)
tft.setCursor(20, 120);
// Set text color to RED
tft.setTextColor(ILI9341_RED);
// Set text size (3 = large text)
tft.setTextSize(3);
// Print text on TFT display
tft.println("Hello STM2");
// ---------------- Display Second Text ----------------
// Move cursor to a new position
tft.setCursor(24, 160);
// Change text color to GREEN
tft.setTextColor(ILI9341_GREEN);
// Set smaller text size
tft.setTextSize(2);
// Print second message
tft.println("I can do SPI :-)");
}
// ------------------------------------------------------------
// LOOP FUNCTION
// Runs continuously after setup()
// ------------------------------------------------------------
void loop() {
// Delay for 1000 milliseconds (1 second)
// No repeated action here, display remains static
delay(1000);
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6