inkplate-6-arduino-library/examples/Advanced Inkplate Features/Inkplate_SD_pictures/Inkplate_SD_pictures.ino

94 lines
3.9 KiB
Arduino
Raw Permalink Normal View History

2020-09-07 11:40:01 +02:00
/*
2020-09-24 10:43:08 +02:00
Inkplate_SD_BMP example for e-radionica Inkplate6
2020-09-07 11:40:01 +02:00
For this example you will need a micro USB cable, Inkplate6 and a SD card loaded with
image1.bmp and image2.bmp file that can be found inside folder of this example.
Select "Inkplate 6(ESP32)" from Tools -> Board menu.
Don't have "Inkplate 6(ESP32)" option? Follow our tutorial and add it:
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
To work with SD card on Inkplate, you will need to add one extra library.
Download and install it from here: https://github.com/e-radionicacom/Inkplate-6-SDFat-Arduino-Library
2020-09-24 11:47:39 +02:00
You can open .bmp, .jpeg or .png files that have color depth of 1 bit (BW bitmap), 4 bit, 8 bit and
2020-09-07 11:40:01 +02:00
24 bit AND have resoluton smaller than 800x600 or otherwise it won't fit on screen.
Format your SD card in standard FAT fileformat.
2020-09-24 11:47:39 +02:00
This example will show you how you can read .bmp and .jpeg files (pictures) from SD card and
2020-09-07 11:40:01 +02:00
display that image on e-paper display.
Want to learn more about Inkplate? Visit www.inkplate.io
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
15 July 2020 by e-radionica.com
*/
2020-09-21 13:24:50 +02:00
#include "Inkplate.h" //Include Inkplate library to the sketch
#include "SdFat.h" //Include library for SD card
Inkplate display(INKPLATE_3BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
SdFile file; // Create SdFile object used for accessing files on SD card
2020-09-07 11:40:01 +02:00
2020-09-09 14:18:37 +02:00
void setup()
{
2020-09-07 11:40:01 +02:00
Serial.begin(115200);
2020-09-09 14:18:37 +02:00
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
display.clearDisplay(); // Clear frame buffer of display
display.display(); // Put clear image on display
2020-09-07 11:40:01 +02:00
2020-09-09 14:18:37 +02:00
// Init SD card. Display if SD card is init propery or not.
if (display.sdCardInit())
{
2020-09-07 11:40:01 +02:00
display.println("SD Card OK! Reading image...");
display.partialUpdate();
2020-09-09 14:18:37 +02:00
// If card is properly init, try to load image and display it on e-paper at position X=0, Y=0
2020-09-24 09:38:01 +02:00
// NOTE: Both drawImage methods allow for an optional fifth "invert" parameter. Setting this parameter
2020-09-09 14:18:37 +02:00
// to true will flip all colors on the image, making black white and white black. This may be necessary when
// exporting bitmaps from certain softwares.
2020-09-24 09:38:01 +02:00
if (!display.drawImage("image1.bmp", 0, 0, 1))
2020-09-09 14:18:37 +02:00
{
// If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
// REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no
// compression! You can turn of dithering for somewhat faster image load by changing the last 1 to 0, or
// removing the 1 argument completely
2020-09-07 11:40:01 +02:00
display.println("Image open error");
display.display();
}
display.display();
}
2020-09-09 14:18:37 +02:00
else
{
// If SD card init not success, display error on screen and stop the program (using infinite loop)
2020-09-07 11:40:01 +02:00
display.println("SD Card error!");
display.partialUpdate();
2020-09-09 14:18:37 +02:00
while (true)
;
2020-09-07 11:40:01 +02:00
}
delay(5000);
2020-09-09 14:18:37 +02:00
// Now try to load image using SdFat library class (for more advanced users) and display image on epaper.
if (file.open("image2.bmp", O_RDONLY))
{
display.drawBitmapFromSd(&file, 0, 0);
2020-09-07 11:40:01 +02:00
display.display();
}
display.clearDisplay();
delay(3000);
// Now draw a JPEG
if (!display.drawImage("pyramid.jpg", 100, 0, true, false))
{
// If is something failed (wrong filename or wrong format), write error message on the screen.
// You can turn off dithering for somewhat faster image load by changing the fifth parameter to false, or
// removing the parameter completely
display.println("Image open error");
display.display();
}
display.display();
2020-09-07 11:40:01 +02:00
}
2020-09-09 14:18:37 +02:00
void loop()
{
// Nothing...
2020-09-07 11:40:01 +02:00
}