ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

l298 python code

Mon May 13, 2019 10:35 am

hi guys
i used l298 for driving motors and everything goes right and dont have error for python code to run
but when i send command to run, motor doesnt work!
what is the problem?
i used this tutorial:
https://www.electronicshub.org/raspberr ... pberry-pi/

https://daneshjookit.com/%D9%85%DA%A9%D ... motor.html

User avatar
B.Goode
Posts: 8058
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: l298 python code

Mon May 13, 2019 11:55 am

Welcome to the Raspberry Pi forums.


ladypi wrote:
Mon May 13, 2019 10:35 am
hi guys
i used l298 for driving motors and everything goes right and dont have error for python code to run
but when i send command to run, motor doesnt work!
what is the problem?
i used this tutorial:
https://www.electronicshub.org/raspberr ... pberry-pi/

https://daneshjookit.com/%D9%85%DA%A9%D ... motor.html


Although reference to the tutorials you used is valuable, it doesn't tell the volunteer helpers here how you may have interpreted (or misinterpreted) them.

It will probably be necessary to share a wiring diagram and a copy of your final (failing) code.


Have you tested the motors independently from the RPi, to check that they actually work?

pcmanbob
Posts: 6450
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: l298 python code

Mon May 13, 2019 12:44 pm

For the wiring its probably best to post some good pictures as a digram will still only show us how you think its connected, were as pictures will show that actual connections.

And the code will only run under python and not python 3
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

Re: l298 python code

Wed May 15, 2019 6:49 am

pcmanbob wrote:
Mon May 13, 2019 12:44 pm
For the wiring its probably best to post some good pictures as a digram will still only show us how you think its connected, were as pictures will show that actual connections.

And the code will only run under python and not python 3
thanks, check this photo

Code: Select all

import RPi.GPIO as GPIO          
from time import sleep

in1 = 24
in2 = 23
en = 25
temp1=1
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(in1,GPIO.OUT)

GPIO.setup(in2,GPIO.OUT)

GPIO.setup(en,GPIO.OUT)
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.LOW)
p=GPIO.PWM(en,1000)
p.start(25)
print("\n")
print("The default speed & direction of motor is LOW & Forward.....")
print("r-run s-stop f-forward b-backward l-low m-medium h-high e-exit")
print("\n")    

while(1):

    x=raw_input()
    
    if x=='r':
        print("run")
        if(temp1==1):
         GPIO.output(in1,GPIO.HIGH)
         GPIO.output(in2,GPIO.LOW)
         print("forward")
         x='z'
        else:
         GPIO.output(in1,GPIO.LOW)
         GPIO.output(in2,GPIO.HIGH)
         print("backward")
         x='z'


    elif x=='s':
        print("stop")
        GPIO.output(in1,GPIO.LOW)
        GPIO.output(in2,GPIO.LOW)
        x='z'

    elif x=='f':
        print("forward")
        GPIO.output(in1,GPIO.HIGH)
        GPIO.output(in2,GPIO.LOW)
        temp1=1
        x='z'

    elif x=='b':
        print("backward")
        GPIO.output(in1,GPIO.LOW)
        GPIO.output(in2,GPIO.HIGH)
        temp1=0
        x='z'

    elif x=='l':
        print("low")
        p.ChangeDutyCycle(25)
        x='z'

    elif x=='m':
        print("medium")
        p.ChangeDutyCycle(50)
        x='z'

    elif x=='h':
        print("high")
        p.ChangeDutyCycle(75)
        x='z'
     
    
    elif x=='e':
        GPIO.cleanup()
        break
    
    else:
        print("<<<  wrong data  >>>")
        print("please enter the defined data to continue.....")
Attachments
2.jpg
2.jpg (167.59 KiB) Viewed 537 times

User avatar
joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: l298 python code

Wed May 15, 2019 10:20 am

How are you powering the motor? All I can see is a lead connected to the logic power supply.

pcmanbob
Posts: 6450
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: l298 python code

Wed May 15, 2019 10:27 am

It would be helpful if you post a picture showing the connections to the motor driver board more clearly especially the ones to the pi and power feed terminals, as we can quite be sure how things are currently connected.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

Re: l298 python code

Wed May 15, 2019 10:34 am

joan wrote:
Wed May 15, 2019 10:20 am
How are you powering the motor? All I can see is a lead connected to the logic power supply.
yes i used 9v adapter for driver motor

ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

Re: l298 python code

Wed May 15, 2019 10:36 am

pcmanbob wrote:
Wed May 15, 2019 10:27 am
It would be helpful if you post a picture showing the connections to the motor driver board more clearly especially the ones to the pi and power feed terminals, as we can quite be sure how things are currently connected.
i use 9v adapter for driver motor

User avatar
joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: l298 python code

Wed May 15, 2019 10:53 am

May we have a photo showing the wiring side of the motor driver board? It is not clear where the various wires are connected.

ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

Re: l298 python code

Wed May 15, 2019 11:13 am

joan wrote:
Wed May 15, 2019 10:53 am
May we have a photo showing the wiring side of the motor driver board? It is not clear where the various wires are connected.
add photo ..
Attachments
11.jpg
11.jpg (74.33 KiB) Viewed 486 times

pcmanbob
Posts: 6450
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: l298 python code

Wed May 15, 2019 11:31 am

Sorry but that picture is to small to clearly see anything.

Try uploading a larger image to an image sharing site like imgur.com and then post a link to it here, we need to be able to see detail like this

Example.
Image

Are you sure your motor will run from the adapter you are using ?
have you tried connecting the motor directly to the adaptor to see if the motor runs ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: l298 python code

Wed May 15, 2019 11:32 am

Need a photo from the other end so we can clearly see the IN1/2/EN and the power connections.

ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

Re: l298 python code

Wed May 15, 2019 11:35 am

pcmanbob wrote:
Wed May 15, 2019 11:31 am
Sorry but that picture is to small to clearly see anything.

Try uploading a larger image to an image sharing site like imgur.com and then post a link to it here, we need to be able to see detail like this

Example.
Image

Are you sure your motor will run from the adapter you are using ?
have you tried connecting the motor directly to the adaptor to see if the motor runs ?
https://imgur.com/r6xJLLA

pcmanbob
Posts: 6450
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: l298 python code

Wed May 15, 2019 11:45 am

Well the connections between the pi and motor drive board look ok and I guess you have power connected to motor drive board because the red LED is lit.

when you try to run the motor does that red LED go out ?

Have you tried replacing the motor with a volt meter to see if you actually have any voltage on the motor terminals ?

Have you tried testing the motor drive board by manually making connections between control pins and 5v /ground on motor driver board with out having any connection to the pi what so ever ?

Edit.

So I just tested the program with an L298N and it works just fine motor running forward at low only gives 9.6V when using a 12V psu.

Image

And that's with no motor connected so no load, so either your motor board is faulty, you have a bad connection some were, you motor will not run at the voltage supplied by your PSU or your PSU cant run both the motor and the motor driver board causing the motor driver board to shutdown.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ladypi
Posts: 10
Joined: Mon May 13, 2019 10:26 am

Re: l298 python code

Wed May 15, 2019 12:37 pm

pcmanbob wrote:
Wed May 15, 2019 11:45 am
Well the connections between the pi and motor drive board look ok and I guess you have power connected to motor drive board because the red LED is lit.

when you try to run the motor does that red LED go out ?

Have you tried replacing the motor with a volt meter to see if you actually have any voltage on the motor terminals ?

Have you tried testing the motor drive board by manually making connections between control pins and 5v /ground on motor driver board with out having any connection to the pi what so ever ?

Edit.

So I just tested the program with an L298N and it works just fine motor running forward at low only gives 9.6V when using a 12V psu.

Image

And that's with no motor connected so no load, so either your motor board is faulty, you have a bad connection some were, you motor will not run at the voltage supplied by your PSU or your PSU cant run both the motor and the motor driver board causing the motor driver board to shutdown.
thanks alot. i,ll with check it and tell you result

ghp
Posts: 1395
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: l298 python code

Wed May 15, 2019 5:17 pm

Hello, on one of the photos there is a small, blue plastic case with a label 'tower pro'. These devices are IMHO not suitable to be driven by a L293, but need a constant power supply with 5V and pulse width modulated signal to control them.

pcmanbob
Posts: 6450
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: l298 python code

Wed May 15, 2019 5:49 pm

ghp wrote:
Wed May 15, 2019 5:17 pm
. These devices are IMHO not suitable to be driven by a L293, but need a constant power supply with 5V and pulse width modulated signal to control them.
That was my example picture to show the OP what sort of detail was required when posting pictures of wiring/gpio connections ,
hence the line " we need to be able to see detail like this " , it was just a random image I had posted before and I was not suggesting that you could control a servo ( Tower pro SS90 ) from an L298N.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”