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