in this video we are going to learn how to use this m5 stack core 2 esp-32 development module
with vl53l0x laser distance sensor to measure distance and display it on the screen
either a centimeter or switch two millimeter put it at around three
I’ve also implemented here the power off with this push button
when you touch it says it will be shut down and turn it on with power.
Hi, welcome to esp32 tutorial from Robojax my name is Ahmad Shamshiri. I you can get the datasheet
and other files related to this click by clicking the link below the video in the description which
will take you to robojax.com/learn/arduino let's get started with this
a separate video explaining this module fully the link for that
is below the video in the description after this video explaining this
vl53 l0x we're going to use it with this m5 stack core 2 esp32 module it does have vcc ground
scl and sda scl is the clock sda is the data pin we're using it with this module and the
feature that I’ve implemented is that we will measure the distance in centimeter or millimeter
and selected with these two touch buttons and also the third one I use it for power so when you touch
it the device will shut down in three seconds and will tell you that power button to turn it on
and here is the wiring for this I used only four wires do not worry about this this is extra wire
that I have not used it in this tutorial we have vcc have been connected here on the second wire
on the right side it has been labeled clearly the first one is battery so this is for the row
on this side and this column is for the column on the right side so this is on the second pen this
orange and then we have ground ground is connected to one of these three grounds on the left side
first second and third on the left side is ground then we have SCL and SDA. I’ve been connected here
using this blue and green wire to the sixth row and if you see here g32 and g33 these are sda and
scl these are for external for devices that you use because we have also sda and scl for internal
and this is if you count it one two three four five that's the sixth one and I’ve connected them
at six one if you count the right side this is scl green is connected to SCL on the right side and
this blue is SDA and if they have been connected on the left side on the sixth row
first we have to install the driver for m5 core 2 click on file preferences and in this
area click here provide you the link this is the link paste it here if you have other stuff
just go to the last line and press enter and paste it here once you're done click ok and click ok
this will tell the system where to get the drivers ever by clicking at tools board manager
boards and then board manager wait for this bar graph to complete
this area type m5 stack and here m5 stack
and install it mine shows remove for you it will be installed once you're done then click
close after that install libraries by clicking the tools manage libraries
wait for this to complete type m5 cool 2
and here you will see m5 core two it says installed
in your case you will see install button and install it
after that we need to install the vl53l0x library from palolo again go to tools manage libraries
and then type vl53r0x after this bar graph completes and stops
vl 53 l0x
so you will see this scroll down until you see
vl5300x by palolo and install it
wait for the bar graph to complete
and close it
make sure to subscribe so you get updates of my upcoming videos
so this was part of the library for m5 core 2. this is wire for I square c communication this
is for the vl53l0x time of flight sensor library which we just installed from the class of library
we create an instance we call it sensor and these are the variables that I have defined maximum
distance this is not used but it can be used so you can ignore certain distances 800 that's four
millimeter and then the type here we define one four millimeter two four centimeter and three
four inch so type the type that you want one two or three and these are the text that is displayed
on the screen here this centimeter and if I press it millimeter these are coming from here
so if you want to change it to something else but keep the quotation put whatever you want inside it
and these are two variables centimeter an inch are being stored in this variable and this float type
so they're being used and distance is the millimeter in terms of uh unsigned integer
this is a prototype which is at the bottom of the code which I’m going to explain it later
inside the setup m5 begin is initializing the module this is creating a full screen black with
black background and this is setting set color for the text yellow and then this is setting the text
size five and then wire dot beginners for I square c communication this is just printing the text on
the screen this is just setting the baud rate for the screen so we can read this line sensor dot
initiate this is initializing the sensor this is setting the timeout if there is some issue
within 500 milliseconds it will time out and this is sensor stored continuous is
initializing the continuous sensor reading and we wait for one second and setup is ending here
inside the loop every time it goes we have to create a click clear the screen and
that's why we are filling up the screen with black background. setting cursor at 0 0 x 0 and
y 0 and pretty printing this word called distance this text sensor dot read continuous limiter and
the result of this is stored in this variable called distance which is at the top of the code
so this will hold it in millimeter now we check if the type is equal three then it is inch so
we set the cursor at 0 60 before for the text was at 0 0 and this is at 0 60 the reason the
reason for that is this is a 60 pixel from the top if you count it comes at this point
so we set it and then we get the distance multiplied by this value convert it to float
and this will give us inch so we call it distance I n inch which is at the top of the code this will
hold an inch the value and then here we get that inch value and here we are formatting it
with four decimal place of type float this means the type is float and we want four decimal place
an inch so just use printf pay attention this is just print and this is printf when you have f then
you can do here formatting for the value and here at the end we print unit type whatever is the type
if it is three minus one would be two it goes gets the millimeter inch or centimeter and prints it
at the end if it is number two then we divided by 10 which makes a centimeter store it in here
and again with because we have only one decimal place formatting it using parent f so centimeter
is here this line were printed and this line this was again type minus one type minus one so this is
two minus one is one it gets the value which is centimeter and we'll print it else mean it is
type 1 and it is centimeter again we go to 60 uh pixel 60 at y direction and we print the
distance it is millimeter we don't need any conversion and we print the unit at
the end and then we wait 500 millisecond this function is in here and it prints the
text on the serial monitor if you click here or go to tools serial monitor so you can see it
but if you uncomment this it will print otherwise you don't need to do it so this is
for debugging if in case it doesn't show on the screen and you want to see it
and this one again it prints on the serial monitor the distance and the type is three
it gets the distance in inch if the type is two it prints a centimeter else it prints the actual
distance which is in millimeter and at the end it prints the unit and we create a new line so this
was the full explanation of the code make sure to subscribe so you get updates of my upcoming videos
and here is a demonstration of measuring distance in millimeter I’m putting it at around 60 in here
so we should get 60 millimeter 90 millimeters or less good 20 millimeters
if I’m pulling it properly
and here's a test for centimeter I’m putting it around five
add around six centimeters I’m going 10
now I’m at 17
that's good 3 so it responds very well and here is a test
an inch unit let me put it around three as you can see we are reading four
let me go seven
one inch
so perfectly responding
now this is the code where we use push button to select millimeter or centimeter
I’ve explained the above everything is the same except in here we check fm5 dot push button a
so push button a is on the left side this is a this is b and this is c it is pressed
then this value will be true we say f this is true then the type is two
f button b is true then the type is one f button c is pressed so that this this is now we do not
do the type we set the cursor as zero zero set the text size and we print this let's make the
screen black and we print shutting down and then we are changing the text and creating a new line
and then we say use power and then backslash in mean go new line power switch 2 and then
n again it goes to turn it on it goes to the next line and we wait 303 seconds and then after that
we use m5 shutdown so this will shut down the device if you press the button c and then
here the rest is exactly the same we read that distance we do the conversion which I
which I explained it in in the previous code and the rest of the code is exactly the same as before
the power off with this push button when you touch it
when you touch it says it will be shut down and turn it on with power
thank you for watching a tutorial on esp32 if you learned something and found this useful
please thumb up as this will help my video in the search algorithm of YouTube
if you have comment or question please post it in the comment section below
I try to answer and reply if you haven't subscribed to my channel please do so
now
in this tutorial we are going to learn how we can send the stepper motor from the interface
of your phone or mobile device or a browser to any predetermined angles by simple touch
it will be controlled over wi-fi and you will have unlimited number of push buttons
each will have their own angle direction and speed