نمایش تصویر در ST7735 با آردوینو و SDCARD

نمایش تصویر در ST7735 با آردوینو و SDCARD

سلام به همگی.

توی این مطلب براتون راه اندازی ST7735 رو قرار دادم . این راه اندازی برای تمامی ماژول های ST7735‌یکسانه ولی اگر مایل بودید میتونید این ماژول رو خودتون بسازید . توی این مطلب آموزشش رو قرار دادم.

خب بریم سراغ راه اندازی. تصویر زیر شماتیک رو روی برد بورد نشون میده:

اما اگر ماژولتون بصورت SDA و SCL نامگذاری شده به این صورت باید SD-Card رو وصل کنید به آردوینو و LCD:

SCL=SCLK
SDA=MOSI

توی این پروژه از کتابخانه SD-Fat استفاده شده که باید به آردوینو اضافش کنید . کتابخونه رو میتونید از اینجا دانلود کنید.

باید SD-Card رو فرمت کنید به فرمت FAT-32 و عکس زیر رو دانلود کنید و داخلSD-Card قرار بدید :

دانلود عکس

حالا کد زیر رو داخل آردونیو آپلود کنید و از تصویر لذت ببرید:

// Adafruit_ImageReader test for Adafruit Mini TFT Breakout for Arduino.
// Demonstrates loading images from SD card or flash memory to the screen,
// to RAM, and how to query image file dimensions.
// OPEN THE ARDUINO SERIAL MONITOR WINDOW TO START PROGRAM.
// Requires three BMP files in root directory of SD card:
// minibot.bmp, rgbwheel.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen
// (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno,
// MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.

#include <Adafruit_GFX.h>         // Core graphics library
#include <Adafruit_ST7735.h>      // Hardware-specific library
#include <SdFat.h>                // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h>    // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions

// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.

// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD

#define SD_CS    4 // SD card chip select
#define TFT_CS  10 // TFT select pin
#define TFT_DC   8 // TFT data/command pin
#define TFT_RST  9 // Or set to -1 and connect TFT RST to Arduino reset pin

#if defined(USE_SD_CARD)
  SdFat                SD;         // SD card filesystem
  Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
#else
  // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive)
  #if defined(__SAMD51__) || defined(NRF52840_XXAA)
    Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS,
      PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
  #else
    #if (SPI_INTERFACES_COUNT == 1)
      Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
    #else
      Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
    #endif
  #endif
  Adafruit_SPIFlash    flash(&flashTransport);
  FatFileSystem        filesys;
  Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys
#endif

Adafruit_ST7735      tft    = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image       img;        // An image loaded into RAM
int32_t              width  = 0, // BMP image dimensions
                     height = 0;

void setup(void) {

  ImageReturnCode stat; // Status from image-reading functions

  Serial.begin(9600);
#if !defined(ESP32)
  while(!Serial);       // Wait for Serial Monitor before continuing
#endif

  tft.initR(INITR_MINI160x80); // Initialize screen
  Serial.println(F("TFT initialized."));
tft.initR(INITR_GREENTAB);
tft.setRotation(ST7735_MADCTL_BGR);
tft.invertDisplay(true);
  // The Adafruit_ImageReader constructor call (above, before setup())
  // accepts an uninitialized SdFat or FatFileSystem object. This MUST
  // BE INITIALIZED before using any of the image reader functions!
  Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
  // SD card is pretty straightforward, a single call...
  if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
    Serial.println(F("SD begin() failed"));
    for(;;); // Fatal error, do not continue
  }
#else
  // SPI or QSPI flash requires two steps, one to access the bare flash
  // memory itself, then the second to access the filesystem within...
  if(!flash.begin()) {
    Serial.println(F("flash begin() failed"));
    for(;;);
  }
  if(!filesys.begin(&flash)) {
    Serial.println(F("filesys begin() failed"));
    for(;;);
  }
#endif
  Serial.println(F("OK!"));

  // Fill screen blue. Not a required step, this just shows that we're
  // successfully communicating with the screen.
  tft.fillScreen(ST77XX_BLUE);

  // Load full-screen BMP file 'minibot.bmp' at position (0,0) (top left).
  // Notice the 'reader' object performs this, with 'tft' as an argument.
  Serial.print(F("Loading image to screen..."));
  stat = reader.drawBMP("/parrot.bmp", tft, 0, 0);//اسم عکس رو اینجا مشخص کنید
  // (Absolute path isn't necessary on most devices, but something
  // with the ESP32 SD library seems to require it.)

  }

void loop() {

}

اگه میخواید تصویر دیگه ای قرار بدید باید فرمت تصویر رو به bmpتبدیل کنید اسم فایل هم داخل کد مشخص کردم کجا نوشته میشه.

امیدوارم از این آموزش لذت برده باشید.

سوالی داشتید میتونید از قسمت نظرات بپرسید.

2 نظرات

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *