Show Posts
Pages: 1 ... 9 10 [11] 12
151  Using Arduino / General Electronics / Re: RCA video signal and transistors? on: December 13, 2011, 09:04:25 pm
or use the microcontroller to bias the bjt.

the bjt toggles a relay. common to tv, NO to one source, NC to the other source.

unless you intend to switch the signal a LOT...... a mechanical component should work just fine.
152  Using Arduino / General Electronics / Re: Serial communication distance on: December 13, 2011, 08:52:18 pm
at work I have run rs232 150+ feet at 38400 baud.

115200 baud rs232 tends to drop out around 50 feet for me.

baud rate and the device you are ouputing frrom make a fair difference for ditances.

if you are looking for long distances 485 or 422 conversion is certainly the way to go as mentioned above.

153  Using Arduino / Programming Questions / Re: Newbe question about programming on: December 08, 2011, 12:08:21 am
and still you haven't posted your code.

just an observation. :-)
154  Using Arduino / General Electronics / Re: PS1 Controller Questions on: December 04, 2011, 09:50:02 pm
you said ps1 in the first post but posted a link to ps2 library....

if it is ps2 library you need use Bill Porters library.
http://www.billporter.info/playstation-2-controller-arduino-library-v1-0/

I used it last week on a lynxmotion track base and lynxmotion arm. worked great.
155  Using Arduino / Programming Questions / Re: code question on: December 04, 2011, 09:38:48 pm
although I am sure you could find this with some searching.

i is a variable set up to inside the loop (in this case an an int type) to keep track of how many times the for loop has been repeated thus far.

int i=0 //sets an initial value
i<20 // if this statement is true run the loop again
i++ // add one to i

and yes. it will run 20 times.

first time i will be 0
second time i will be 1
........
........
........
twentieth time i will be 19
then on the twenty-first time i will be 20 which makes i  < 20 false and the loop exits.

the end.
156  Using Arduino / Programming Questions / Re: Complete noob starting out, need help PLEASE on: November 29, 2011, 10:33:07 pm
if you wrote a sketch in java I would be impressed. arduino are programmed in c++....

I would say start out with a plan on what you want the final product to do. them once you have an idea of the final build you can come nack and say.

"I have an arduino uno and would like to set up an automatic aquarium that would............................. What would everyone recommend to get this project started?"

you have to know what you wa t to accomplish before you start with anything else or you will work yourself in circles usually.
157  Using Arduino / General Electronics / Re: Breadboards....I don't understand. on: November 29, 2011, 11:56:16 am
the arduino is a microcontroller.

is the breadboard you have solderless breadboard (white with lots of divets to push components into) or standard breadboard (usually a yellowish color with just a bunch of through holes)?

pictures would be great to make sure everyone understand what you have to work with.
158  Using Arduino / General Electronics / ps2 controller interface using fets on: November 29, 2011, 11:39:31 am
I have been trying to interface a ps2 controller to my mega (1280) using bill porters ps2x library.

I eventually manged to get a hard wired controller working. It was a pelican brand from wally world.

it didn't seem to like 5 volts and I couldnt find a relaitivly simple way to convert without having to buy the tsx0104 as shown here.
http://www.wegmuller.org/arduino/Arduino-Playstation_gameport.html

doing some more research on level shifting I found what these guys were doing with an I2C circuit.
http://www.google.com/m/url?ei=CQLVTvCZB6SuNZUr&q=http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf&ved=0CBoQFjAD&usg=AFQjCNEFePVS1vee0VS57JEjTsMddGSPGA

so what I ended up doing was merging these two ideas and getting it working. the hard wire model worked fine with only level shifting the command, attention, and clock line. the data line was wired directly to the arduino.

I used a 2n6660 fet. tied the gate to 3.3 volts. the source tied to the controller with a 10k resistor pulling the line up to 3.3. the drain is tied directly to the arduino with no pull up.

I went ahead and shifted all 4 lines when I made the shield just to be sure I wouldn't have any issues with wireless controllers.

I made a quick hand drawn diagram and scanned it in for reference. It only shows one circuit but that same thing is repeated 4 times. 1 for each com line.

It has been tested with the two controller i have. One wireless Pelican, One wired Pelican.
159  Using Arduino / Programming Questions / Re: ps2x in functions? on: November 21, 2011, 12:30:13 pm
I see your point. In most cases i would or if I would be storing these variables inside of the function where it is needed.... which I suppose would be possible.

in this case i am using these Numbers in a call. so I would be specify in that call all needed information:

source of control, which would be my controller assignments as I know them
desitantion of command, the channel on the ssc32
high and low limits, to stop motion before physical impact
speed limit of joint.

so if I am always passing this into a function as a value directly from the controller I am not seeing how it would benefit the flow of the program to name is as the distination rather than the source....

maybe its just the way we see the flow in our minds.

in either case, the help is much appreciated. "
160  Using Arduino / Programming Questions / Re: ps2x in functions? on: November 20, 2011, 09:50:01 pm
in this case. no.

its a ps2 controller. left x is side to side left y is up and down. same for right joystick. in my sketch they will do a few different things at different times so if I name them for the function it would be more confusing than if I refer to them as the x and y axis of the left and right joystick.
161  Using Arduino / Programming Questions / Re: ps2x in functions? on: November 20, 2011, 10:55:22 am
understood. So i would end up with something like this in my full code..... (abridged version)

Code:
int RX;
int RY;
int LX;
int LY;
int azimuth = 128;

void loop () {
ps2x.read_gamepad(false, 0);

RX = ps2x.Analog(PSS_RX);
RY = ps2x.Analog(PSS_RY);
LX = ps2x.Analog(PSS_LX);
LY = ps2x.Analog(PSS_LX);

analogMotion (RX, aximuth, 600, 2400, 1);

}

So my joint values are stored as int and refreshed each loop. but passed as integers.
162  Using Arduino / Programming Questions / Re: ps2x in functions? on: November 19, 2011, 11:54:28 pm
I think i see what you are saying. But if

ps2x.Analog(PSS_RX) is an int value between 0 and 255

and analogStick = ps2x.Analog(PSS_RX) 

Wouldn't map(analogStick, 0, 127, jointSpeed, 0) == map(ps2x.Analog(PSS_RX), 0, 127, jointSpeed, 0) as it does in the first set that is tested and working?

i think my error is coming in where i don't know how to make the call properly reference what value i should read form the controller for that iteration of the function. In this case the arduino would see ps2x.Analog(PSS_RX) as a string rather than a 'variable' from the library........ am i understanding your statement properly?

the same issue presents with the second portion. I am trying to replace "joint" with "azimuth" but i am getting a string instead of a variable reference.......

If i am correct in understanding you.. how would you recommend i make my call to be more functional? I am just trying to refine my coding skills so i am looking for more efficient ways to do things.

Thanks for your help.
163  Using Arduino / Programming Questions / ps2x in functions? on: November 19, 2011, 09:56:50 pm
I have an arm from Lynxmotion i am controlling with my Mega1280 using an SSC-32 from lynxmotion.

The general control scheme in my working code looks like this

 
Code:
if (ps2x.Analog(PSS_RX) >= 0 && ps2x.Analog(PSS_RX) <= 127){      // If (Right joystick is left of center) do the below items
    azimuthVal = map (ps2x.Analog(PSS_RX),0,127,jointSpeed,0);   // Adjusts the speed at which the joint moves relative to the                  
                                                                         amount of joystick used | To change the jointSpeed modify
                                                                         the value of the variable
    azimuthPos = azimuthPos - azimuthVal;                                 //  Take the current position of the Azmiuth joint and subtract
                                                                                               the value needed to adjust it to the new position
     if (azimuthPos <= 600){                                    // If the value makes it to the lower limit of the possible swing of the servo
     azimuthPos = 600;                                          //  stop the counter at this value
     }
    
    Serial1.print("#1 P");                                      // Making string for SSC-32: Azimuth is Servo #1, P indicates the positioning wanted
    Serial1.println(azimuthPos);                                //  Positioning value needed to move the servo to    
  }

  if (ps2x.Analog(PSS_RX) >= 129 && ps2x.Analog(PSS_RX) <= 255){               // Same as above but move joystick to the right
                                                                                                              instead of left
    azimuthVal = map (ps2x.Analog(PSS_RX),255,129,jointSpeed,0);        
    azimuthPos = azimuthPos + azimuthVal;                      
     if (azimuthPos >= 2400){                                    
     azimuthPos = 2400;                                          
     }
    
    Serial1.print("#1 P");                                          // Azimuth Servo is #1  
    Serial1.println(azimuthPos);                                    
  }

I have this set up for all of the servos on the arm. I call them azimuth, shoulder, elbow, wrist, and jaw. All is well with that program. It's just quite a few repetitions of the above code. I have done a proof of concept now and was looking to get better at coding so i decided to see if i could condense the long form version of the program and make a function for analog functions and a function for the digital functions.

i was hoping for something like:

Code:
analogMotion(ps2x.Analog(PSS_RX), azimuth, 600, 2400, 1);

void analogMotion(String analogStick,String joint,int lowStop,int highStop,int servoChannel){
  
  if (analogStick >= 0 && analogStick <= 127){
    jointVal = map(analogStick, 0, 127, jointSpeed, 0);
    joint = joint - jointVal;
    
    if (joint <= lowStop){
      joint = lowStop;
    }
    
    Serial1.print(35, BYTE);  //prints # to Serial
    Serial1.print(servoChannel, BYTE);   //prints the proper servo channel number for ssc-32
    Serial1.print(32, BYTE);  // prints a space
    Serial1.print(80, BYTE);  // prints the letter P
    Serial1.println(joint);  //Print the numeric value for the servo position and a <CR>
    
  }
  
  if (analogStick >= 129 && analogStick <=255){
    jointVal = map(analogStick, 255, 129, jointSpeed, 0);
    joint = joint + jointVal;
    
    if(joint >= highStop){
      joint = highStop;
    }
    
    Serial1.print(35, BYTE);  //prints # to Serial
    Serial1.print(servoChannel, BYTE);   //prints the proper servo channel number for ssc-32
    Serial1.print(32, BYTE);  // prints a space
    Serial1.print(80, BYTE);  // prints the letter P
    Serial1.println(joint);  //Print the numeric value for the servo position and a <CR>
    
  }
}
  

I have tried different types where you see String but can't seem to make it work. Any suggestions on how i could use a function for my movements and call out a certain button in the ps2x library properly? I can't seem to find a way to drop something like ps2x.Analog(PSS_RX) into the call of the function.

Any help is appreciated.......
164  Using Arduino / Project Guidance / Re: steering question on: February 21, 2011, 10:32:13 am
Assuming you are using a servo (because your adjustments are listed in degrees) this page may also help.

http://www.arduino.cc/playground/ComponentLib/Servo
165  Using Arduino / Programming Questions / Re: please help?? on: February 21, 2011, 09:56:59 am
Ok. As an 'ok' programmer at each Labview and Arduino i will attempt to at least shine a little light on your issue to help you understand what's happening.

The 0 to 5 volts you are referring to is not a PWM Output in the way you are describing it. It is an Analog Input. Labview will not output those analog inputs the way you expect and give you fine control of the LED unless you use a floating point variable and the use the map command to limit that number into the 0 to 255 range which makes it make it a bit more of a pain than it needs to be.

Labview, without seperate external digital to analog conversion hardware, cannot output an analog 0 to 5 volts directly. You will be wanting Labview to output a Serial string containing the PWM value you wish to output. You then set up your arduino to take the number provided by this serial string and set it to a variable, that variable will then be written as an analog.write to the pin controlling your LED.

so if your VI has a slider you want to be set to adjust the brightness of an LED. You set the slider min to 0 and max to 255 (Range of an 8 bit PWM signal). The set point of that slider then get output via serial string on the proper comm port.

I have a bit of code i was playing with while in a labview class a few years ago, It need a little tweaking for proper reading of the serial string but you may be able to get a general idea of whats happening. (This VI has 3 sliders Red, Green, and Blue.  The output serial string is in the format "Rxxx,Gxxx,Bxxx" where xxx is the color value 000 to 255.

Code:
int red = 5; // Set pins for output
int green = 7;
int blue = 6;

char testVal = 0;

int buf1 = 0; // Buffer spaces for 000 to 255
int buf2 = 0;
int buf3 = 0;

int redVal = 0; // To hold LED value
int blueVal = 0;
int greenVal = 0;

void setup (){
 
  pinMode (red, OUTPUT);
  pinMode (blue, OUTPUT);
  pinMode (green, OUTPUT);
 
  digitalWrite (red, LOW); //LED's all off
  digitalWrite (blue, LOW);
  digitalWrite (green, LOW);
 
  Serial.begin(9600);
}

void loop () {
 
  if (Serial.available () > 0 ){ // Any chars wating to be read?
    testVal = Serial.read ();
   
 if (testVal == 'r'){
       
        buf1 = Serial.read(); // the Serial.read command brings the characters in as their ASCII equivilant so is stores as an intiger
        buf1 = buf1 - 48;     // 1 becomes 49, 2 becomes 50, 7 becomes 55, etc. this line subtracts 48 to give the digit it's numeric value
        redVal = buf1;
       
        buf2 = Serial.read();
        buf2 = buf2 - 48;
        redVal = (buf1 * 10) + buf2; // Converts two individual numbers into a two digit value. For example 2 then 5 would become 25

        buf3 = Serial.read();
        buf3 = buf3 - 48;
        redVal = ((buf1*10) + buf2)*10 + buf3; // Converts two individual numbers into a three digit value. For example 25 then 3 would become 253
       }
       
       Serial.print("Red:"); // Serial Print for DEBUG and as feedback to Labview VI Display box
       Serial.println(redVal);
     
    if (testVal == 'b'){
       
        buf1 = Serial.read();
        buf1 = buf1 - 48;     
        blueVal = buf1;
       
        buf2 = Serial.read();
        buf2 = buf2 - 48;
        blueVal = (buf1 * 10) + buf2;

        buf3 = Serial.read();
        buf3 = buf3 - 48;
        blueVal = ((buf1*10) + buf2)*10 + buf3;
       }
       
       Serial.print("Blue:");
       Serial.println(blueVal);
       
     if (testVal == 'g'){
       
        buf1 = Serial.read();
        buf1 = buf1 - 48;     
        greenVal = buf1;
       
        buf2 = Serial.read();
        buf2 = buf2 - 48;
        greenVal = (buf1 * 10) + buf2;

        buf3 = Serial.read();
        buf3 = buf3 - 48;
        greenVal = ((buf1*10) + buf2)*10 + buf3;
       }
       
       Serial.print("Green:");
       Serial.println(greenVal);
       
  }
     
     
   analogWrite (red , redVal); // Ouput color value to pins
   analogWrite (blue , blueVal);
   analogWrite (green , greenVal);
   
   delay(50); // Delay 50ms
   
}
Pages: 1 ... 9 10 [11] 12