|
| 1 | +/* |
| 2 | + Inkplate5V2_Show_Pictures_From_Web example for Soldered Inkplate 5 |
| 3 | + For this example you will need a USB C cable, Inkplate 5, and an available WiFi connection. |
| 4 | + Select "Soldered Inkplate5V2" from Tools -> Board menu. |
| 5 | + Don't have "Soldered Inkplate5V3" option? Follow our tutorial and add it: |
| 6 | + https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/ |
| 7 | +
|
| 8 | + You can open .bmp files that have a color depth of 1 bit (BW bitmap), 4 bit, 8 bit and |
| 9 | + 24 bit AND have resoluton smaller than 960x540 or otherwise it won't fit on screen. |
| 10 | +
|
| 11 | + .jpg files encoded with Baseline DCT, Huffman coding are supported. |
| 12 | + .png files are generally well supported. |
| 13 | +
|
| 14 | + If you are experiencing issues, usually opening the image in an image editor and |
| 15 | + exporting it in a different format resolves the issue. |
| 16 | +
|
| 17 | + This example will show you how you can download a .bmp and .jpg file from the web and |
| 18 | + display that image on Inkplate 5's e-Paper display. |
| 19 | +
|
| 20 | + Want to learn more about Inkplate? Visit www.inkplate.io |
| 21 | + Looking to get support? Write on our forums: https://forum.soldered.com/ |
| 22 | + 15 March 2024 by Soldered |
| 23 | +*/ |
| 24 | + |
| 25 | +// Next 3 lines are a precaution, you can ignore those, and the example would also work without them |
| 26 | +#ifndef ARDUINO_INKPLATE5V2 |
| 27 | +#error "Wrong board selection for this example, please select Soldered Inkplate5V2 in the boards menu." |
| 28 | +#endif |
| 29 | + |
| 30 | +// Include needed libraries |
| 31 | +#include "HTTPClient.h" //Include library for HTTPClient |
| 32 | +#include "Inkplate.h" //Include Inkplate library to the sketch |
| 33 | +#include "WiFi.h" //Include library for WiFi |
| 34 | + |
| 35 | +// Enter your WiFi credentials |
| 36 | +const char *ssid = ""; |
| 37 | +const char *pass = ""; |
| 38 | + |
| 39 | +Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW) |
| 40 | + |
| 41 | +void setup() |
| 42 | +{ |
| 43 | + display.begin(); // Init Inkplate library (you should call this function ONLY ONCE) |
| 44 | + display.clearDisplay(); // Clear frame buffer of display |
| 45 | + display.display(); // Put clear image on display |
| 46 | + |
| 47 | + display.setTextSize(2); // Use larger text for easier readability |
| 48 | + display.print("Connecting to WiFi..."); |
| 49 | + display.partialUpdate(); |
| 50 | + |
| 51 | + // Connect to the WiFi network. |
| 52 | + WiFi.mode(WIFI_MODE_STA); |
| 53 | + WiFi.begin(ssid, pass); |
| 54 | + while (WiFi.status() != WL_CONNECTED) |
| 55 | + { |
| 56 | + delay(500); |
| 57 | + display.print("."); |
| 58 | + display.partialUpdate(); |
| 59 | + } |
| 60 | + display.println("\nWiFi OK! Downloading..."); |
| 61 | + display.partialUpdate(); |
| 62 | + |
| 63 | + // Draw the first image from web. |
| 64 | + // Monochromatic bitmap with 1 bit depth. Images like this load quickest. |
| 65 | + // NOTE: Both drawImage methods allow for an optional fifth "invert" parameter. Setting this parameter to true |
| 66 | + // will flip all colors on the image, making black white and white black. This may be necessary when exporting |
| 67 | + // bitmaps from certain softwares. Fourth parameter will dither the image. Photo taken by: Roberto Fernandez |
| 68 | + if (!display.drawImage("https://varipass.org/neowise_mono.bmp", 0, 0, false, true)) |
| 69 | + { |
| 70 | + // If is something failed (wrong filename or wrong bitmap format), write error message on the screen. |
| 71 | + // REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression! |
| 72 | + display.println("Image open error"); |
| 73 | + display.display(); |
| 74 | + } |
| 75 | + display.display(); |
| 76 | + |
| 77 | + // Draw the second image from web, this time using a HTTPClient to fetch the response manually. |
| 78 | + // Full color 24 bit images are large and take a long time to load, will take around 20 secs. |
| 79 | + HTTPClient http; |
| 80 | + // Set parameters to speed up the download process. |
| 81 | + http.getStream().setNoDelay(true); |
| 82 | + http.getStream().setTimeout(1); |
| 83 | + |
| 84 | + // Photo taken by: Roberto Fernandez |
| 85 | + http.begin("https://varipass.org/neowise.bmp"); |
| 86 | + |
| 87 | + // Check response code. |
| 88 | + int httpCode = http.GET(); |
| 89 | + if (httpCode == 200) |
| 90 | + { |
| 91 | + // Get the response length and make sure it is not 0. |
| 92 | + int32_t len = http.getSize(); |
| 93 | + if (len > 0) |
| 94 | + { |
| 95 | + if (!display.drawBitmapFromWeb(http.getStreamPtr(), 0, 0, len)) |
| 96 | + { |
| 97 | + // If is something failed (wrong filename or wrong bitmap format), write error message on the screen. |
| 98 | + // REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no |
| 99 | + // compression! |
| 100 | + display.println("Image open error"); |
| 101 | + display.display(); |
| 102 | + } |
| 103 | + display.display(); |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + display.println("Invalid response length"); |
| 108 | + display.display(); |
| 109 | + } |
| 110 | + } |
| 111 | + else |
| 112 | + { |
| 113 | + display.println("HTTP error"); |
| 114 | + display.display(); |
| 115 | + } |
| 116 | + |
| 117 | + display.clearDisplay(); |
| 118 | + delay(3000); |
| 119 | + |
| 120 | + // Try to load image and display it on e-paper at position X=80, Y=70 (centered) |
| 121 | + // NOTE: Both drawJpegFromWeb methods allow for an optional fifth "invert" parameter. Setting this parameter to |
| 122 | + // true will flip all colors on the image, making black white and white black. Fourth parameter will dither the |
| 123 | + // image. |
| 124 | + if (!display.drawImage("https://varipass.org/destination.jpg", 80, 70, true, false)) |
| 125 | + { |
| 126 | + // If is something failed (wrong filename or format), write error message on the screen. |
| 127 | + display.println("Image open error"); |
| 128 | + display.display(); |
| 129 | + } |
| 130 | + display.display(); |
| 131 | + |
| 132 | + http.end(); |
| 133 | + |
| 134 | + WiFi.mode(WIFI_OFF); |
| 135 | +} |
| 136 | + |
| 137 | +void loop() |
| 138 | +{ |
| 139 | + // Nothing... |
| 140 | +} |
0 commit comments