HI, welcome to ESP32 tutorials from Robojax. my name is Ahmad Shamshiri. I am
presenting this tutorial from Canada. in this tutorial we are going to learn how
we can control up to 32 servo motors using ESP 32 without Wi-Fi just directly
connecting it as a microcontroller. you can get the code for this by clicking at
the link below the video in the description which will take you to
www..Robojax.com/learn/arduino
let's get started with this
I have three version of this video for PCA9685 16 channel Pulse Width Modulation
controller that can control LED lights or a servo. I've used it for servo I have
first version version 1 V1 which you can control 16 servo motors I've posted that
and then because of a lot of requests and different type of control
I created version 2 V2 where you can control motors in different way all
motors together or few of them or a different methods the link for those
will be below this video as well I've created video version 3 V3 where 32 servo
motors were controlled using Arduino Uno. and now I'm going to show you how you
can control this 32 servo motors using esp 32 Wi-Fi bluetooth microcontroller
this will act exactly the same as Arduino Uno except we have to
demonstrate that everything works this demonstration and code is preparation
for using Wi-Fi and Bluetooth to control 16 or 32 servo motors if you're planning
to use that please watch this because on the next step I'm not going to explain
everything I will just jump directly to the portion where you can control it via
Wi-Fi or in the next video via bluetooth. to make this video short I'm not going
to explain the module that all the input and output I'm not going to go through
datasheet and other explanation that I did in the version 1 and version 2 of this
video so please watch this video the link is below this video or just type PC
a 9 6 8 5 in the search bar of my channel in the version 3 I've explained
how to prepare 2 of this module connect them together and then prepare as you
can see I've numbered them here from 0 1 2 3 up to 15 on this side these all of
these are connected to the module number 1 and then for the
module 2 it starts on 16 17 18 up to 31 because
start from zero so we don't have 32 so 32 servo 16 is being
controlled by one module and 16 by the other module. and for the wiring we have
only three wires two for ESP 32 to get signal from the module and one ground so
from these we will have only three wires connected to ESP 32 and then I have
external power connected to power all these models and in total its 1.7 ampere
current for this tiny motor is needed so your power source must be 5 volts 2
ampere and higher in order to be able to supply the current for all of these if
you're using different motors and if you are applying a connecting load that
these motors will control the load then the amount of current will significantly
increase and make sure you have enough power for this otherwise it will the
voltage will drop and system were shut off and we start at the middle of
operation
Wiring Explained
I have explained the wiring in video V3. Please watch that video. The link is below this video.
you
let me explain the wiring for ESP 32. because the rest of the wiring have been
explained and when I did the video for Arduino I've connected my power supply
this 5 volts external power supply when all of these are activated you will need
1.8 amp ere with these tiny servos so the positive is connected to the first
wire on this side the white and the black is the negative negative is
connected on this side on the left side the last one here is that the same as V
Plus and this is he is the pin that you need 5 volts for this module now
external power is connected to get power connect a dupont wire like this so we
will supply 5 volts from this module from the servo section to the module
very important.
now this module have power as you can see that light is on. and then I have had
one black wire connected that to the last pin to the ground and connected to
a ground pin of ESP 32 wherever you have doesn't matter which module you have
there we'll have multiple GND or grounds just find it and connect. it now
I'm connecting these two green all will be connecting it to SDA and blue to SCL
and SDA SCL are accordingly from the right the this is SCL the third and the
fourth . will be connected to 21 and this will be connected to 22 on this
module I have 21 and 22 accordingly I
will insert them. if you have different board that it says g21 g 22 then source
like this we have G 21 and then we have the RX and then TX and g 22 but in this
module that I'm using, they are labeled of 21 and 22 without G they are side by
side
Code Explained
Preparing Arduino IDE to work with ESP32 if you didn't understand this, watch my other video
in order to start using esp 32 with arduino ide you need to prepare arduino
IDE for this purpose Click on File->preference-> you will copy and paste here you see this package ES32
index.JSON at the end so once you pasted here click OK click OK this
is telling arduino ide where to get the board driver click on tools and then
Boards-> Board Manager and here wait for this to complete at the bottom this
bar graph and then type here ESP 32 you see EFP 32 by Espress systems
this is installed in your case it will not be insulted you will have install
button here click on it and it will take maybe few seconds for a minute
and the solution once is completed click close. now we have to tell arduino ide
which board you are working with because the driver is ready click on Tool ->Ports
this is Arduino IDE which you will usually work but scroll down until
you see a line below that all of these are ESP2, ESP32 Wrover module is the
one that you click and select and that dot will appear. now we have to select
the port for that we have to find out which port we are using very click on
the Start menu device manager and you see port click on this arrow to collapse
it and mine is using comport silicon lab if I disconnect it now you will see that
it will disappear connecting it back so this has COM6
note that click on tool port and you will see COM6 is already selected and
now you can write your program and run it.
Now your Arduini IDE is ready to work with ESP32
To ensure that the wiring is done properly we have to upload this I2C
scanner I provide you the code. I'm not going to explain it just copy and paste
it in a new sketch like this and then upload it, I've already uploaded. it once
he uploaded I've selected the same board Wroover32 the port is already selected so
it is selected now if I open the serial monitor this is how it shows
device found it will find two devices because two have been connected here and
address is 0 X 40 and 0 X 41 these are determined by the soldering
had a way I have soldered it so it shows the correct address. now let me explain
the code this is exact code that I've used for Arduino you need to download
this library will provide you the link once you download it as a zip file
save it as a zip file and then click on Sketch->Include
library->Add .zip library and then pointed to where you are saved. and I'm
was saved and the Downloads pointed to that and select it
and click open once that is done this line means that
class is included with this line and then for each board we are creating an
instance of the class an object and we call it board1, board2 and for each we
will set a an address so we are starting address with 40 and there 41 I've fully
explained that 40th for board1 0x40 and 0x41 this is the hex value for
board2 and throughout the code will be referring to board1 and board2 here.
define servoMin, ServoMax these are the value that our servo is
responding to the minimum pulse width and i've determined this by experiment i
have linked watched a video version 1 (V1) i've shown how to achieve it. and here
this is just a variable that is keeping the servo number inside the code and we
are initializing the serial monitor and this is just print a text the
make it 32 and then board1.begin() you must do board1.being and board2.begin()
begin and also you must set board1.setPWMFreq(60) and board2.setPWMFreq(60)
60Hz and also for two these are done inside the setup and after that
inside the loop I have created one for loop if I delete this you will know that
this is one for loop that goes from zero to hundred and eighty with the increment
of ten so this goes from zero to hundred and eighty degrees where angle is
changing and as long as angle is under 181 the angle will be 0 10 20 40 60 so
every time it goes 10 up 180 and then I have this loop this for loop "i" is 0 up
to 16 here because 16 is on one board and 16 on the other board so these two
boards were controlling them together with a board1.setPWM and then I
this "i" is referring to the board which servo on the board because the "i"
becomes 0 and then it increments and then 1 2 3 up to 15 so 0 to 15 this "i"
will change this do not change i. and here angleToPulse is a function that I
will explain it's at the bottom of the code and we pass this angle which is
between 0 to 180 so this board and this servo will move to this angle and on
board 1 also we moves the servo whichever is 0 or 1 or 2 up to 15 will
move so this code will move at the same time the servo with the same number on
both one and the same number on board to 2 suggested just for demonstration you
can remove this and use it in your code whatever we want for example if you want
to control servos 7 just type 6 and if you want to send it to 120 degree just
120 or use a variable to control it and then we give it hundred millisecond and
the loop will continuously take the same action.
now angleToPulse is a function that I have created it here it takes the number
and it Maps it that number which is between zero two hundred and eighty and
it Maps it to serve a minimum serve a maximum which I've determined
experimentally here so it will map it and the result is a pulse which fits
between these two values and then this is also printing it on the screen and it
returns the pulse the calculated value which will go here
Demonstration
and here I'm testing it now without Wi-Fi making sure that it works the
power is now disconnected that
everything works fine I'm now demonstrating it without Wi-Fi just
directly as a regular Arduino type microcontroller that as you can see
alter the to or functioning and responding the next step would be to go
and test that over Wi-Fi and we can control each
I would like to thank my Patrons from Patreon.com
Subtitle Typed and corrected by Ahmad Shamshiri on May 18, 2020 in Ajax, Ontario, Canada
I did my part so you can learn. now it is your time to help me.
Simple thumb up 👍 the video, subscribe to my channel and type simple "thank you " in the comment section.
I have paypal account where you donate money. PayPal account link is below this video.
thanks for watching. This was how to control 32 servo motors using ESP32
without Wi-Fi directly wired if you learned something and found this useful
thumb up 👍 as this will help my video in the search algorithm. if have any
have comment or question posted at the comment section below I try to answer
and reply if you want to get updates of my upcoming videos make sure to
subscribe.
<> now in order to make sure that this works with Wi-Fi before that I
<>uploaded the code without do I find making sure that I have no issue with
controlling these servos but you can see what ESP 32 now this is running and
connected