🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
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

Hey folks! So, I've been tinkering with a compact PCB featuring an ESP32 S3 Mini, and it's been a blast! This little guy has a USB-C and battery connection, with nifty chips like a charge controller and voltage regulator. I'm diving into mechanical keyboards with some cherry switches, and guess what? I made this cool 'Vibe button' for a single key keyboard! I even used AI to vibe code it, so it sends command-enter when pressed. PCB Way did a stellar job on the assembly, and now I'm setting up the RGB LED for charging status. Let's make coding more vibey!

Related Content
Transcript

So, what have we been up to? Well, I’ve
been making this very compact PCB. It’s
got an ESP32 S3 Mini. Now, we’ve got a
battery connection and we’ve got a USBC
connection. So, this IC here, that’s the
battery charge controller. This one here
is the ESD protection chip. This chip
here is the power switch. So, I’ve moved
away from the fairly classic MOSFET plus
diode and I’ve started using this IC. I
quite like it. The reason I really like
it is because um you can basically put a
lot of capacitance on the other side of
it. So it has a slew rate limiter
circuit. That means when it’s powered
up, it seems like it’s not got much
capacitance to the USBC connector, but
you can put a lot of capacitance on the
other side. So it’s quite handy. And we
also got this um RGB LED. Now this
really tiny IC here is the voltage
regulator. It is absolutely microscopic.
Pretty amazing. So, this is a single key
keyboard. Now, I’ve designed it to take
two different types of cherry switches.
So, this red one is a low profile
version, and this blue one is a standard
height one. Um, so unfortunately or
somewhat annoyingly, these have quite
different footprints. So, the red one
has this very large kind of thing that
goes through the PCB. Blue one has this
quite small um bit of plastic. But I
have managed to get a footprint that
works for both. So I’ve got a blue
version
and I have a red version. Now this is my
first um experiment with um mechanical
keyboards and I have discovered all
about stabilization. So if let’s have a
look at the the red one first, the low
profile. So if we put the key cap onto
this works quite nicely when you push in
the middle. If you push either side,
it’s really not very good. It’s uh not
very stable. And if we try it on the
blue one, you can see we have the same
problem. So, let’s um let’s connect
this. So, it’s less bad, but it’s still
not very nice to use. It’s a bit wobbly.
But what you can do is you add on these
stabilizers. So, these um these black
bits are stabilizers. They clip through
the PCB and this metal rod connects
them. So when you move one, the other
one moves. So if we take our key cap
and stick it onto this.
So now when I push on one side, the
whole button goes down. So there’s no
more wobbliness. It’s actually quite a
nice movement. So it works quite well.
Unfortunately, these stabilizers
don’t quite match up to the red button.
and they’re just too tall. I’ve looked
around to try and find stabilizers for
red versions, but um I can’t seem to
find any. So, any ideas, please put them
in the comments. Now, obviously, it’s
just a plain white button. That’s pretty
boring. So, what I’ve done, I’ve had
these custom buttons made. So, we now
have our Vibe button. So, I’m going to
do a bit of Vibe coding. So, let’s give
it a go. We’ll vibe code up the software
for our Vibe button and see if it works.
So before we get down to some vibe
coding, I just want to do a quick shout
out to PCB Way who manufactured these
PCBs and did the SMD assembly. As
always, it’s a fantastic job. Check out
our link to them in the description. Get
your own PCBs made. Why not? So what is
Vibe coding? What are we even talking
about? Well, it’s the new way of coding
where you don’t even look at the code.
You just let the AI do it. So what I’ve
done here is I’ve set up a platform IO
project. We have the out of the box main
function and I’ve added in this header
file that defines all of our GPIO pins.
Now, you might be saying, “Surely you’re
cheating. Haven’t you just written a
bunch of code in this hardware header
file?” Well, actually, no. I used an AI
to write it for me. So, I tried a few
different ones. Here’s Chat GBT’s
attempt. So, I gave it the net list and
the bomb, and it generated this header
file. It’s actually pretty good. So,
it’s worked out the RGB LED and it’s
active low. It’s got the boot key and
it’s got our key press. So our GPIO pin
is 33 is connected to the cherry key.
Now the only thing it did that was quite
weird is this enable pin. It made up
this GPIO number. So I had to go with
Claude instead. So here’s Claude’s
attempt. It’s also actually really good.
So it’s worked out that we need internal
pull-ups. It’s worked out that the
charging pins are active low. It’s got
the RGB pins. It’s got the how to turn
the LED on. It’s got our button key and
our boot key. Um, so that’s pretty good
as well. It’s even written us some setup
functions and some helper functions. But
in the end, I chose to go with um
Gemini’s approach. So, it’s given me
this nice header file. And I thought I’d
use this one. It’s quite clean. It’s
quite simple. There’s not too much code
in here. It’s just the GPIO pins and the
mappings. So, we’ve gone with that one.
So, let’s actually try and make
something work. So what I’m going to do
is I’ll add in the main file to our
context and then we’ll just tell the AI
what we want to do. So I want to make a
USB keyboard. Uh so we’ll say when the
key is pressed and I want to send
command plus enter. So command enter is
the key combination that actually lets
us do the vibe coding. So let’s send
this off and see what the agent does. So
it’s going off to think.
Okay. what it’s doing. It knows we’re
using platform io. It’s going to have a
look at the platform io.in file and see
what it needs to do. So, it’s worked
out. We’ve got an ESP32S3.
And it’s saying, “Oh, that’s got native
USB hit support. I’ll help you create a
USB keyboard that sends command enter
when your key switch is pressed. So, let
me update your project to implement the
functionality.” So, it’s gone off. It’s
fixing a few things. It doesn’t need
this. It added this library and then
decided actually I don’t need it. you’ve
got native support. So now it’s off
updating the main.cpp. So I’m not even
going to look at the code it writes. I’m
just going to accept everything. So
let’s accept that. Okay. Let’s just
accept everything.
Okay. So it says it’s done. So now I’m
going to check to make sure it actually
compiles. So let’s see if it actually
does compile. Hopefully it will. All
right. Successful compilation. So there
we go. It tells us what it’s done. So,
your USB keyboard features command enter
shortcut. Press your key to send command
enter. Got visual feedback. A blue LED
lights up briefly when you press the
key. It’s got debouncing and it’s got a
status indicator. So, the green LED
flashes briefly on startup to show the
device is ready. So, let’s flash it and
see what happens. Okay, so our device is
all flashed. I have this keyboard tester
here. So, let’s hit the reset button.
Oh, we get the nice green flash to show
we’ve initialized. Let’s see if the
keyboard actually works. So, this
keyboard tester, I can just type. But
now, if I hit our button, we get command
enter being pushed. So, that’s pretty
cool. And you can see we get the little
blue LED flashing when we push the
button. So, that’s quite cool. What I
can see though is it’s only momentarily
pushing command enter. So, let’s fix
that. What we want to happen is when the
key is pressed, command plus enter
should be sent and held only release the
keys when the when the key is released.
See what happens. Okay, so it’s going to
give us a more natural keyboard
experience. Now, what’s quite cool is
because our button is semi- workinging,
we should be able to just hit accept
using our vibe it button. So, let’s try
it. Vibe it. And it works.
So it’s going to check it actually
compiles. So we use our vibe bit button
again. All compiles.
Let’s flash it to our device. So what
have we changed? When you press the key,
command enter is sent and held down.
While you’re holding the key, the keys
remain pressed. And when you release the
key, command entry is released. And the
blue LED should stay on while you’re
holding the key down. So let’s give that
a go. Let’s head over to our keyboard
tester. Let’s just clear the state. And
now let’s do the vibe it button. So
there we go. That’s working. And you can
see the blue LED stays on. And command
enter remains pressed when we press. So
that’s pretty cool. Not bad at all. So
we’re not really taking advantage of our
RGB LED. It’ be quite nice to have that
showing the charging status of the
battery. So let’s tell it um let’s use
the RGB LED to show charging status.
Let’s have red for charging and green
for fully charged key for the blue LED
for the key press indicator. So, let’s
see how it handles this.
So, you can see it knows we’ve got the
charging pins from our hardware
definition. So, it’s going off and
modifying the code.
Okay, let’s use our vibe bit button to
accept everything.
All compiles. Let’s flash the firmware.
So, I can see we still have our blue
functionality, but I don’t see any LEDs
for the red and the green. So, let’s
unplug.
Plug back in.
Ah, there we go. So, we have a red for
charging. So, have our blue LED. Let’s
leave that charging up and see if it
eventually changes green. But meanwhile,
we could add some more functionality.
So, one thing we could do is we could
add Bluetooth support. So, I’d quite
like
to have Bluetooth support as well as
USB. What are my options? Okay, so it’s
saying the ESP32S3
excellent Bluetooth support. Got several
options. Let’s send it off and it will
do a bit of searching to find out what
the best way of doing is. Okay, it’s
gone back with a lot of research. So we
have multiple options and I think I want
USB and B simultaneously. Um it has
picked up this library. Now I believe
this library is actually not that well
maintained and we do have out of the box
B functionality on the ESP32. So what
I’m going to say is I want um dual mode
but avoid any additional libraries. use
the built.
So, let’s tell it to give us dual mode,
but use the built-in B functionality. I
don’t want to pollute my thing with too
many libraries. So, let’s see what it
makes of that. Okay, so it’s going to
use the built-in B functionality. So,
hopefully we should have a dual device
now. One that does both USB and
Bluetooth low energy. Let’s see if this
actually works. Let’s see if it actually
compiles. It’s written a lot of code.
Let’s see what happens. Oh. Oh dear.
compilation errors. Let’s see if it can
fix itself.
Okay, so it’s trying to fix itself.
Let’s see if it succeeded. Let’s run the
command. So far so good. It’s linking. I
do believe it’s actually built. So,
let’s flash this and see what happens.
So, let’s check the USB keyboard still
works. So, that’s still working.
Now, let’s bring up our system settings.
So, let’s see if our system settings
show any keyboards. Now, I’m not seeing
anything obvious here. Searching for
devices. Let’s try um switching off and
on again. Still searching. Nothing yet.
So, do we have any instructions? Has it
told us anything to do?
So, we’ve uploaded.
So, I don’t think it’s pairing. So, plug
into the computer. USB C cable
recognizes keyboard. Works instantly. No
pairing require required.
Um, we’re not seeing any Bluetooth
devices showing up though. I don’t see
any nearby devices. So, let’s tell it.
So, it’s going off to check its
implementation. Let’s see if it can make
it work. Okay. So, it’s made some
changes. Let’s do the upload. All right.
Then, let’s have a look. Oh, Bluetooth
device via keyboard. Let us connect.
Come on. Are you connecting?
I think we’re connected.
Let’s see.
I’ve got it plugged into USB right now.
So, let’s disconnect
our USB connection. I’ve got a battery
connected. Is it going to work? Oh, it
doesn’t work. What a shame. So, let’s
see. Is it actually connecting? I don’t
know if it is. Yeah, it’s not
connecting.
Let’s see if it can troubleshoot it.
Okay, so it’s doing some more stuff.
Let’s um let’s run this. See what
happens. Accept everything.
So, it all compiles.
Let’s flash the device and see if we
finally get something that works. Okay,
so we’re flashed. Going to try a
complete power cycle just to check.
So, we’re on.
Let’s have a look. See if it shows up.
Not seeing anything obvious. Well,
that’s not very promising, is it? We’re
not seeing any Bluetooth devices nearby.
So, we’re not having much joy with the
current code, but let’s give it a
suggestion. Why don’t we give it a
library that I know definitely works?
Why don’t you try this library? Here’s
some sample code.
Okay, let’s send it off to do that. I’m
determined this is going to work. Okay,
so it’s adding the library now. It’s
going to rewrite our code and hopefully
our new code will work. Fortunately, our
USB keyboard’s still working, so I can
use my Vibe key quite nicely. So, let’s
see if this actually works. Let’s flash
the firmware. Okay, so we’re all
flashed. Hit the reset button. Fingers
crossed. Oh, Bluetooth device. Let’s
connect.
Come on. Oh. Oh, we’re connected. We’re
connected. Let’s check the old um
keyboard tester. Where’s my keyboard
tester gone? Got so many windows open.
Ah, key test. So,
that’s with the USB connected. Let’s
disconnect our USB and see if our
Bluetooth works. It works.
We vibecoded our USB and Bluetooth key.
Fantastic. It actually worked quite
well. A few um missteps in the Bluetooth
setup. And I have noticed the LED. If I
plug this back in,
I should be seeing an red LED when it’s
charging. So, let’s just make sure
that’s working. Check that the charging
and blue charged indicator is working.
flashing red for charging, green for
really charged. Right, if this works, we
will stop because I think we’ve got
something quite successful. I’m pretty
pleased with that. We’ve uh vibed up a
completely working um bit of code that
does a USB keyboard and it does a
Bluetooth keyboard. Had to give it a few
hints. So, I had to tell it what library
to use and give it some sample code, but
I’ve not actually looked at any of the
code it’s generated and I’ve not had to
debug any of it or fix any of it. So,
I’m pretty amazed by that. Um, so let’s
uh use our vibe bit key to apply all the
changes. So, just accept that. Okay,
let’s make sure it builds. Okay, so that
built.
Oh, let’s uh we’re running out of
requests. I’m I’m hitting it too hard.
The AI is getting upset. Uh, but it
built. So, let’s um Oh, it’s doing some
more. It’s adding some debugging for us.
Might be useful. Don’t know.
There is one thing with the S3. Uh, when
you’re using USB, the serial thing
doesn’t work out of the box, but um I
think we’ll Yeah, we’ll leave it there.
I could ask it to fix that, but I’m
going to flash the firmware and we’ll
see how well this works. So,
let’s flash the firmware and we’ll see
if our LEDs actually show the right
status. Okay, so let’s reset.
Okay, red flashing LED indicates battery
charging. Um, let’s check that the
keyboard still works. Where’s my
keyboard tester gone? There we go.
Keyboard tester.
Yep. So, the keyboard tester still
works. Let’s unplug. Make sure the USB
uh the BLE connection works. Yes, BLE
connection still works. Amazing. So, I
think we got a pretty fully functional
um bit of kit here. So, not bad. I’m
pretty pleased with that. Not bad at
all.
So, yeah, we vibe coded up a fantastic
bit of kit. Thanks for watching. I will
uh see you in the next


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

atomic14

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