No title

1. Convert Your Image to C-Array

Upload an image and select your ST7735 screen size to generate the RGB565 array.

Image to Arduino ST7735 RGB565 Converter



px    px

Preview (Stretched to fit):
Arduino C Array Code:

2. Library-Free Arduino Code

Copy the code below into your Arduino IDE. Replace the example image array at the top with the array generated from the tool above. Update the drawImage function dimensions to match your array.

#include <SPI.h>
#include <avr/pgmspace.h>

// Pin definitions
#define TFT_CS   10
#define TFT_DC   9
#define TFT_RST  8

// --- PASTE YOUR GENERATED ARRAY HERE ---
const unsigned char image_32x32[] PROGMEM = {
  // Your generated hex codes will go here
};

// --- Low Level SPI Functions ---
void writeCommand(uint8_t cmd) {
  digitalWrite(TFT_DC, LOW);  // Command mode
  digitalWrite(TFT_CS, LOW);
  SPI.transfer(cmd);
  digitalWrite(TFT_CS, HIGH);
}

void writeData(uint8_t data) {
  digitalWrite(TFT_DC, HIGH); // Data mode
  digitalWrite(TFT_CS, LOW);
  SPI.transfer(data);
  digitalWrite(TFT_CS, HIGH);
}

// --- ST7735 Initialization ---
void initST7735() {
  digitalWrite(TFT_RST, HIGH); delay(10);
  digitalWrite(TFT_RST, LOW); delay(10);
  digitalWrite(TFT_RST, HIGH); delay(150);

  writeCommand(0x01); // Software Reset
  delay(150);
  
  writeCommand(0x11); // Sleep Out
  delay(150);

  writeCommand(0x3A); // Color Mode
  writeData(0x05);    // 16-bit color (RGB565)

  writeCommand(0x36); // Memory Data Access Control
  writeData(0x00);    // RGB color order

  writeCommand(0x29); // Display ON
  delay(100);
}

// --- Draw Image Function ---
void drawImage(uint8_t x, uint8_t y, uint8_t width, uint8_t height, const unsigned char* image) {
  writeCommand(0x2A); 
  writeData(0x00); writeData(x);
  writeData(0x00); writeData(x + width - 1);

  writeCommand(0x2B); 
  writeData(0x00); writeData(y);
  writeData(0x00); writeData(y + height - 1);

  writeCommand(0x2C); // Memory Write

  digitalWrite(TFT_DC, HIGH);
  digitalWrite(TFT_CS, LOW);
  
  uint16_t totalBytes = width * height * 2;
  
  for (uint16_t i = 0; i < totalBytes; i++) {
    uint8_t byteToSend = pgm_read_byte(&image[i]);
    SPI.transfer(byteToSend);
  }
  
  digitalWrite(TFT_CS, HIGH);
}

// --- Main Arduino Flow ---
void setup() {
  pinMode(TFT_CS, OUTPUT);
  pinMode(TFT_DC, OUTPUT);
  pinMode(TFT_RST, OUTPUT);

  SPI.begin();
  SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));

  initST7735();
  
  // Draw the image at coordinates x=0, y=0. Change 32, 32 to match your image dimensions.
  drawImage(0, 0, 32, 32, image_32x32);
}

void loop() {
  // Static image display
}
Previous Post Next Post