OpenMarine
L298N and Arduino Nano - Printable Version

+- OpenMarine (https://forum.openmarine.net)
+-- Forum: Pypilot (https://forum.openmarine.net/forumdisplay.php?fid=17)
+--- Forum: General discussion (https://forum.openmarine.net/forumdisplay.php?fid=18)
+--- Thread: L298N and Arduino Nano (/showthread.php?tid=1941)



L298N and Arduino Nano - jamos.tan@gmail.com - 2019-08-13

Hi,

I'm having trouble with the L298N motor driver. I realize it is very weak (rated 2A) and not supported, but I just want to use it to be able to test a concept.
All info about the board is here: https://produktinfo.conrad.com/datenblaetter/1500000-1599999/001573541-an-01-en-JOY_IT_MOTORMODUL__2_4PHASEN__L298N_.pdf

I was hoping someone could help me with the following:

- Which adjustments do I need to make in motor.ino to drive the motor in both directions
- Which pins from Arduino do I need to use

Now I have it setup like this:

- Pins 9 and 10 from Arduino Nano --> pins 1 and 2 on motor controller
- Motor.ino is configured for h-bridge mode

Sync in Pypilot is OK, and when pressing AP or << / >> there is movement. Only problem is:

- Motor spins in only one direction
- No matter what I configure, it rotates very slow (with about 2 watts and less dan 1 amp)

When testing the motor controller and electromotor by 'fooling' the connection by 'thinking' it receives a signal (did that with rs485) it is able to spin quickly, so I know it is capable of more power.
I've attached my motor.ino also. 
.txt   motornosensors.txt (Size: 36.95 KB / Downloads: 248)

Hope somebody can help.


RE: L298N and Arduino Nano - seandepagnier - 2019-08-14

don't use d9 d10 use d2 d3 to in1, in2.

Once this is working, feed d9 to the pwm (ena) pin to get speed control. You might want to switch to pwm_style = 2, since d10 will be pwm output in other direction.

Since it's dual motors, you could maybe parallel everything to get twice the output current?


RE: L298N and Arduino Nano - jamos.tan@gmail.com - 2019-08-14

(2019-08-14, 02:21 PM)seandepagnier Wrote: don't use d9 d10 use d2 d3 to in1, in2.

Once this is working, feed d9 to the pwm (ena) pin to get speed control.  You might want to switch to pwm_style = 2, since d10 will be pwm output in other direction.

Since it's dual motors, you could maybe parallel everything to get twice the output current?

don't use d9 d10 use d2 d3 to in1, in2.
Thanks, tried this and adjusted motor.ino for pwm_style = 2.
When trying the pypilot with this combination the motor does nothing.

feed d9 to the pwm (ena) pin to get speed control
I see that my servo has a jumper placed there, I'm not sure if I need to remove it or keep it.
If I need to remove it, to which of the pins do connect the d9?

 get twice the output current
That's a great idea!  Big Grin Thanks for that.  Wink


RE: L298N and Arduino Nano - seandepagnier - 2019-08-14

you would connect the first one to the ena d9.

I would review the L298N datasheet and look at what motor.ino does closely. I believe pwm_style ==2 is what you want but maybe need to tweak things.


RE: L298N and Arduino Nano - jamos.tan@gmail.com - 2019-08-15

Hi Sean,

I've found an article online which helped me understand more about the L289N board in combination with arduino, and an example sketch steering it.
https://www.teachmemicro.com/use-l298n-motor-driver/ and this is also a good one: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

I've also looked at motor.ino more closely, but don't know how to combine the information I've found in the example sketch from the article, and what to change in motor.ino
Hope I am not asking for too much, but I was wondering if you could help me.


RE: L298N and Arduino Nano - jamos.tan@gmail.com - 2019-08-15

(2019-08-15, 09:35 AM)jamos.tan@gmail.com Wrote: Hi Sean,

I've found an article online which helped me understand more about the L289N board in combination with arduino, and an example sketch steering it.
https://www.teachmemicro.com/use-l298n-motor-driver/ and this is also a good one: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

I've also looked at motor.ino more closely, but don't know how to combine the information I've found in the example sketch from the article, and what to change in motor.ino
Hope I am not asking for too much, but I was wondering if you could help me.

Ok, update here. I've downloaded the newest motor.ino from your github.
My bad, I didn't uncomment the #define VNH2SP30 // defined if this board is used

Autopilot has no errors! When engaging the AP and changing direction of the magnetic compass, polarity reverses OK.
Also manual buttons work.

However, the electromotor is not realy spinning I think. It makes a high pitch sound (recognize it from your video from youtube, makes the same sound)
When measuring it, it is only using about 2 volts.

I'll need to tweak with the gains / and the maximum / minimum settings in the client for that probably right?
Only thing I modified for compensating the low power board I have is change this line:

uint16_t max_current = 200; // 2 Amps


RE: L298N and Arduino Nano - seandepagnier - 2019-08-15

(2019-08-15, 11:54 AM)jamos.tan@gmail.com Wrote:
(2019-08-15, 09:35 AM)jamos.tan@gmail.com Wrote: Hi Sean,

I've found an article online which helped me understand more about the L289N board in combination with arduino, and an example sketch steering it.
https://www.teachmemicro.com/use-l298n-motor-driver/ and this is also a good one: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

I've also looked at motor.ino more closely, but don't know how to combine the information I've found in the example sketch from the article, and what to change in motor.ino
Hope I am not asking for too much, but I was wondering if you could help me.

Ok, update here. I've downloaded the newest motor.ino from your github.
My bad, I didn't uncomment the #define VNH2SP30 // defined if this board is used

Autopilot has no errors! When engaging the AP and changing direction of the magnetic compass, polarity reverses OK.
Also manual buttons work.

However, the electromotor is not realy spinning I think. It makes a high pitch sound (recognize it from your video from youtube, makes the same sound)
When measuring it, it is only using about 2 volts.

I'll need to tweak with the gains / and the maximum / minimum settings in the client for that probably right?
Only thing I modified for compensating the low power board I have is change this line:

uint16_t max_current = 200; // 2 Amps


Try just supplying vcc to the ena pin, and see if the motor spins both ways.

Maybe the frequency is too high.   Look for where the pwm parameters are set and change it.


RE: L298N and Arduino Nano - jamos.tan@gmail.com - 2019-08-15

(2019-08-15, 01:37 PM)seandepagnier Wrote:
(2019-08-15, 11:54 AM)jamos.tan@gmail.com Wrote:
(2019-08-15, 09:35 AM)jamos.tan@gmail.com Wrote: Hi Sean,

I've found an article online which helped me understand more about the L289N board in combination with arduino, and an example sketch steering it.
https://www.teachmemicro.com/use-l298n-motor-driver/ and this is also a good one: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

I've also looked at motor.ino more closely, but don't know how to combine the information I've found in the example sketch from the article, and what to change in motor.ino
Hope I am not asking for too much, but I was wondering if you could help me.

Ok, update here. I've downloaded the newest motor.ino from your github.
My bad, I didn't uncomment the #define VNH2SP30 // defined if this board is used

Autopilot has no errors! When engaging the AP and changing direction of the magnetic compass, polarity reverses OK.
Also manual buttons work.

However, the electromotor is not realy spinning I think. It makes a high pitch sound (recognize it from your video from youtube, makes the same sound)
When measuring it, it is only using about 2 volts.

I'll need to tweak with the gains / and the maximum / minimum settings in the client for that probably right?
Only thing I modified for compensating the low power board I have is change this line:

uint16_t max_current = 200; // 2 Amps


Try just supplying vcc to the ena pin, and see if the motor spins both ways.

Maybe the frequency is too high.   Look for where the pwm parameters are set and change it.

Its working! I've done it by adjusting the max skew settings. Tiller from the autohelm st4000 works like a charm now! You are the best.


RE: L298N and Arduino Nano - ironman - 2019-08-31

I got myself an IR2104 (instead of an IR2101), which, in essence, has the similar inputs as the L298: direction and enable, instead on low side and high side. I tried the pwm_style=2 option as well, but found it unsatisfactory, with the sound coming out of the motor, and the motor hardly getting in motion, or very abrupt when slew parameters set close to 100. I then switched back to the pwm_style=0 ('h-bridge'), using only d2 and d3, whilst tying the EN pin of the driver to vcc. This seems to work fine for me in the lab. Tying EN to vcc was suggested as a test above, but I'm under the impression that the d2 and d3 outputs give me PWM as well, so I think I should not want for more. Is this true?  I'm aware that by doing so, the low side of my h-bridge is always engaged in rest, but frankly I don't really think I should care, should I?