Adafruit_ImageReader exercises run on Raspberry Pi Pico to load images from SD Card, display on 320x240 IPS SPI ILI9341
It's Adafruit_ImageReader exercises run on Raspberry Pi Pico to load images from SD Card, and display on 320x240 IPS SPI ILI9341 Module using using Adafruit_ILI9341 library.
Basically follow the page Adafruit GFX Graphics Library Loading Images
For 320x240 IPS SPI ILI9341 part using Adafruit_ILI9341 library, refer:
~ Raspberry Pi Pico (RP2040) + 3.2inch IPS SPI Module ILI9341 (using
Adafruit_ILI9341 library) It will also install Adafruit GFX Graphics Library as dependence.
This
exercise run on Raspberry Pi Pico in Earle Philhower's Arduino core (Raspberry
Pi Pico/RP2040). refer:
~
Install Earle Philhower Raspberry Pi Pico Arduino core.
Currently Adafruit_ImageReader support uncompressed 24-bit color
BMPs only, refer:
~
Convert image to 24-bit color BMPs using GIMP to prepare s1.bmp ~ s12.bmp, save in root directory of SD card.
Install
Adafruit_ImageReader and dependence in Arduino IDE Library Manager.
Connection:
ILI9341 Module Raspberry Pi Pico
1 VCC 3V3
2 GND GND
3 LCD_CS GP17
4 LCD_RST GP21
5 LCD_RS GP20
6 SDI(MOSI) GP19
7 SCK GP18
8 LED 3V3
9 SDO(MISO) GP16
10 CTP_SCL
11 CTP_RST
12 CTP_SDA
13 CTP_INT
14 SD_CS GP15
Code:
picoILI9341__ImageReader_s1.ino
/*
Exercise of Raspberry Pi Pico (Arduino framework) using Adafruit_ImageReader.
loading a single bmp from root directory of SD card (s1.bmp) and display on
3.2" TFT SPI 240x320 (ILI9341) with Capacitive Touch (FT6336U).
Notice that It have been compilied using Earle Philhower Raspberry Pi Pico Arduino core.
If compile using Arduino Mbed OS RP2040 Boards, will fail with
error: 'rp2040' was not declared in this scope
This uses the microcontroller's SPI interface for the screen and must be wired to
specific pins (MOSI/MISO/SCK).
Other pins (TFT_DC/TFT_CS/TFT_RST/SD_CS) are configurable below.
Connection:
ILI9341 Module Raspberry Pi Pico
1 VCC 3V3
2 GND GND
3 LCD_CS GP17
4 LCD_RST GP21
5 LCD_RS GP20
6 SDI(MOSI) GP19
7 SCK GP18
8 LED 3V3
9 SDO(MISO) GP16
10 CTP_SCL
11 CTP_RST
12 CTP_SDA
13 CTP_INT
14 SD_CS GP15
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.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.
#define SD_CS 15 // SD card select pin
#define TFT_DC 20
#define TFT_CS 17
#define TFT_RST 21
SdFat SD; // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
Adafruit_ILI9341 tft = Adafruit_ILI9341(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);
while(!Serial); // Wait for Serial Monitor before continuing
tft.begin(); // Initialize screen
tft.invertDisplay(true);
tft.setRotation(1);
// The Adafruit_ImageReader constructor call (above, before setup())
// accepts an uninitialized SdFat or FatVolume object. This MUST
// BE INITIALIZED before using any of the image reader functions!
Serial.print(F("Initializing filesystem..."));
// SD card is pretty straightforward, a single call...
if(!SD.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit
Serial.println(F("SD begin() failed"));
for(;;); // Fatal error, do not continue
}
Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're
// successfully communicating with the screen.
tft.fillScreen(ILI9341_BLUE);
// Load BMP 's1.bmp' into a GFX canvas in RAM.
Serial.print(F("Loading s1.bmp to canvas..."));
stat = reader.loadBMP("/s1.bmp", img);
reader.printStatus(stat); // How'd we do?
}
void loop() {
for(int r=0; r<4; r++) { // For each of 4 rotations...
tft.setRotation(r); // Set rotation
tft.fillScreen(0); // and clear screen
img.draw(tft, 0, 0); //draw from RAM-resident images:
delay(2000);
}
}
picoILI9341__ImageReader.ino
/*
Exercise of Raspberry Pi Pico (Arduino framework) using Adafruit_ImageReader.
loading a bmp(s) from root directory of SD card (s1.bmp~s12.bmp) and display on
3.2" TFT SPI 240x320 (ILI9341) with Capacitive Touch (FT6336U) repeatly.
Notice that It have been compilied using Earle Philhower Raspberry Pi Pico Arduino core.
If compile using Arduino Mbed OS RP2040 Boards, will fail with
error: 'rp2040' was not declared in this scope
This uses the microcontroller's SPI interface for the screen and must be wired to
specific pins (MOSI/MISO/SCK).
Other pins (TFT_DC/TFT_CS/TFT_RST/SD_CS) are configurable below.
Connection:
ILI9341 Module Raspberry Pi Pico
1 VCC 3V3
2 GND GND
3 LCD_CS GP17
4 LCD_RST GP21
5 LCD_RS GP20
6 SDI(MOSI) GP19
7 SCK GP18
8 LED 3V3
9 SDO(MISO) GP16
10 CTP_SCL
11 CTP_RST
12 CTP_SDA
13 CTP_INT
14 SD_CS GP15
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.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.
#define SD_CS 15 // SD card select pin
#define TFT_DC 20
#define TFT_CS 17
#define TFT_RST 21
SdFat SD; // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
const char *bmpFile[] = {"/s1.bmp", "/s2.bmp", "/s3.bmp", "/s4.bmp",
"/s5.bmp", "/s6.bmp", "/s7.bmp", "/s8.bmp",
"/s9.bmp", "/s10.bmp", "/s11.bmp", "/s12.bmp"};
void setup(void) {
Serial.begin(9600);
while(!Serial); // Wait for Serial Monitor before continuing
tft.begin(); // Initialize screen
tft.invertDisplay(true);
tft.setRotation(1);
// The Adafruit_ImageReader constructor call (above, before setup())
// accepts an uninitialized SdFat or FatVolume object. This MUST
// BE INITIALIZED before using any of the image reader functions!
Serial.print(F("Initializing filesystem..."));
// SD card is pretty straightforward, a single call...
if(!SD.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit
Serial.println(F("SD begin() failed"));
for(;;); // Fatal error, do not continue
}
Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're
// successfully communicating with the screen.
tft.fillScreen(ILI9341_BLUE);
}
void loop() {
for(int i=0; i<12; i++) {
reader.drawBMP(bmpFile[i], tft, 0, 0);
delay(2000);
}
}
next:
~ Detect FT6336U Capacitive Touch Screen on Raspberry Pi Pico using Arduino-FT6336U library.
related:
~ Adafruit_GFX/ImageReader exercises to load bmp images from MicroSD and display on 240×320 ST7789 SPI TFT, run on Seeed Studio XIAO ESP32S3 Sense (Arduino Platform).
Comments
Post a Comment