Pages: [1]   Go Down
Author Topic: L298N HELP!!??  (Read 474 times)
0 Members and 1 Guest are viewing this topic.
Long Island, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 40
He that would make his own liberty secure, must guard even his enemy from oppression; for if he violates this duty, he establishes a precedent that will reach to himself.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I completed the getting started with Arduino guide and exercises. I proceeded to buy the L298N motor shield and two small dc motors (not steppers) and two Photo resistors. I am trying to make a basic photovore that will determine engine speed based on light level for each side and thereby steer. Fairly straightforward or so one would assume. I am going to be hooking up the motors to the a and b motor drivers on the L298N. I am currently trying to figure out how to control speed. I am using this code at present, which I found on some site:

Code:
int pwm_a = 3;  //PWM control for motor outputs 1 and 2 is on digital pin 3 (or 5,6)
int pwm_b = 9;  //PWM control for motor outputs 3 and 4 is on digital pin 9 (or 10,11)
int dir_a = 2;  //direction control for motor outputs 1 and 2 is on digital pin 2 (or 4,7)
int dir_b = 8;  //direction control for motor outputs 3 and 4 is on digital pin 8 (or 12,13)

void setup()
{
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_a, OUTPUT);
  pinMode(dir_b, OUTPUT);

  analogWrite(pwm_a, 100);  //set both motors to run at (100/255 = 39)% duty cycle (slow)
  analogWrite(pwm_b, 100);

}

void loop()
{
  digitalWrite(dir_a, LOW);  //Set motor direction, 1 low, 2 high
  digitalWrite(dir_b, LOW);  //Set motor direction, 3 high, 4 low

  delay(1000);

  analogWrite(pwm_a, 255);  //set both motors to run at 100% duty cycle (fast)
  analogWrite(pwm_b, 255);

  delay(1000);

  digitalWrite(dir_a, HIGH);  //Reverse motor direction, 1 high, 2 low
  digitalWrite(dir_b, HIGH);  //Reverse motor direction, 3 low, 4 high

  delay(1000);

  analogWrite(pwm_a, 100);  //set both motors to run at (100/255 = 39)% duty cycle
  analogWrite(pwm_b, 100);

  delay(1000);
}

at this point I only have one motor hooked up and 9v batter going to the Uno board. The motor is hooked up to A, and I can hear it engage and the LED is lighting, however the motor is not rotating. I beesech one kind soul to hook me up with a working code snippet to drive the motor, and I can figure out the rest from there. Much thanks.
Logged

Looking to host an Arduino related site? Check us out:

http://www.bitronictech.net/

Long Island, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 40
He that would make his own liberty secure, must guard even his enemy from oppression; for if he violates this duty, he establishes a precedent that will reach to himself.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Unfortunately there is no basic guide to this chip that I have boon able to find, hell if I had the knowledge I would write one. Unfortunately I am a newbie in the world of arduino, this is only my second day working with the board, and first with the L298N.
Logged

Looking to host an Arduino related site? Check us out:

http://www.bitronictech.net/

Long Island, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 40
He that would make his own liberty secure, must guard even his enemy from oppression; for if he violates this duty, he establishes a precedent that will reach to himself.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop()
{
analogWrite(pwm_a, 255);  //set both motors to run at 100% duty cycle (fast)
}

haha the problem has that I ripped this motor out of a broken nano helicopter and the prong was bent, had to move it a bit now it works
Logged

Looking to host an Arduino related site? Check us out:

http://www.bitronictech.net/

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 5519
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Unfortunately there is no basic guide to this chip that I have boon able to find, hell if I had the knowledge I would write one. Unfortunately I am a newbie in the world of arduino, this is only my second day working with the board, and first with the L298N.

The datasheet isn't clear enough...?
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Pages: [1]   Go Up
Jump to: