Viikate79
Posts: 4
Joined: Fri Feb 27, 2015 8:10 pm

L298N chip question

Fri Feb 27, 2015 8:56 pm

Hi,
Can some one please help me (n00b) with L298N motor driver. Im trying to make timelapse rail but now im stuck with this damm board. Im not sure is problem in code or not...

https://i0.wp.com/img.dxcdn.com/product ... 0475_2.jpg

Im very happy if some one could make example python code for this board to just run 1 motor.

Here is my code... oh and sry my bad english

#program asks how many pictures you wanna take then starts running when last picture is taken motor moves back to start
import wiringpi
from time import sleep

#Gpios
moottori_oikealle= 2 #motor foward
moottori_vasemmalle= 3 #motor reverse
suljin= 5 #shutter

#variables
moottori_odota1= 2.5 #time for rail settle before taking picture
moottori_odota2= 0.5 #motor waits
moottori_kay= 0.25 #motor runs foward
moottori_pakitus_maara= 0 #how many times motor need to run moottori_kay to be at start

suljin_aika= 0.5 #exposure is on this time

io= wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
io.pinMode(moottori_oikealle,io.OUTPUT)
io.pinMode(moottori_vasemmalle,io.OUTPUT)
io.pinMode(suljin,io.OUTPUT)

#asks how many pictures you want
kuvia= raw_input(" how many pictures you want ")
kuvia= int(kuvia)

while (kuvia > 0):
io.digitalWrite(moottori_oikealle,io.HIGH)
sleep(moottori_kay) #motor moves this time
io.digitalWrite(moottori_oikealle,io.LOW)
sleep (moottori_odota1)#time for rail settle before taking picture

io.digitalWrite(suljin,io.HIGH) #exposure starts
sleep(suljin_aika) #exposure is on this time
io.digitalWrite(suljin,io.LOW) #exposure ends
print "kuvia on ottamatta: " #prints how many pictures need to taken
print kuvia-1
sleep(moottori_odota2)
kuvia= kuvia-1
moottori_pakitus_maara= moottori_pakitus_maara+1
else:
while (moottori_pakitus_maara > 0): #motor will reverse
print "motor is driving reverse" ,moottori_pakitus_maara
io.digitalWrite(moottori_vasemmalle,io.HIGH)
sleep(moottori_kay)
io.digitalWrite(moottori_vasemmalle,io.LOW)
moottori_pakitus_maara= moottori_pakitus_maara-1
else:
print "DONE"

Viikate79
Posts: 4
Joined: Fri Feb 27, 2015 8:10 pm

Re: L298N chip question

Sat Feb 28, 2015 2:38 pm

Oh and im not sure do i need to use enable A or not?
thanks

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

Re: L298N chip question

Sat Feb 28, 2015 2:51 pm

It's a simple module. Not much can go wrong.

Please post a photo of the connections you have made between the Pi and the L298N. If you can't supply a photo please describe the connections.

Viikate79
Posts: 4
Joined: Fri Feb 27, 2015 8:10 pm

Re: L298N chip question

Sat Feb 28, 2015 3:13 pm

L298N chip board i have put on to raspberry pi where are those gpio pins.
Attachments
26 päivä helmikuu 2015 kuva 001.jpg
26 päivä helmikuu 2015 kuva 001.jpg (51.1 KiB) Viewed 814 times

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

Re: L298N chip question

Sat Feb 28, 2015 3:16 pm

I'd try jumpering the enable pins on the board.

With the modules I use you can connect a gpio to the enable pin to set it high or low in software.

Viikate79
Posts: 4
Joined: Fri Feb 27, 2015 8:10 pm

Re: L298N chip question

Fri Mar 06, 2015 7:10 pm

Jumpers did not help :(

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: L298N chip question

Fri Mar 06, 2015 7:47 pm

You do not need Raspberry Pi to test that board. The L298N needs two separate power supply lines and of course ground connection. Connecting a jump wire from one of the inputs to logic high (usually about 5 V) should start to turn the motor. Do not connect the logic input to motor power supply since that will damage the L298N. You could test it also with LEDs first like here

https://github.com/oh7bf/RasPiHBridge/b ... bridge.pdf

Once you have checked the hardware you can try carefully if Raspberry Pi 3V3 logic levels can drive the board directly. If not you might need logic level shifters between 3V3 of Raspberry Pi and 5 V used by the L298N on the board.

Return to “Beginners”