Home » Archive by category "L298N"

Status Optocoupler

I finally got the octocouplers and tried them in my circuit but without success. I think I have reviewed my code and circuit tens of times but I don’t see where is the issue. Even with the octocouplers connected I still have the same symptoms. Once the DC motor runs, I cannot read any signal anymore with the infrared. Weird, very weird.
Anyway, I keep looking but I am also busy with plan C :-). I have seen on Ebay that there exists an L298N with integrated optocouplers in the chip to for isolation. I have ordered it yesterday evening. I hope I can finally get it to work. In the meanwhile when I have time I keep looking into my circuit to see what could possibly be wrong. My circuit is not that complicated.

Continue reading »

PWM enable pins L298N

Hello readers,

Trying out pwm pins to control the speed of the dc motors was not an easy story.  WiringPi has a software driven pwm handler which is used via PI4J.  In fact WiringPi is a GPI Access C library.  For more information see WiringPi.  The software handler makes it possible to have pwm functionality on all GPIO data pins on the raspberry pi.  There are also hardware pwm pins but there are only a couple of those dedicated hardware pins.  I have chosen to go for the software handled pwm pins.  What worried me was that the pin for the enable pin was not like the ones for the input pins (between the 2 enable pins) on the L298N.  I managed to get it wired but was not really satisfied because it didn’t fit right.  The result was that I could not manage at all the speed of the dc motors using pwm.  Whatever I tried in my little test program, it did not work work on the dc motors.  Just on the moment I was about to test with the hardware pwm pins, I found out there was a jumper on the enable pin, covering 2 pins.  At first sight when turning the L298N upside down, one pin was connected to the enable and the other pin had no real connection.  But since I am not a microchip nor electronics expert, that could be a wrong impression.  I connected 2 pwm (software handled) pins from the raspberry pi with the enable pins on the L298N which fitted right this time.  And guess what.  It worked.  I was able to increase and decrease speed of the dc motors.  Just like mentioned on the WiringPi site.

Shortly the pin wiring.  I am using the Raspberry Pi B+.  The port numbering is described at GPIO Port Numbering.

GPIO 0 -> enable A, GPIO 4 -> enable B, GPIO 2 -> input 1, GPIO 3 -> input 2, GPIO 5 -> input 3, GPIO 6 -> input 4, the output pins are wired to the dc motors, the battery (I used a 8,4V) positive wire is wired to the +V12 pin, the 3,3V power pin (Raspberry Pi) is wired to the +5V pin.  I know it sounds not logical +12V connected to 8,4V and +5V connected to 3,3V but it worked.  I bet my motor will turn like mad when I put higher voltage battery on it.



Continue reading »


A while ago I talked about making a Raspberry Pi Controlled car.  Don’t worry.  I did not forget.  Actually, I started yesterday writing some code to get the DC motor running.  What I need to get this working from a functional point of view is a Motor Controller which is a L298N in this case and of course the Raspberry Pi whom who is the microcontroller.  I have put a wheel on the DC Motor to make more clear where I am going to.  I also need a powersupply (4 AA batteries in a parallel holder) connected to the Motor Controller.  After some time I finally got it to work.  Felt great to see the wheel turning in both directions.  All done with some simple instructions.  The most difficult thing was wiring everything up so to speak.  The programming effort was very limited, just a couple of lines to get this to work.  Very easy.  Just setting some pins low or high and done …  Far more easy than the I2C instructions.

Once I have cleaned up my code, I will put it on Github.



Continue reading »