View All Posts
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Learn how to create a weather display using the LILYGO 2.7-inch ePaper Plus Module, featuring step-by-step instructions on programming in PlatformIO, designing an enclosure in Fusion360, and utilizing deep sleep mode for long battery life.

Related Content

[0:00] I’ve been playing around with one of these E-Paper displays.
[0:03] I’ve got the LILYGO 2.7” ePaper Plus Module
[0:07] The classic thing that people seem to do is get a weather display up and running
[0:12] so I thought I would do the same.
[0:14] But first, I’d like to thank PCBWay for sponsoring the channel.
[0:18] PCBWay offer PCB Production, CNC and 3D Printing, PCB Assembly and much much more.
[0:25] They are great to deal with and offer excellent service, quality and value for money.
[0:29] Check out the link in the description.
[0:32] There’s a really nice library by G6EJD on GitHub that everyone seems to be using.
[0:39] This already has support for a whole bunch of EPaper displays
[0:42] including the Waveshare 2.7 inch display which is the one that is used on the LILYGO board I have.
[0:48] Most of the instructions are around using the Arduino IDE
[0:51] but as regular viewers will know I’m much happier using PlatformIO,
[0:55] so we’ll get it up and running in that
[0:58] First thing to do is get a new project.
[1:01] Once the project has been created
[1:04] we need to add some dependencies by editing the the “platformio.ini” file.
[1:09] For the weather display library we can just include a direct link to the GitHub repo.
[1:14] We also need to include “Wire”, the “Adafruit BusIO” libray, “GxEPD2” and “U8g2_for_Adafruit_GFX”
[1:25] Once we add these entries, PlatformIO will download them
[1:29] and we can copy out the example sketch that we need for our board
[1:33] We’re looking for the “Waveshare_2_7.ino” file.
[1:38] I’m going to copy the contents of this and replace the contents of my “main.cpp”
[1:43] making sure that I keep the hash include for Arduino.
[1:47] This code expects a file called “owm_credentials.h” and for some reason this wasn’t in the same folder as the 2.7 inch example
[1:55] but the other folders contain example files
[1:58] and we just need to copy one into our src folder.
[2:01] We need to edit this to match our setup.
[2:04] We need our WiFi credentials.
[2:06] And we also need an API key for open weathermap.
[2:10] Obtaining this key is pretty straightforward
[2:13] we just need to create an account
[2:14] And then goto the API menu and subscribe to free tier of the One Call API.
[2:21] You can access your API keys from your profile once you have subscribed to the API.
[2:27] There’s a couple of other settings to fill out including the city you want forecasts for,
[2:31] your country, language, hemisphere, units and timezone.
[2:35] Back in our main.cpp we need to make sure we select the correct language file
[2:40] and we need to update the pins to match our LILYGO board
[2:43] we can find these pins from the sample code in the LILYGO GitHub repository
[2:47] (I’ve included a link to their repository along with a link to the ePaper weather repository in the video description).
[2:55] Now if we try and compile we get a bunch of errors.
[2:59] We don’t have any forward declarations for the functions so the compiler is getting a bit upset.
[3:04] Now, we could go through and copy all the function definitions to the top of the file.
[3:09] But let’s be lazy and use some regular expression magic.
[3:13] If we look at a typical function declaration we can see that they always start with a letter
[3:18] followed by a bunch of characters and always finish with a closing bracket.
[3:22] We can build a simple regular expression that only matches this pattern
[3:25] and won’t match anything else in the file.
[3:29] If we use this in VSCode to search and switch on regular expressions
[3:33] then we’ll only find function declarations.
[3:36] You can then select all the find results using “Cmd+Shift+L” on a Mac or “Ctrl+Shift+L” on windows.
[3:44] We can now copy all the function declarations and paste them in at the top of the file.
[3:49] All we’re missing is a semi-colon on the end of each line
[3:52] which we can add with another simple find and replace
[3:56] All we’re doing here is matching the whole line.
[3:58] Placing this inside round brackets turns it into something called a “capture group”.
[4:02] We can then use this capture group in our replace expression by using $1 and stick a semi-colon on the end.
[4:10] Regular expressions are really powerful - it’s really worth taking some time to learn about them.
[4:15] With that done, we can compile and upload to the device.
[4:19] It’s pretty cool.
[4:21] I might tweak things in the future to add more things to the display
[4:24] there’s a blank slot in the bottom right that could be filled with something useful.
[4:28] And Ive also got a three colour display, so I can include some red.
[4:32] Maybe for the full sun I’ll change that to a red colour.
[4:35] Or when it’s very warm, which is unlikely for Scotland - I’ll have the temperatures shown in red.
[4:41] I’m going to get hold of a couple more ePaper displays
[4:43] as I can think of a lot projects that would benefit from a long battery life and a display.
[4:48] There are a couple of interesting things in the code. That it’s worth diving into.
[4:53] It makes great use of deep sleep mode and only wakes up every half an hour.
[4:58] This should mean my fairly small battery should last for quite some time.
[5:01] I don’t really have suitable equipment for measuring the current draw during deep sleep,
[5:06] but I’m expecting the battery to last quite a few months.
[5:09] I’ll do a future video on deep sleep as it’s pretty interesting.
[5:13] It’s also got quite an interesting bit of code for working out the percentage battery life remaining.
[5:18] The code assumes that there’s a potential divider on the battery feeding a value into GPIO35
[5:24] which fortunately matches the Lilygo schematic.
[5:28] The author of the code has produced a formula that maps onto the discharge graph of a lithium ion battery
[5:33] we can plot his graph using Excel.
[5:36] it seems to match my google searches of what a lithium battery discharge graphs look like.
[5:41] So this should work quite well
[5:44] So, that’s the software all done.
[5:46] I just need a nice box to put this in.
[5:50] So, in Fusion360
[5:52] I’ve made a very simple model of the LILYGO board based on their specs
[5:56] and added in the battery I’m going to be using.
[5:59] Once we’ve got this basic model in place, making a box is pretty straightforward.
[6:04] The first thing we’ll do is create the front panel
[6:07] we just create a sketch and project the screw holes and screen through.
[6:12] Previously for this kind of thing I’ve used these really nice brass inserts along with M3 bolts.
[6:17] However I’ve run out of the original ones I bought which were manufactured by Ruthex
[6:21] and can only find some generic ones.
[6:24] I’ve tried these out and they don’t seem to be of the same quality.
[6:27] Because of this I’m going to use screws to hold the box shut.
[6:30] If anyone knows where I can get some of the original Ruthex ones then please let me know.
[6:35] To complete the case we just extrude the sides of the case down to the bottom face of the battery
[6:40] and add a bit of extra wiggle room.
[6:42] We can then just close the bottom of the case and we’ve got a box.
[6:46] We can then simply split this using the split body tool and a construction plane.
[6:51] The PCB is slightly lower than the actual screen so I’ll extrude some supports for it from the front of the case.
[6:58] And then we just need to add some supports from the bottom of the case for the screws to go into.
[7:04] The final thing to do is to just make a hole for the USB socket.
[7:08] Originally I was thinking that I wouldn’t bother with this as the battery is going to last quite a few months
[7:13] but then I thought that I’d better add it so I could easily flash new versions of the firmware without unscrewing everything
[7:18] I would normally add over the air update
[7:21] but that’s a bit tricky when the device is spending most of its time in deep sleep.
[7:26] The print came out really nicely.
[7:28] I might experiment with some different colours to see how that looks,
[7:30] but all in all, I’m pretty happy with this project.
[7:33] If I’m honest, it’s really nice that someone else has done all the heavy lifting on the software side.
[7:38] Makes life so much easier.
[7:40] I’ve pushed my code up to GitHub
[7:42] so if you’ve got one of these LILIGO EPaper displays you should be able to get it up and running pretty easily
[7:48] just update the “owm_credentials.h” file with your own details.
[7:51] There are more videos coming up.
[7:53] So don’t forget to hit that subscribe button.
[7:55] I’ll see you in the next video!

HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening

> Image


A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts