Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 15, 2013, 05:02:11 am
cleaned up a little -  cant wait to go test it:)

Code:
#include <PWM.h>

int ENA = 11; //PWM
int IN1 = 12;
int IN2 = 13;
int32_t frequency = 25000; //frequency (in Hz)

void setup ()
{
   InitTimersSafe();

  //sets the frequency for the specified pin
  bool success = SetPinFrequencySafe(ENA, frequency);
  if(success)
  {
  pinMode (ENA, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  InitTimersSafe(); //initialize all timers except for 0, to save time keeping functions
  }

}

void test_motor_1 ()
{
 
  for (int i = 0; i < 256; i++)
  {
    digitalWrite (IN1, HIGH);
    digitalWrite (IN2, LOW);
    analogWrite (ENA, i);
    delay (50);
  }

  delay (3000);
  digitalWrite (IN1, LOW);
 
  for (int i = 0; i < 256; i++)
  {
    digitalWrite (IN1, LOW);
    digitalWrite (IN2, HIGH);
    analogWrite (ENA, i);
    delay (50);
    Serial.println(i);
  }

  delay (3000);
  digitalWrite (IN2, LOW);
}

void loop()
{
  test_motor_1();
}
17  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 15, 2013, 04:41:57 am
Yep sorry about the pins..changed now to pins 11,3.  And nice Ill have a  look at the library too
18  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 15, 2013, 04:01:39 am
Ok this is what I cam up with so far, no Board to test it on until latter today when I get back to the workshop.  One question would be is if I can use another value other than the values in the below chart -  for the prescalar factor to bring it into any frequency range I want...for example 1.3 or something
Code:
/*
Changing the PWM frequency on Pins 11 and 3
Setting Divisor Frequency
0x01 1 31250  //should not be able to hear this though the frequency is a little high for the l298
0x02 8 3906.25
0x03 32 976.5625
0x04 64 488.28125 // default
0x05 128 244.140625
0x06 256 122.0703125
0x07 1024 30.517578125 //here is also good..in theroy but may be a little to low for the dc motor
*/

int ENA = 11; //PWM
int IN1 = 12;
int IN2 = 13;
int value = 4; //4 being the default giving  488.28125hz

void setup ()
{
  pinMode (ENA, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
TCCR2B = (TCCR2B & 0xF8) | value;// change the value of the (Timer 2 pins 11, 3?) register to a value ranging between 1 - 7
}

void test_motor_1 ()
{
  
  for (int i = 0; i < 256; i++)
  {
    digitalWrite (IN1, HIGH);
    digitalWrite (IN2, LOW);
    analogWrite (ENA, i);
    delay (50);
  }

  delay (3000);
  digitalWrite (IN1, LOW);
  
  for (int i = 0; i < 256; i++)
  {
    digitalWrite (IN1, LOW);
    digitalWrite (IN2, HIGH);
    analogWrite (ENA, i);
    delay (50);
    Serial.println(i);
  }

  delay (3000);
  digitalWrite (IN2, LOW);
}

void loop()
{
  test_motor_1();
}
19  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 14, 2013, 04:10:05 pm
thanks Erdin, its late here so its some bed time reading for me.  One question though may be how did you derive the switching rate/freq of the l298/ i looked at the data sheet but could not determine which of the values were important to figure it out. 
20  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 14, 2013, 02:20:37 pm
ok so the motors are now moving which is nice so thanks for all the help:)  Another thing i have to deal with now is the audible noise of the PWM frequency.  Ive read up a little already about the time registers but now I'm confused more.  What I am hearing is within the speech frequency range (using pin 10 as the PWM)  I tried using the fast PWM on pin 6 but this just pushes the sound slightly higher in pitch. From what I understand the default value of the PWM for the slow and fast is 32000 and 64000(approx).  This should for me be clearly out of the audible range but it clearly inst. Any points or perhaps what to look at..is 64000 approx the upper limit of the PWM frequency or could I go higher(not considering the external electronics) or should I go lower?.
21  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 13, 2013, 07:34:06 am
ok great so Ill be off to give it a spin soon..hopefully:)
22  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 13, 2013, 06:11:33 am
ok so your saying to use a non pwm pin for example input 1 and 2 (lets say pins 1 and 2 from the Arduino for the direction change) say 0 1 for left and 1 0 for right and then use the enable pin with PWM for the speed? 

I mean It doesnt bother me too much to leave it as originally intended but if its going to make code easier then that's a plus
23  Using Arduino / Motors, Mechanics, and Power / Re: DIY L298n motor controller - need a little help on: April 13, 2013, 05:39:25 am
Erdin the motors are not that big and as I said I measured them and stall was less than 1amp each so I should be fine.  Id rather try and get this working as I have no real money to go off and buy anything..Im not kidding:(


I made a little picture to make it a little clearer of where I want to make sure I'm hooking things up properly.  The image should server as a nice example of how some newbie like me can hook this all up

Normally with a h bridge Id expect that I would have 1 PWM and 1 digital pin to control direction but its seems from this setup that its using 2 PWM outs from the arduino.  I am not sure of what advantage or disadvantage this has (apart that Im using 2 extra PWM on my uno).

Im trying to make a fast Gimbal head that uses a potentiometer as the initial controller for example 0 - 512 :: 512 - 1024 = PWM left and right for each motor 512 being middle or 0 PWM

Anyway just trying to sort out this pin stuff and in the meantime looking fro some nice code to run the PWM..
24  Using Arduino / Motors, Mechanics, and Power / DIY L298n motor controller - need a little help on: April 12, 2013, 07:41:05 pm
Hi all,
       So today I built myself a l298 motor controller for the purpose of controlling a few 24v dc motors.  I used an instructables paint by number type of tutorial thinking that it we be clear on how to set it up with arduino at the end..but it isnt so clear to me.
Here is the link for the board that I made
http://www.instructables.com/id/Dual-H-Bridge-L298-Breakout-Board-Homemade/

What I would like help with  is how to use it, what pins I should use and which grounds to connect together and also if Im going to have an issue using 0,43 ohm 1 watt resistors instead of the 0,047 it says to use.

Ill be setting it up for pwm control of 2 motors.  I measured the amps of both motors and it seems I am under the 2amp limit of this chip.
my power supply is not quite 24v(19.4) taken from an old laptop that died but it has about 4amps output.
Its really just the hook up that im looking to complete and if those cap and resistor values are within spec..

25  Using Arduino / Project Guidance / Re: analog connection between 2 Arduinos -not i2c or serial on: March 06, 2013, 12:57:31 pm
and for discussion sake here is the other stuff im doing..not directly on the arduino its a chipkit32 and faster so I know as far as i can see that firmata wont work on it but simple serial stuff should..and im testing the serial for arduino anyway
26  Using Arduino / Project Guidance / Re: analog connection between 2 Arduinos -not i2c or serial on: March 06, 2013, 12:52:00 pm
actually anything that can let me get osc values to an arduino with 2 float values is all I need, it could be processing or pure data or whatever.  I was hoping for a simple pure data patch and a simple bit of code that I could integrate with the other code I have. I abandoned serial yesterday but I can see there are so many options for so many things that I need to stick with it and try and figure it out a little more.

I could use i2c or serial I just got stuck trying to make it work that i thought perhaps it would be simpler another way for a basic programmer(very basic). 

27  Using Arduino / Project Guidance / analog connection between 2 Arduinos -not i2c or serial on: March 06, 2013, 05:15:45 am
I have 2 Arduinos, one for running accelstepper and the other for using firmata so I can send values from pc.  I did this because I was having a hard time getting serial communication to work correctly and have the accelstepper running at the same time.  So my thought now was to use the PWM out from one Arduino to analog in on the other.  I cant use i2c or serial, I guess the simplest way would be if there was some way for the second Arduino to read the pwm directly without having to make an analog to digital converter. 
has anyone done this before?  Any help links to something simple would be fantastic.
28  Using Arduino / Programming Questions / Re: vvvv to arduino using serial on: March 06, 2013, 04:32:26 am
vvvv is a graphical programming environment like puredata or maxmsp
http://vvvv.org/
I got a little further with a new power supply, which seemed to stop the hanging as I guess I was under powering this little servo(micro servo).  Anyway with a simple test program on the arduino I as testing v4 ability to send out us full information over the rs232 and its seems its just not able to send consistent data and therefore I can use it at the moment.  Ill be resorting to using 2 Arduinos and firmata on one and analog to the other for now as I cant fix what ever string sending issues..Could be so easy but its not
29  Using Arduino / Programming Questions / vvvv to arduino using serial on: March 05, 2013, 01:39:02 pm
Im having a very hard time trying to get any usable input over the serial port to arduino from vvvv.  I have included 2 my test patch and some code that zoomkat work on for something else that I thought I could modify.  I get some servo movement but usually as soon as I start my connection from vvvv everything on the screen freezes. I only need to get in a few float values to arduino to control some servos and latter positions of some stepper motors.  Please anyone else who may have dealt with this before and has a a solution then Id be very grateful.
Below is the code so far and attached is the v4 patch to go with it.  Its quite specific to VVVV so I hope Im posting in the right place.

Code:
//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added

String readString;
#include <Servo.h>
Servo myservoa;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);

  myservoa.writeMicroseconds(1500); //set initial servo position if desired


  myservoa.attach(9);  //the pin for the servod control
  Serial.println("TESTME"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        //Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
         Serial.print("writing Microseconds: ");
         Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
        }
        else
        {   
         Serial.print("writing Angle: ");
         Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
        }
         readString=""; //clears variable for new input
      }
    } 
    else {     
     readString += c; //makes the string readString
    }
  }
}





30  Using Arduino / Programming Questions / Re: Serial Control of variables on arduino from computer on: March 05, 2013, 11:56:15 am
zoomkat thats awesome and seems like a possible solution for what Im trying to do getting in serial from vvvv.  Im trying to get some very basic values in via vvvv and I have the option to intersperese or use whatever delimiter I need.  Ive got some servo movement but its pretty jumpy..am i missing something to make this work correctly?

I attached the v4 file in case you happen to deal with it.
Pages: 1 [2] 3 4