In this lecture, I'll show you how to control these simple five volt DC motor using the the RV eight
eight seven one to break out.
The particular one that I'm using here is from the fruit.
It's actually a really good and small package, actually, to control motors like this one.
Before we get started with the actual demonstration, I just wanted to talk a little bit about this
module.
Now, the first thing to notice is that in order for the motor to operate, you need to provide at least
six point five votes of power to this power as crude terminals.
From here, I have connected mine to my benchtop power supply and I'm connected on in a moment.
If you provide anything less than six and a half volts, your motor is not going to work at all.
The other thing to notice that is important is that this device is able to take instructions, basically
work with logic levels up to five point five volts.
So it's going to work well, both with your UNO, which operates at five volts logic level and with
the SB 32, which operates at three point three.
So really, you can take it from one project to the other and just use it without having to worry about
the logic level of each device.
OK, now part of that, I'm going to show you what the wirings and then have a look at the software.
So first of all, in this row of pins down here at the bottom with conchi and connected to the ground,
of course, so that there is a common ground between my external benchtop power supply and the ability
two, then for VM, I haven't connected it.
That is the the power voltage for the logic circuit.
But I've opted to just power the V eight eight seven one from the power supply.
So I'm leaving the room and connected and I've got in one and into in one in to allow you to control
the direction of the spin of the rotor of the motor and its speed, the way that have configured it
here, using in one to control the direction and that is connected to Tapio 21 and into I'm using it
to control the speed of the rotor and that is connected to Tiberio two on my PSP thirty two.
And finally I've got my motor connected to the motor scooter and if it does really matter which way
you connect the wires, it's a symmetrical device.
All right.
Now let's have a look at the software side.
There's no particular library that you need to install in order to control this motor or when it really
is pinned.
And and I've also imported the sleep module so can add a bit of delay in between speed settings then.
I am creating that in one and in two objects.
So in one, again, it's just a simple G.P.A. pin object used to control the direction.
So I'm simply turning to Peio twenty one on and off and then control it.
Which way the rotor is going to spin.
And then I'm using GWM signals on Tapio two to control the speed.
Now the speed with it's fast or slow depends on the direction of travel of the rotor.
So I'll explain the frequency here.
Default is one thousand but of five hundred hertz frequency work with my motor and again you can experimentally
try different settings to see which ones work best in the case of your motor.
Then we go into an infinite loop and I've got two things happening here.
First, I am sending different settings to the motor so that I change its speed.
And notice, for example, that when I am moving the motor in one particular direction by turning in
one two on, then M0 is its fastest setting and the other extend the M one thousand and twenty three
is when the motor is actually stopped.
But the exact opposite is happening in reverse.
So when I turn the in one typical of and that causes the rotor to shift its direction to the other direction
in the opposite direction, then a high number of m the.
Value for the duty cycle will cause the Rotha to spin fast where it was slow in the previous direction,
the opposite direction, and then as the values drop towards zero, the speed of the rotor stops as
well, where zero in the opposite direction is the fastest setting.
So we just need to keep in mind that the speed and value and speed have to do with the direction of
travel of the road.
So these numbers need to be taken into conjunction with the direction of the rotation and no go together.
All right, let's do a demonstration.
So I'm going to turn on my power supply.
I've said the voltage to six and a half volts, which is the minimum that the Davíð eight eight seven
one will work with.
I've got a maximum of two ends and will tend the power supply on.
All right.
And can you start the script?
So moving one direction, let's call that forward and then moving the other direction.
Let's call that reverse.
And I can control the speed each time from high to low, just passing the appropriate value for that
direction of travel of the rotor.
OK, we'll stop that here.
Just remember that it is possible to use the chill here in order to figure out what the numbers are
before you commit them into your sketch.
So I'll just give you a quick demonstration.
Let's say that we've got these two Io's in one and two to go for the default frequency, which is 1000
hertz.
And let's say that in one is on so called the road of travelling in that direction.
That seems to be clockwise, let's call it clockwise, for I change duty cycle to zero.
Is its maximum speed and scope for 1023.
That stops I for a change in one two of.
I can see that now it's spinning at the maximum speed, but in the opposite direction for them, go
for two cycles zero.
In this direction.
The rotor stops, whereas in the previous direction, he was at maximum speed, so that's how you can
just empirically and easily figure out which speed he is setting and direction works best for the situation.