foreign
it's laser time in Dave's Garage and
today I'll show you how to make it
[Music]
hey I'm Dave welcome to my shop this
weekend my mom sent me an ad for a cool
Giga on Facebook that looked kind of
like what you just saw and I saw that I
could write that on a Monday morning she
pretty much called me on that so I very
much had to go ahead and do it now grant
that I use the night driver software
package to do the heavy lifting and
today I'm going to show you exactly how
to build this effect on the cheap and
easy I'll take you through all the steps
from connecting your very first led on
through everything you need to know to
pair night driver with individually
adjustable LED strips in order to build
some truly fun and compelling projects
best of all it's all completely free and
open source it's easy to get started and
from there you can modify customize and
create new effects to your heart's
content
to Briefly summarize the technology and
individually addressable LED strip gives
you complete control over the color and
brightness of each LED on the Strip
unlike a conventional strip where all
the LEDs must be set to the same color
and brightness each one on an
individually adjustable strip can be
controlled independently giving you the
ability to create some very powerful
effects so from here on forward when I
talk about LEDs or LED strips in this
video I'm speaking specifically about
the individually addressable style and
you can find links to any parts I use in
the video description
as a few quick examples here's my patio
umbrella with a strips running night
driver on all eight of the spokes it
runs any effect you can think of from
Flames to dancing lights to solid
ambient colors now in a similar vein we
find the atomic fire lap which is a
simple LED lamp that I grabbed off
Amazon it features four spokes where I
replace the factory white LED strips
with individually addressable strips and
then added night driver to control them
and here's my desktop PC fans running
night driver the code also supports
strips arranged in circles so you can
animate the LEDs radially or in any
direction best of all by the end of this
episode you should be able to build any
of these projects just by changing a
single line in the night driver
configuration without writing any new
code if the chip module that you wind up
using to drive the LEDs features a
microphone night driver also supports
Sound Processing so you can make your
effects sound reactive here's an example
of LED strips arranged into a simple
Matrix to form a music Spectrum analyzer
it also features several interesting
sound reactive effects that track the
music The Sound Processing features beat
detection so you can have elements of
your effect trigger on Every Beat of the
Music making it the ultimate light organ
we're going to use it to launch a laser
shot on every strong beat or loud sound
that we hear
let's take a look at the parts we're
going to use today the first thing we
need of course is an individually
addressable strip what you're looking
for is something compatible with the
ws2812b standard and running at 5 volts
ideally
and again I've put Amazon links for
everything that I'm using here in the
video description so you can find them
easily I've selected this strip from BTF
lighting and they've earned my loyalty
over the years by making a reliable
product at a good price they even offer
to sponsor this episode but I said nah
to keep things independent but I'm still
happy to recommend them the next thing
we need and in fact other than a few
connectors the only other thing we
require is an esp32 chip module to
control the LEDs now the difference
between a bare esp32 chip and what's
known as a module is that the module has
a power supply serial Port an LCD
display a battery accelerometer
microphone and various other peripherals
all built in
they're cheap and easy to find on Amazon
and as little as three dollars if you
really want to hunt around on AliExpress
and wait on the international shipping
for this project I'm going to use a
module known as the m56c plus the esp32
inside has a dual core CPU Wi-Fi
Bluetooth and it runs at a fairly fast
240 megahertz so it's not your grandpa's
Arduino
this module also includes a number of
extra features like a microphone a color
LCD display infrared remote control
transmitter a six position accelerometer
and so on but since we need a microphone
on our project it's a good choice it
comes in at around 35 dollars but I
think it's worth it given all the extra
features particularly if you're just
getting started you'll use it over and
over as you learn new things
let's have a look at how the module
communicates with the strip it's going
to prepare and send a square wave signal
that contains little batches of three
bytes each those packets contain the
color data encoded in 24 bit RGB one for
each LED in between frames there'll be a
gap of at least six milliseconds and
that signals the start of a new frame
now there's no configuration or setup to
be made between the chip and the module
the chip just sends as many packets as
you wish and if you have more color
values then you have LEDs they simply
spill off the end harmlessly and if you
have too few your colors won't reach the
end of the strip and that's it now
fortunately we don't need to know
anything about this as the software side
is all handled by Night driver and the
hardware we need is self-contained in
the module you'll simply install the
code on the module and then it connects
it to the strip and then the magic
happens
but before any real magic can happen
though we need to set up our Hardware
the good news is that there's only three
wires power ground and a signal that's
all we need to get started the first
thing we need to do is supply power to
the strip the M5 module itself can be
powered off USB or whether USBC adapter
and we'll use a small power brick to run
the strip
now in theory you could Supply the whole
thing off the USB power but once you get
past about a dozen or so LEDs you're
asking for more power than the port can
normally Supply so it's just good
practice to power the strip
independently to do that I'm going to
connect a female Barrel jack adapter to
the red and white lines of the strip
which are power and ground respectively
then I can simply plug the strip into a
power brick of matching voltage nothing
will happen yet when we apply power
because without any data the LEDs all
default to the off State
now strips normally come in three
primary flavors 5 volt 12 volts or 24
volts it doesn't matter which one you
have as long as your power brick outputs
the correct matching voltage and that
the ground but not the power is shared
between the module and the strip and so
let's connect the module there are two
ways that you can connect the M5 module
to the strip either way you'll need a
connector the simplest way I figure is
to grab what's commonly known as a
Groveport connector which has four wires
coming out it supplies a connection for
the ground signal the power signal which
we'll ignore and two signal lines of
which we need only one and so the force
has four pins of which we're going to
connect only two you'll leave the
modules red power wire and the second
data wire unconnected as they're not
needed for this project and can cause
problems if you do connect them at the
other end the M5 module also has a
standard female header connector that
exposes eight of the Chip's lines
including ground power out power in
battery and then three signal lines if
you prefer you could just use an 8-pin
header and connect the ground and the
line labeled as g26 if you do go this
this way you'll need to change a single
line in the configuration to change the
output pin and I'll show you that when
we get to the code
the final connection is from the module
to the strip the power lead from the
strip is not connected to the module so
leave both red wires unconnected this is
especially important if your strip
voltage is anything other than 5 volts
that the module is expecting
regardless the ground must be shared
between the strip and the module as the
signal line requires a ground reference
that both can see we then connect that
one signal line which is green in most
cases and we're done on the hardware
side
with the hardware all set up what we
need to do next is to load the night
driver software now this is simple but
it requires a couple of prerequisite
tools first you'll need to install git
if you don't already have it I've put a
link to that in the video description
once git is installed you execute a
single command line to copy down the
code
that will copy all of the code into a
new subfolder called night driver strip
next we need platform i o which is going
to be our build IDE and it will compile
and upload the code to the module for us
now there are plenty of videos on how to
install platform i o including one I
made a year or so ago and links are
again in the video description it's an
extension to visual studio code so start
by installing vs code and then adding
the platform i o extension and you're
ready to go there are only two lines
that we need to worry about in this
entire project and that's the default
environment which tells that which of
the many night driver strip
configurations to use and which serial
port to upload on if you're using the M5
you can simply make sure the default
environment line is set to laser line as
shown here finally we need to tell
platform i o which Port which serial
Port the module is connected to plug it
in and use device manager windows or the
devices tab in platform i o to find the
name of your Port if you only have a
single port you can actually leave this
blank and platform i o should find it
for you but to be safe find the section
of the platform i o dot any file labeled
as laser line and then change the upload
port in the serial port to be whatever
you discovered it to be like com3 with
that we're ready to build and upload the
code to the module to do so we press F1
to bring up the command pal and then
select platform i o upload it should
chew away for a minute then then look
for the module on the port and upload
the code if it fails double check your
serial Port as the likely culprit the
code will always compile and work right
out of the git repo as is
with that the code will run as soon as
it uploads and reboots now if you're
using the M5 you'll get a simple little
screen on the LCD with some stats about
the running project and it'll be ready
to generate your laser effects I'm using
two 300 LED strips chained together to
get some links for the demo but it
should work equally well with whatever
length of strip you have let's have
another look
now remember the chip itself won't make
any sound that sound you're hearing is
just an effect I downloaded from the
internet and I'm playing it over the
shop speakers from my PC the board will
react with any significant change in
sound level so you can clap your hands
or say pew pew or whatever you like to
trigger the LEDs if it doesn't work
check that your strip has approximately
the right voltage at its tail end in
order to confirm that it's being powered
properly verify that the data line is
connected and that the ground is shared
between the strip and the module
if you're using the Grove connector on
the M5 the pins will match the default
configuration everything should work
right away
if you're using the header connector
it's a different output pin so we need
to change one more line in platform i o
dot any if that is the case find the
section called laser line where your
serial config was also listed and change
the line that reads LED pin 0 equals 26
to whatever gpio you've connected the
data line to then rebuild and re-upload
the code and you should be ready to go
there are dozens of project
configurations listed in the any file
and while building for other modules is
the topic for another day you can build
any of the projects that make reference
to the m56c plus and they should work
right out of the box writing your own
effects from scratch is also be on the
scope of today's video so make sure you
subscribe to the channel if you want to
see more projects in detail for now
let's look at the only effect we'll be
running which is the laser line effect
this effect is defined down and include
effects strip laserline.h our laser line
effect simply derives from two base
classes beat effect base 2 and LED strip
effect the former provides the sound
integration so that the microphone can
actually hear things and later provides
us with a canvas on which we can draw to
our LEDs
the init function makes a record of the
gfx pointer which is the pointer we need
to call functions like setpixel to
actually do our drawing it then calls
the Base Class a knit function to do
whatever basic setup the effects require
and that's all handled for you we only
need to provide two functions draw which
does the obvious and a function callback
name handle beat this function is called
by Night driver whenever a beat occurs
in the audio up in our Constructor we
passed two values to the beat effect
base 2 class the threshold from zero to
two on how loud that beat must be which
we set to 1.5 and a minimum duration
that has to occur between beats to
ensure we don't miss rapid fire sound
effects I'm setting that to zero meaning
no delay needs to be found in between
the shots as long as the volume exceeds
at 1.5 threshold
when it does you can see that we have a
vector or array of shots we create a new
one and push it onto the array and
that's all we need to do in a handle
audio case
our draw call must first call Process
audio as that's what does the fast
Fourier transform that actually analyzes
the incoming sound for you next we fade
the entire strip out by some amount you
can specify a value from 0 to 255 and
the LEDs will be dimmed by that amount
every frame I found that a good value
for this project is 200 and it gave a
pleasing trail behind the shot
we then walk the array of shot objects
and call each of their draw methods
which we'll look at in just a moment
next we call its update function which
will move the shot and return a value of
false when the shot has gone off the end
of the strip when that happens we erase
the shot from the list
that way our array can hold any number
of active shots but they expire as soon
as they hit the end of the strip and
then clean themselves up automatically
this mysterious shot object is just a
small class right above the effect
itself and it simply tracks the shots
position speed and color
it only has two methods update and draw
the update function is responsible for
moving the position of the shot it
receives a value indicating the
fractional number of seconds that have
elapsed since the last draw and so the
speed of the shot is the same regardless
of the number of frames per second that
are being rendered as noted if the shot
reaches the end of the strip the
function returns false to advise the
collar that has gone off the end
otherwise it returns positive to
indicate that it's still alive and
active the draw function simply walks
the pixels beginning with the start
position and finishing after the number
of pixels corresponding to the shot's
size have been drawn we calculate the
color of the shot using a chsv class for
Hue saturation and Vibrance which allows
us to specify a hue from 0 to 255
indicating the base color and then we
fully saturate it and show it at maximum
intensity and that's all it takes to
render an effect via night driver night
driver also supports remote drawing
complete with buffering to smooth out
the Wi-Fi of any dropouts So in theory
once you have it running you can render
and control everything you see directly
from your desktop but that's a more
advanced top topic you can even render
an effect using your GPU and then send
it to the strip over Wi-Fi for today
we've done everything without writing a
single line of code but the code's all
on GitHub for The Adventurous or those
who want to contribute now we're
especially looking for somebody to
contribute to the UI side of things
using react it's an interesting project
and that everything runs out of the
flash ROM on the chip itself and the web
server is hosted on the esp32 chip as
well via the built-in Wi-Fi if you're a
react expert please stop on by the
GitHub repo in the video description and
lend a hand
if you have any interest in matters
related to autism Asperger's or ASD
please check out my book on Amazon
secrets to the autistic millionaire it's
got nothing to do with money and
everything to do with living a
successful life on the Spectrum it's
everything I know now that I wish I'd
known back then
remember I'm mostly in this for the subs
and likes so please be sure to leave me
one of each before you go today in the
meantime and in between time hope to see
you next time right here in Dave's
Garage
[Music]