I'm a sucker for a gadget, and when I saw this come up on Twitter, I just had to buy one.
I've got myself a Monocle from Brilliant Labs.
Let's see what's in the box.
So we've got the charging case with the Monocle inside, and we've got the charging cable.
It's an AR device that clips onto your glasses.
As usual, this video is sponsored by PCBWay, and I was hoping to get their logo to show
up on the Monocle.
The problem is, there's clamorly no support for images, it only does vector graphics.
But we don't let these small problems get in the way on this channel, how hard can it
be to take a PNG file and turn it into polygons.
This was a pretty fun exercise, there are quite a few libraries that can help out with this
and ChatGPT was a lifesaver.
The first thing I'm doing is detection the two most common colours.
Looking at our image, you would think this should be simple, we've got green and orange.
But zooming in, we can see that there's actually a lot more colours, particularly where the
orange slash overlaps the green wire.
You can also see that we've got various levels of opacity around the edges.
We can see the range of colours if we do a 3D plot of the red, green and blue values.
We've got a wide range of colours.
However, we can feed our colours into a K-means clustering algorithm, and provided we tell
it just to create two clusters, we can get the two most common colours.
We can now map our original colours onto these clusters, and if we look at the image
now, we've got rid of all the anti-aliasing that was there.
I've also thresholded the alpha channel, so we've got rid of the opacity.
We can now take each colour in turn, and feed it through a library that extracts the boundaries.
I'm using a library called potrace, I'm not going to pretend to know how this works,
I've linked to a paper that explains it in the description.
This gives us a bunch of outlines for the boundaries of our objects, and also gives
us outlines for the holes within our objects.
It was a small issue though, it uses a lot of bezier curves for its lines, and our library
only does straight lines.
But all is not lost.
The equation for a bezier curve is pretty simple, so we can approximate any bezier curve
with a series of straight lines.
So far so good, but we've still got a problem.
We've got the outlines of our shapes, and we've got the outlines of the holes in our
shapes, but our library can only draw simple polygons, it can't draw polygons with holes
in them.
There's a couple of options to solve this, after confirming with chatgpt, we decided
to use a triangulation library.
This library can take the boundary polygon, and the whole polygons, and produces a bunch
of triangles.
We can easily feed these into the display, as triangles are just very simple polygons.
But we do have a lot of triangles, this may not be very efficient.
After a bit of digging into the triangulation code, I found that it actually has a function
that will extract the boundary of a polygon with holes.
So we can just feed our polygons into that, and we end up with some nice polygons with
holes in.
Our work is done, we're ready to display the results.
Unfortunately so far, I've only managed to display a couple of the letters, we're going
to need to wait for some new firmware with some bug fixes.
But if you want some PCBs manufactured, you know where to go.
Stay tuned to the channel, at some point I may get a spinning cover from Elite working,
which will be pretty amazing.
Let's take a closer look at the tech.
The case is really just for charging up the monocle, it's got a built in 450 mWh battery
so you don't need to have it plugged in all the time, and it connects to the monocle using
these two pogo pins.
As far as I can tell, it's just a dumb device, the USB connection is just used for charging.
The actual monocle itself connects over Bluetooth and runs MicroPython, there's a web rebel
you can use to program it.
We can run a pretty simple blink sketch with the built in LEDs, and it seems to work pretty
well.
We're just cycling between the red LED and the green LED in this sketch.
There's some pretty interesting bits of hardware, we've got a touch controller for
the two touch pads on the top, and the MCU is a Nordic NRF 52832, with 512 KB of flash
and 64 KB of RAM.
Now compared to things like the ESP32 which we're normally using, it's a pretty puny
processor.
It only runs at 64MHz, and with 64 KB of RAM, we're really limited in what we can do with
it.
To make up for this, the monocle comes with a built in FPGA.
This is used to manage the camera, microphone and to drive the display.
There's quite a nice exploded diagram on the monocle website that shows you all the bits.
There's a 70 mAh battery, that's this big orange blob that you can see here, and you
can see the 5 megapixel camera via next to it, the microphone's hidden somewhere behind.
The screen is up here connected to the PCB.
This shines down onto some optics, which let you see it when you're wearing the monocle.
It's really hard to film the screen, but I've done my best.
Here I'm running one of their simple samples that wires up the touch buttons to some text
on the screen.
It's just wired up so the text changes when you touch the A or the B buttons.
The firmware is a bit of a work in progress at the moment, so I'm waiting for a new release
to play around with some more graphics.
Is it actually any good?
Well, it does work.
The lenses in my glasses are pretty thick and bulge out quite a bit, which makes it quite
hard to get the monocle to sit at a good angle.
But with a bit of fiddling, it does work ok.
I'll probably 3D print something to make it a bit more useful.
The MCU is pretty underpowered, but the ability to offload any heavy processing to another
device over Bluetooth and the built-in FPGA do mitigate this somewhat.
I haven't done any FPGA programming since university, so this could get quite interesting.
What in all is a fun bit of kit?
I just need to think of something useful to do with it now.
Any suggestions in the comments?