Now here's a little interesting Electronics
gadget for a tinkerers and the Arduino people
out there.
Well, what we have today is an 8x8 LED matrix.
The way in which it works is extremely interesting
and I've been having a lot of fun with it
just on basis of how it works, so today let's
delve into it.
Let's actually try to understand better what's
going on with this particular piece of kit.
Now in this video we will be delving into
a little bit of physics and math, we'll be
doing a little bit of Ohm's law calculations.
Don't be too alarmed by that right, hopefully
it will all make sense if you like to find
out more about this I have also written a
companion blog post, so the pop open the video
description you'll find a link to that.
We'll have little code snippets as well as
even perhaps some downloads that you can take
a look at.
So with that said, let us jump in to this
random Wednesday episode.
Hello and welcome back to another random Wednesday
episode.
So today we're going to be talking about the
8x8 LED matrix.
In fact we have so much to say about it that
we are probably not going to fit it all in
one video, so yeah be prepared to get another
video in maybe two or three weeks time - We
will go a little bit deeper into this particular
component
As mentioned this particular component is
interesting because of how it operates.
Let's take a look at what that means - So
of course the question is how do we actually
power 64 LEDs with just 16 pins.
As it turns out it's actually quite ingenious
and, you know, in order to properly understand
this we're going to have to actually delve
into the innards of, well, the LED matrix
itself.
Now, basically these LEDs are connected together
using a grid of wires, so exactly like this
right they're split into rows and columns
so yeah what you can then do is you can set
one of the rows to a high state, in other
words it's actually receiving power.
Then you can set one of the columns to low
state, in other words going to ground of course
through a resistor, but we'll talk about a
resistor stuff later on.
The idea is once you have a row and column
connector like this, one of the LEDs will
light up and well the reason for this is you've
basically created a complete path for a current
to flow.
So yeah what this means is you can basically
address any pixel by just appropriately powering
its corresponding row and column.
Now one thing that may not be quite as intuitive
is in the fact that, well, the pins are not
actually "in order".
So what you're looking for here is the top
of the LED matrix which has the name of the
part, and what you'll find is well the eight
pins on top as well as the eight pins at the
bottom.
And yeah basically these are rows and columns
they correspond to - They're kind of all over
the place so yeah, I guess this is probably
the only thing that is a little bit not as
optimal.
Of course this isn't a problem!
As long as you know what to connect up, things
will still work correctly.
Now interestingly, there is another challenge
and that would basically come about when we
try to draw a figure like this one.
Now at face value this seems quite simple
right?
All I have to do is of course to power up
the first row, send the relevant columns to
low and then well those LEDs will light up,
right?
Repeat that for the next two rows and yeah,
very nicely the correct LEDs light up without
needing us to set any other columns.
The problem comes about with the next part.
Now what if I wanted to set up these two pixels
which are sort of the edges of the smile.
Of course I will need to power up this row
but once we do that a problem becomes very
apparent because these two columns have already
been set to low.
The moment I switch on this row these two
are going to light up and there's nothing
I can do about that.
I can't switch these off without also affecting
the guys on top.
Similarly if I were to actually try and switch
on the pixels here you realize that once I
set these two lines to low, well extra pixels
at the top light up as well, and I don't want
that.
So I think you can see why there is a problem
here, but how do we actually solve it?
As it turns out this is kind of non-trivial!
In order to solve this we are going to have
to implement quite a bit more logic that brings
this beyond a purely electrical thing, to
something in which some computational power
is required.
The method we're going to be using is called
scanning, and let's start with everything
off again.
What we're going to do is we're going to switch
on just the first line.
Clearly no pixels belong here so we make sure
that, you know, we don't set any of the columns
to low.
We switch off our first row and proceed to
our second one.
Now we need to switch on these two pixels
so we set these two lines to low.
Scanning to our next line again, well we keep
the same two columns to low, and that gives
us our two pixels here.
I think you get the idea for the next row,
we do exactly the same.
Next row, nothing to see here so none of the
columns are set to low.
Then we go on to our next line now we can
simply draw these two without, you know, any
other interference because at this point of
time, only these two lines are set to low.
Going to our final line, now we have to light
up four pixels so now four of the lines are
set to low.
Finally our last row is empty so we don't
do anything and that is basically it for one
scan.
So if we were to actually step through this
a little bit quicker you will see that we
are basically drawing out that smiley face.
And what this means is in order to display
that particular image on screen, you're going
to actually have to scroll through and scan
all these lines really quickly.
In fact what you're seeing here is an example
of that in action.
I've also hooked up this to a little potentiometer
so what that means is as I turn that little
knob you'll find that I'm actually changing
up the scanning speed, and when things get
slower, well you can actually see that pattern
of all the pixels being scanned.
All right so earlier on we mentioned resistors,
something I didn't get into, you know, the
details about but well now let's look at it!
Let's say we have an LED if you were to connect
it directly to power what you will get is
a little mini explosion!
Well not really but you will fry the LED.
The LED will draw a large amount of current
in a fleeting moment and then basically burn,
and well becomes unusable.
So we don't want that!
We want to actually restrict the amount of
current that can actually go through the LED
and in order to do that we add a resistor
to the mix.
The reason why this works is because in a
series circuit the voltage is basically distributed
across the components, that is we start at
say 5 volts and a voltage drops until when
it goes back to ground it should be zero volts.
However the current stays constant across
all the components we have connected, and
therefore if you have something that can limit
the current here, you are also limiting the
current going towards the LED.
Usually a 220 ohm resistor is used and in
order to figure out what effect that has on
a circuit, we make use of Ohm's law.
So let's do a very quick little sample calculation
here.
Assuming that the potential difference across
the entire circuit is 5 volts which is incidentally
what the Arduino puts out, we also assume
that the LED has a voltage drop of 2 volts
- This really depends on the LED as well as
its color so we're just going to use a very
average value here.
Now since we know this and we know that voltage
is distributed, the voltage across the resistor
must be 3 volts.
So this is where Ohm's law comes into the
picture here - We know the voltage, we know
the resistance, we plug it in, we rearrange
our equation so that we can find out the currents
that is flowing through the entire thing,
and this gives us about 13 milliamps.
So is this a good number?
Well again it depends on the LED itself but
generally an LED can take up to 20 maybe 30
milliamps, and what that means is well this
is a very good fair amount.
Of course if your resistor has a lower resistance
then well we can get more current with the
LED it will glow brighter, but 220 ohm is
a very common resistor and as a result this
tends to be used a lot of the time.
So why did we discuss all of this?
Well going back to our LED matrix we clearly
have to do the same, otherwise we will fry
an entire row of LEDs in our matrix, and we
don't want to do that.
Now at first glance it seems to be that we
can connect the resistor along the rows or
along the columns and it doesn't really matter.
Well as it turns out there is a little consideration
you have to take note of - Let's say we have
our supply going through a resistor and to
our LEDs, and then our LEDs go to ground and
as a result they all switch on.
That is of course fine right, it's completely
okay because well we have a resistor nothing
is going to cook itself.
However there is one problem - let's rearrange
this circuit into a slightly easier to understand
form.
Basically we're creating a whole bunch of
LEDs in parallel and we have a single resistor
that just limiting the current to all of these
LEDs.
However because this is a set of parallel
circuits now, the voltage across this stays
constant, but the current is actually distributed
across each branch.
What this means is your LEDs aren't getting
0 a healthy 13 milliamps each.
Assuming that our resistor is still a 220
ohm resistor putting out 13.6 milliamps, well
what this means is our LEDs aren't actually
getting this healthy amount per led.
Instead that amount is actually going to supply
this entire stack, distributed among each
LED.
What this means is each LED is only taking
well slightly less than 2 milliamps each.
Your LEDs may still light up, that may still
be enough to kind of get it going but that
is going to be very little, and each LED is
going to be very dim at best, so we don't
want to do that.
We want to actually connect our resistors
to the other side.
In fact the important thing is that if we
are scanning along the rows, then we want
to connect our resistors to the columns.
The reason for this is well even if we have
to search on every single LED, notice that
we are creating a complete path in which every
path has its own resistor.
At no point of time are we powering more than
one LED using the same resistor.
In other words these circuitry now looks something
like this - In every little one of these parallel
branches we have our own resistor, so the
voltage drop across this entire part in the
middle is 5 volts, and for every LED that
needs to be switched on, well it's getting
the amount of current it needs, since the
resistor is only actually in a sort of localized
manner.
What this means that is if this current is
actually coming from your Arduino, well the
more LEDs need to be switched on, the more
current is going to supply.
Because we are now able to set up vary the
amount of total current that's coming out,
each LED can get the amount of current it
needs to operate at, well a fair brightness.
This basically wraps it up for the basics
of the 8x8 LED.
Of course there is still one little problem
- And that is a crazy number of pins are required
to drive the display!
I used an Arduino Nano earlier on and that
certainly doesn't have the 16 pins needed
for this.
So the question is - Is there a way to reduce
on the number of pits required?
And there you have it!
Do think about that last question - How can
we economize on the amount of pins that we
are actually using here, and to what extent
can we do that?
The only hint that I'm going to give you regarding
this is that, well we've actually already
taken a look at this before.
It's just that next time when we actually
return to the subject we will apply that in
a slightly different way.
That's all there is for this particular episode
thank you very much for watching and until
next time you're watching 0612TV with NERDfirst.net
