Updated examples to work with new SdFat and SPIFlash changes

This commit is contained in:
Melissa LeBlanc-Williams 2019-07-30 14:06:43 -07:00
parent 7d6ff23246
commit 356aa341a3
10 changed files with 441 additions and 87 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
Doxyfile* Doxyfile*
doxygen_sqlite3.db doxygen_sqlite3.db
html html
*.DS_Store

View file

@ -1,18 +1,21 @@
// Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// rgbwheel.bmp, miniwoof.bmp and wales.bmp. // rgbwheel.bmp, miniwoof.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen // 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, // (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. // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_SSD1331.h> // Hardware-specific library #include <Adafruit_SSD1331.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 #include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// Color definitions // Color definitions
#define BLACK 0x0000 #define BLACK 0x0000
#define BLUE 0x001F #define BLUE 0x001F
@ -31,9 +34,28 @@
#define TFT_DC 8 // TFT display/command pin #define TFT_DC 8 // TFT display/command pin
#define SD_CS 4 // SD card select pin #define SD_CS 4 // SD card select pin
Adafruit_SSD1331 tft = Adafruit_SSD1331(&SPI, TFT_CS, TFT_DC, TFT_RST); #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_ImageReader reader; // Class w/image-reading functions
Adafruit_SSD1331 tft = Adafruit_SSD1331(&SPI, TFT_CS, TFT_DC, TFT_RST);
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -49,11 +71,28 @@ void setup(void) {
tft.begin(); // Initialize screen tft.begin(); // Initialize screen
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,18 +1,21 @@
// Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// rgbwheel.bmp, miniwoof.bmp and wales.bmp. // rgbwheel.bmp, miniwoof.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen // 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, // (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. // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_SSD1351.h> // Hardware-specific library #include <Adafruit_SSD1351.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 #include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// Color definitions // Color definitions
#define BLACK 0x0000 #define BLACK 0x0000
#define BLUE 0x001F #define BLUE 0x001F
@ -35,9 +38,28 @@
#define TFT_DC 4 // TFT display/command pin #define TFT_DC 4 // TFT display/command pin
#define TFT_RST 6 // Or set to -1 and connect to Arduino RESET pin #define TFT_RST 6 // Or set to -1 and connect 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_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, TFT_CS, TFT_DC, TFT_RST); Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -53,11 +75,28 @@ void setup(void) {
tft.begin(); // Initialize screen tft.begin(); // Initialize screen
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,18 +1,21 @@
// Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// rgbwheel.bmp, miniwoof.bmp and wales.bmp. // rgbwheel.bmp, miniwoof.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen // 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, // (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. // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific 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 #include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// TFT display and SD card share the hardware SPI interface, using // TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus. // 'select' pins for each to identify the active device on the bus.
@ -21,8 +24,27 @@
#define TFT_DC 8 // TFT display/command pin #define TFT_DC 8 // TFT display/command pin
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin #define TFT_RST 9 // Or set to -1 and connect 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_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -38,11 +60,28 @@ void setup(void) {
tft.initR(INITR_144GREENTAB); // Initialize screen tft.initR(INITR_144GREENTAB); // Initialize screen
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,18 +1,21 @@
// Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// parrot.bmp, miniwoof.bmp and wales.bmp. // parrot.bmp, miniwoof.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen // 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, // (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. // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific 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 #include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// TFT display and SD card share the hardware SPI interface, using // TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus. // 'select' pins for each to identify the active device on the bus.
@ -21,8 +24,27 @@
#define TFT_DC 8 // TFT display/command pin #define TFT_DC 8 // TFT display/command pin
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin #define TFT_RST 9 // Or set to -1 and connect 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_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -38,11 +60,28 @@ void setup(void) {
tft.initR(INITR_BLACKTAB); // Initialize screen tft.initR(INITR_BLACKTAB); // Initialize screen
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,6 +1,6 @@
// Adafruit_ImageReader test for Adafruit Mini TFT Breakout for Arduino. // Adafruit_ImageReader test for Adafruit Mini TFT Breakout for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// OPEN THE ARDUINO SERIAL MONITOR WINDOW TO START PROGRAM. // OPEN THE ARDUINO SERIAL MONITOR WINDOW TO START PROGRAM.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// minibot.bmp, rgbwheel.bmp and wales.bmp. // minibot.bmp, rgbwheel.bmp and wales.bmp.
@ -8,22 +8,44 @@
// (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // (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. // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific 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 #include <Adafruit_ImageReader.h> // Image-reading functions
// TFT display and SD card share the hardware SPI interface, using // TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus. // '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 SD_CS 4 // SD card chip select
#define TFT_CS 10 // TFT select pin #define TFT_CS 10 // TFT select pin
#define TFT_DC 8 // TFT data/command 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 #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_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -40,11 +62,28 @@ void setup(void) {
tft.initR(INITR_MINI160x80); // Initialize screen tft.initR(INITR_MINI160x80); // Initialize screen
Serial.println(F("TFT initialized.")); Serial.println(F("TFT initialized."));
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -7,12 +7,15 @@
// (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // (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. // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789 #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SdFat.h> // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions #include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// TFT display and SD card share the hardware SPI interface, using // TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus. // 'select' pins for each to identify the active device on the bus.
@ -21,8 +24,27 @@
#define TFT_DC 8 // TFT display/command pin #define TFT_DC 8 // TFT display/command pin
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin #define TFT_RST 9 // Or set to -1 and connect 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_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -36,13 +58,30 @@ void setup(void) {
while(!Serial); // Wait for Serial Monitor before continuing while(!Serial); // Wait for Serial Monitor before continuing
#endif #endif
tft.init(240, 320); // Init ST7789 240x240 tft.init(240, 320); // Init ST7789 320x240
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,27 +1,51 @@
// Adafruit_ImageReader test for Mini TFT FeatherWing. Demonstrates loading // Adafruit_ImageReader test for Mini TFT FeatherWing. Demonstrates loading
// images to the screen, to RAM, and how to query image file dimensions. // images from SD card or flash memory to the screen, to RAM, and how to
// OPEN THE ARDUINO SERIAL MONITOR WINDOW TO START PROGRAM. // query image file dimensions. OPEN THE ARDUINO SERIAL MONITOR WINDOW TO
// Requires three BMP files in root directory of SD card: // START PROGRAM. Requires three BMP files in root directory of SD card or
// minibot.bmp, rgbwheel.bmp and wales.bmp. // flash: minibot.bmp, rgbwheel.bmp and wales.bmp.
// This ONLY demonstrates BMP loading. Other features of the FeatherWing // This ONLY demonstrates BMP loading. Other features of the FeatherWing
// (stick, buttons, backlight control) are NOT demonstrated here, // (stick, buttons, backlight control) are NOT demonstrated here,
// see other ST7735 library examples for that. // see other ST7735 library examples for that.
// MINI TFT FEATHERWING REQUIRES Adafruit_Seesaw LIBRARY. // MINI TFT FEATHERWING REQUIRES Adafruit_Seesaw LIBRARY.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific 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 #include <Adafruit_ImageReader.h> // Image-reading functions
#include <Adafruit_miniTFTWing.h> // Part of Seesaw library #include <Adafruit_miniTFTWing.h> // Part of Seesaw library
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
#define TFT_CS 5 // TFT chip select (FeatherWing) #define TFT_CS 5 // TFT chip select (FeatherWing)
#define TFT_DC 6 // TFT data/command select (FeatherWing) #define TFT_DC 6 // TFT data/command select (FeatherWing)
#define TFT_RST -1 // FeatherWing uses Seesaw for TFT reset #define TFT_RST -1 // FeatherWing uses Seesaw for TFT reset
#define SD_CS 4 // SD card chip select (Feather AdaLogger 32u4 or M0)
#define SD_CS 4 // SD card chip select (Feather AdaLogger 32u4 or M0) OR use 10
// for Adalogger FeatherWing
#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_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -46,11 +70,28 @@ void setup(void) {
tft.initR(INITR_MINI160x80); // Initialize screen tft.initR(INITR_MINI160x80); // Initialize screen
Serial.println(F("TFT initialized.")); Serial.println(F("TFT initialized."));
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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(25))) { // ESP32 requires 25 MHz limit
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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,27 +1,49 @@
// Adafruit_ImageReader test for Adafruit ILI9341 TFT Shield for Arduino. // Adafruit_ImageReader test for Adafruit ILI9341 TFT Shield for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// purple.bmp, parrot.bmp and wales.bmp. // purple.bmp, parrot.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 <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.h> // Hardware-specific 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 #include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// TFT display and SD card share the hardware SPI interface, using // TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus. // 'select' pins for each to identify the active device on the bus.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins. For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define SD_CS 4 // SD card select pin #define SD_CS 4 // SD card select pin
#define TFT_CS 10 // TFT select pin #define TFT_CS 10 // TFT select pin
#define TFT_DC 9 // TFT display/command pin #define TFT_DC 9 // TFT display/command 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_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -37,11 +59,28 @@ void setup(void) {
tft.begin(); // Initialize screen tft.begin(); // Initialize screen
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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(25))) { // ESP32 requires 25 MHz limit
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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're

View file

@ -1,6 +1,6 @@
// Adafruit_ImageReader test for Adafruit ST7735 TFT Shield for Arduino. // Adafruit_ImageReader test for Adafruit ST7735 TFT Shield for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query // Demonstrates loading images from SD card or flash memory to the screen,
// image file dimensions. // to RAM, and how to query image file dimensions.
// Requires three BMP files in root directory of SD card: // Requires three BMP files in root directory of SD card:
// parrot.bmp, miniwoof.bmp and wales.bmp. // parrot.bmp, miniwoof.bmp and wales.bmp.
// This ONLY demonstrates BMP loading. Other features of the shield // This ONLY demonstrates BMP loading. Other features of the shield
@ -8,14 +8,17 @@
// see other ST7735 library examples for that. // see other ST7735 library examples for that.
// CURRENT TFT SHIELD REQUIRES Adafruit_Seesaw LIBRARY. // CURRENT TFT SHIELD REQUIRES Adafruit_Seesaw LIBRARY.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific 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 #include <Adafruit_ImageReader.h> // Image-reading functions
#include <Adafruit_seesaw.h> // IF EARLY TFT SHIELD (no Seesaw), #include <Adafruit_seesaw.h> // IF EARLY TFT SHIELD (no Seesaw),
#include <Adafruit_TFTShield18.h> // THESE TWO LINES CAN BE REMOVED. #include <Adafruit_TFTShield18.h> // THESE TWO LINES CAN BE REMOVED.
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// TFT display and SD card share the hardware SPI interface, using // TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus. // 'select' pins for each to identify the active device on the bus.
@ -24,9 +27,28 @@
#define TFT_DC 8 // TFT display/command pin #define TFT_DC 8 // TFT display/command pin
#define TFT_RST -1 // TFT reset pin #define TFT_RST -1 // TFT 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_TFTShield18 seesaw; Adafruit_TFTShield18 seesaw;
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions int32_t width = 0, // BMP image dimensions
height = 0; height = 0;
@ -50,11 +72,28 @@ void setup(void) {
tft.initR(INITR_BLACKTAB); // Initialize screen tft.initR(INITR_BLACKTAB); // Initialize screen
Serial.print(F("Initializing SD card...")); // The Adafruit_ImageReader constructor call (above, before setup())
if(!SD.begin(SD_CS)) { // accepts an uninitialized SdFat or FatFileSystem object. This MUST
Serial.println(F("failed!")); // BE INITIALIZED before using any of the image reader functions!
for(;;); // Loop here forever 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(25))) { // ESP32 requires 25 MHz limit
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!")); Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're // Fill screen blue. Not a required step, this just shows that we're