Raspberry Pi Pico Tutorial - L298N Motor Driver Module

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to the nerd cave today's tutorial we will learn how to use the l29n motor driver module with the raspberry pi pico we will look at how to connect this module to the pico to control two motors in the first example we will let the motors turn full speed in either clockwise or anti-clockwise direction and in example 2 see how can we use pwm to control the speed of the motors using this playstation 2 joystick the l29n comes in different packages depending on the module but the most common one you will see in every diy video will look like this we have the motor power input pen vcc here in the front which takes an input of 5 volt to 35 volt with a peak current up to 2 ampere the input next to it has a common ground with all the power supplies there is also a 5v pen which can either be an input or an output this depends on the voltage used at the motors vcc the module have an on-board 5v regulator which is either enabled or disabled using a jumper if the supply voltage vss is between 5 to 12 volt we can enable the 5 volt regulator and the 5v pin can be used as an output for example for powering our picker board but if the voltage supply is greater than 12 volt we must disconnect the jumper because those voltages will cause damage to the onboard 5 volt regulator in this case the 5v pin will be used as an input as we need to connect it to the 5v power supply for the ic to work correctly you should also note that the ic makes a voltage drop of about one and a half to two volt for example if we use 7.59 volt as our input voltage the voltage at the motor terminals will be around 5.75 volt which means that we won't be able to get the maximum speed out of our dc motors due to the voltage drop next are the logical control inputs the enable i and enable b pens are used for enabling and controlling the speed of the motor if a jumper is present on this pin the motor will be enabled and work at maximum speed and if we remove the jumper we can connect a pwm input in that way we can control the speed of the motor if we connect this pen to ground the motor will be disabled next the input 1 and 2 pins are used for controlling the rotation direction of motor a and the input 3 and 4 for motor b if input 1 is low and input 2 is high the motor will move forward if input 1 is high and input 2 is low the motor will move backwards in case both inputs are the same either low or high the motor will stop the same applies for the input 3 and 4 to control motor b we will connect the module as indicated on a schematic diagram for our first demonstration make all the necessary connections as shown after making all the connections head over to my github repository link given in the description where i have included all the code for each example we will discuss open example.py and copy all the code and then inside funny create a new file and paste the code let's look at the code together we start by importing the pen module from the machine library and import a time module for creating delays we define all the input bins and enable pence's output according to our schematic since we will not be using pwm to control the speed we can set an apple pen a and b too high we then create four functions for the movement of the motors to either turn clockwise or anti-clockwise we define a function move forward and set the pins to low or high as indicated if you find that one motor turns in the opposite direction due to the connections you can change the pins low and high also up the wires connected to the motor we define a function move backward and see depends as indicated which is the opposite then a move forward function in the following two functions turn right and turn left we will set one motor off by setting both its input to low and turn the other one either to the right or left depending on the function we define a function stop to stop all the motors and set all the input pens to low but you can also set this to high now we can create an endless loop to call the functions as needed with a delay in this example we move the wheels forward for two seconds and stop then rotate the wheels backward for two seconds install and we'll do the same for right and left before the loop repeats itself uploading the code to the pico we can see that the motor is turning as indicated in the code this code is a good start for creating an autonomous robot car for a project in the last example we will use the thumb joystick to control the direction of the motor and the speed using pwm add the joystick to your circuit as shown in the schematic diagram and open example 2 in a github repository we start by importing pen adc and pwm from machine we then set up pen 27 and 26 as analog inputs for our choice 6x and y-axis we define the module input bands but we will set them as pwm for enable a and b for the frequency of the pwm we will set it to 1500 hertz we again define the functions move forward backward and stop and this time we will use the move forward to control the right turn and left then in our endless loop we will read the x value and the y value for our joystick which fluctuates the x and y values we receive are between three two thousand to thirty four thousand we can then use an if statement to call the stop function if we receive values in this range if we push the joystick all the way backward we will receive a value of sixty five thousand five hundred and thirty five and all the way forward we will receive 400. using this information we create an if statement to test if the y value is greater than 34 000 if this is true we will convert the value we receive into a duty cycle that we will send to both enable a and b which will then move backward with a certain speed depending on how far the joystick has been placed with this we can now control the speed of the motor we will do this for move forward and turn right and left if you are interested in knowing how the calculations were done i will upload a detailed description of this topic in a github repository uploading this code to the pico we can now control the motif direction and speed with the joystick i hope you found this tutorial helpful and for more content on a raspberry pi pico and tutorial subscribe to my channel i will see you in the next video you
Info
Channel: NerdCave
Views: 22,583
Rating: undefined out of 5
Keywords: LN298N raspberry pi pico, dc motor, raspberry pi, ln298n motor driver, ln298n, l298n pwm, l298n dual h bridge, raspberry pi pico, raspberry pi tutorial series, raspberry pi pico programming, raspberry pi pico motor control, nerdcave
Id: H1Fzil_VUq4
Channel Id: undefined
Length: 6min 35sec (395 seconds)
Published: Sun May 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.