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

126 lines
4.8 KiB
Arduino
Raw Normal View History

2020-09-07 11:40:01 +02:00
/*
2020-09-24 10:43:08 +02:00
Web_BMP_pictures 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 an available WiFi connection.
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/
You can open .bmp 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.
This example will show you how you can download a .bmp file (picture) from the web and
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/
23 July 2020 by e-radionica.com
*/
2020-09-14 12:07:34 +02:00
#include "HTTPClient.h" //Include library for HTTPClient
2020-09-24 09:38:01 +02:00
#include "Inkplate.h" //Include Inkplate library to the sketch
2020-09-14 12:07:34 +02:00
#include "WiFi.h" //Include library for WiFi
2020-09-24 09:38:01 +02:00
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
2020-09-07 11:40:01 +02:00
2020-09-24 09:38:01 +02:00
const char *ssid = ""; // Your WiFi SSID
const char *password = ""; // Your WiFi password
2020-09-07 11:40:01 +02:00
2020-09-14 12:07:34 +02:00
void setup()
{
2020-09-24 09:38:01 +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
display.print("Connecting to WiFi...");
display.partialUpdate();
2020-09-24 09:38:01 +02:00
// Connect to the WiFi network.
2020-09-07 11:40:01 +02:00
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(ssid, password);
2020-09-14 12:07:34 +02:00
while (WiFi.status() != WL_CONNECTED)
{
2020-09-07 11:40:01 +02:00
delay(500);
display.print(".");
display.partialUpdate();
}
display.println("\nWiFi OK! Downloading...");
display.partialUpdate();
2020-09-24 09:38:01 +02:00
// Draw the first image from web.
// Monochromatic bitmap with 1 bit depth. Images like this load quickest.
// NOTE: Both drawImage methods allow for an optional fifth "invert" parameter. Setting this parameter 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. Forth parameter will dither the image. Photo taken by: Roberto Fernandez
if (!display.drawImage("https://varipass.org/neowise_mono.bmp", 0, 0, false, true))
2020-09-14 12:07:34 +02:00
{
2020-09-24 09:38:01 +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!
2020-09-07 11:40:01 +02:00
display.println("Image open error");
display.display();
}
display.display();
2020-09-24 09:38:01 +02:00
// Draw the second image from web, this time using a HTTPClient to fetch the response manually.
// Full color 24 bit images are large and take a long time to load, will take around 20 secs.
2020-09-07 11:40:01 +02:00
HTTPClient http;
2020-09-24 09:38:01 +02:00
// Set parameters to speed up the download process.
2020-09-07 11:40:01 +02:00
http.getStream().setNoDelay(true);
http.getStream().setTimeout(1);
2020-09-24 09:38:01 +02:00
// Photo taken by: Roberto Fernandez
2020-09-07 11:40:01 +02:00
http.begin("https://varipass.org/neowise.bmp");
2020-09-24 09:38:01 +02:00
// Check response code.
2020-09-07 11:40:01 +02:00
int httpCode = http.GET();
2020-09-14 12:07:34 +02:00
if (httpCode == 200)
{
2020-09-24 09:38:01 +02:00
// Get the response length and make sure it is not 0.
2020-09-07 11:40:01 +02:00
int32_t len = http.getSize();
2020-09-14 12:07:34 +02:00
if (len > 0)
{
if (!display.drawBitmapFromWeb(http.getStreamPtr(), 0, 0, len))
{
2020-09-24 09:38:01 +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!
2020-09-07 11:40:01 +02:00
display.println("Image open error");
display.display();
}
display.display();
}
2020-09-14 12:07:34 +02:00
else
{
2020-09-07 11:40:01 +02:00
display.println("Invalid response length");
display.display();
}
}
2020-09-14 12:07:34 +02:00
else
{
2020-09-07 11:40:01 +02:00
display.println("HTTP error");
display.display();
}
display.clearDisplay();
delay(3000);
// Try to load image and display it on e-paper at position X=0, Y=100
// NOTE: Both drawJpegFromWeb methods allow for an optional fifth "invert" parameter. Setting this parameter to
// true will flip all colors on the image, making black white and white black. forth parameter will dither the
// image.
if (!display.drawImage("https://varipass.org/destination.jpg", 0, 100, true, false))
{
// If is something failed (wrong filename or format), write error message on the screen.
display.println("Image open error");
display.display();
}
display.display();
2020-09-07 11:40:01 +02:00
http.end();
WiFi.mode(WIFI_OFF);
}
2020-09-14 12:07:34 +02:00
void loop()
{
2020-09-24 09:38:01 +02:00
// Nothing...
2020-09-07 11:40:01 +02:00
}