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.
[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!