Show Posts
Pages: 1 ... 8 9 [10] 11 12
136  Using Arduino / Programming Questions / Re: why use longs? on: January 14, 2012, 08:34:04 pm
I'm confused...

Code:
void f() {
    unsigned int a = 1;
    unsigned int a = 2;
}

sketch_jan14a.cpp: In function ‘void f()’:
sketch_jan14a.cpp:15:18: error: redeclaration of ‘unsigned int a’


Roger that, fixed.

Code:
/* Program set up to work with the LTC1660 8 Channel 10bit DAC chip */


#include <PS2X_lib.h>  //for v1.6

//PS2 initialization values
PS2X ps2x; // create PS2 Controller Class
int error = 0;
byte type = 0;
byte vibrate = 0;

//PS2 input variables
boolean inTetherIn, inTetherOut, inJawOpen, inJawClose, inPanUp, inPanDown, inPanLeft, inPanRight, inGain; //digital function inputs
int inForAft, inLat, inTurn, inVert; //analog funtion inputs
int outForAft, outLat, outTurn, outVert; //analog functions to send to DAC Chip

//Out Pin Assignments
const int outTetherIn = 22;  //Pins to connect to DB25 for digital functions. All functions will be active low.
const int outTetherOut = 23;
const int outJawOpen = 24;
const int outJawClose = 25;
const int outPanUp = 26;
const int outPanDown = 27;
const int outPanLeft = 28;
const int outPanRight = 29;
const int outGainHigh = 30;
const int outGainLow = 31;

const int pinData = 2; //Data, Clock, and Chip Select Pins
const int pinCLK = 3;
const int pinCS = 4;

void setup(){
 Serial.begin(9600);
  
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 
 if(error == 0){
   Serial.println("Found Controller, configured successful");
 }
  
  else if(error == 1)
   Serial.println("No controller found, check wiring, see readme.txt to enable debug.");
  
  else if(error == 2)
   Serial.println("Controller found but not accepting commands");
  
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it.");
  
   //Serial.print(ps2x.Analog(1), HEX);
  
   type = ps2x.readType();
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
       case 2:
         Serial.println("GuitarHero Controller Found");
       break;
     }
 
 pinMode(outTetherIn, OUTPUT);  
 pinMode(outTetherOut, OUTPUT);
 pinMode(outJawOpen, OUTPUT);
 pinMode(outJawClose, OUTPUT);
 pinMode(outPanUp, OUTPUT);
 pinMode(outPanDown, OUTPUT);
 pinMode(outPanLeft, OUTPUT);
 pinMode(outPanRight, OUTPUT);
 
 pinMode(pinData, OUTPUT);
 pinMode(pinCLK, OUTPUT);
 pinMode(pinCS, OUTPUT);
 
 digitalWrite(pinData, LOW);
 digitalWrite(pinCLK, LOW);
 digitalWrite(pinCS, HIGH);
 
}


void loop(){
  
 ps2x.read_gamepad(false, vibrate);          //read controller and set motor to spin at 'vibrate' speed
 
  inTetherIn = ps2x.Button(PSB_L1);          //read digital in's from controller
  inTetherOut = ps2x.Button(PSB_L2);
  inJawOpen = ps2x.Button(PSB_R2);
  inJawClose = ps2x.Button(PSB_R1);
  inPanUp = ps2x.Button(PSB_PAD_UP);
  inPanDown = ps2x.Button(PSB_PAD_DOWN);
  inPanLeft = ps2x.Button(PSB_PAD_LEFT);
  inPanRight = ps2x.Button(PSB_PAD_RIGHT);
  
  inForAft = ps2x.Analog(PSS_LY);
  inLat = ps2x.Analog(PSS_LX);
  inTurn = ps2x.Analog(PSS_RX);
  inVert = ps2x.Analog(PSS_RY);
  
digitalOutput(inTetherIn, inTetherOut, outTetherIn, outTetherOut);
digitalOutput(inJawOpen, inJawClose, outJawOpen, outJawClose);
digitalOutput(inPanUp, inPanDown, outPanUp, outPanDown);
digitalOutput(inPanLeft, inPanRight, outPanLeft, outPanRight);

analogOutput(0, inForAft);
analogOutput(1, inLat);
analogOutput(2, inTurn);
analogOutput(3, inVert);

}

void digitalOutput(boolean button1, boolean button2, int output1, int output2){
  
  if (button1 == true && button2 == false) {
    digitalWrite (output2, HIGH);
    digitalWrite (output1, LOW);
  }
  
  if (button1 == false && button2 == true){
    digitalWrite (output1, HIGH);
    digitalWrite (output2, LOW);
  }
  
  if (button1 == true && button2 == true){
    digitalWrite (output1, HIGH);
    digitalWrite (output2, HIGH);
  }
  
  if (button1 == false && button2 == false){
    digitalWrite (output1, HIGH);
    digitalWrite (output2, HIGH);
  }
}

void analogOutput(unsigned int channel, unsigned int value) {
  unsigned int output = output | channel << 12; //build a new variable and store the channel number as the first 4 bits
               output = output | value << 2; //put the value in place and put 2 0's in the LSB spots since the LTC1660 ignores them
  
  digitalWrite (pinCS, LOW); //Set chip to start pulling data to buffer
  Serial.println ("Chip Select Low");
  
  for (int8_t i = 15; i >= 0; i--){   //check each bit in the command and output them through the data line
    byte pinState = (output >> i) & 1;
    Serial.print (pinState);
    digitalWrite(pinCLK, HIGH);  //cycle the clock pin so the chip knows when to pull in each bit
    digitalWrite(pinCLK, LOW);
  }
  Serial.println("End Command");
  
  digitalWrite(pinCS, HIGH);  //Tell the chip that the command is ended and to complete the command change
  Serial.println("Chip Select High");
  
}
137  Using Arduino / Programming Questions / Re: why use longs? on: January 14, 2012, 08:14:06 pm
Code:
if(button1) {
    digitalWrite(output1, LOW);
    digitalWrite(output2, HIGH);
  }
  
  if(button2) {
    digitalWrite(output2, LOW);
    digitalWrite(output1, HIGH);
  }
  
  if(button1 && button2){
  digitalWrite(output1, HIGH);
  digitalWrite(output2, HIGH);
  }

Better make up your mind what you want to happen if button1 and button2 are both down. First you set the output(s) to LOW, then HIGH.

And what do you want the output to be if no button is down? You haven't got a test for that.


Well these functions will eventually be controlling hydraulic outputs on the ROV. If both buttons are pushed i don't want the circuit to try and open both solenoids (it wouldn't hurt anything but it wouldn't work either).

Maybe i can do this to stop the double working but cover all states.

Code:

  if (button1 == TRUE && button2 == FALSE) {
    digitalWrite (output2, HIGH);
    digitalWrite (output1, LOW);
  }
  
  if (button1 == FALSE && button2 == TRUE){
    digitalWrite (output1, HIGH);
    digitalWrite (output2, LOW);
  }
  
  if (button1 == TRUE && button2 == TRUE){
    digitalWrite (output1, HIGH);
    digitalWrite (output2, HIGH);
  }
  
  if (button1 == FALSE && button2 == FALSE){
    digitalWrite (output1, HIGH);
    digitalWrite (output2, HIGH);
  }

Couldn't you conceivably also just write

Code:
digitalWrite(output1, button1);
digitalWrite(output2, button2);

Not really. If the button is true i want to pull the output low. So Nick's would be more along the line of what i need but wouldn't cover all possible combinations. If someone pressed both buttons it would just toggle them both on an off extremely fast and could potentially be hard on the remote equipment at it opens and closes a solenoid (or tries to).

Code:
unsigned int output = channel << 12; //build a new variable and store the channel number as the first 4 bits
  unsigned int output = value << 2; //put the value in place and put 2 0's in the LSB spots since the LTC1660 ignores them

You declare output twice. Also, the second assignment completely overwrites the first one.

Code:
unsigned int output = channel << 12 | value << 2;


It's not declaring the output variable twice.

The first one sets the first 4 bits of the 16 total bits to the channel number. the second variable set's the other 12 bits to the value of the channel.

Then the whole control word (16 bits of information) is put out on the SPI pins.

*edit - I understand what you are saying, i didn't realize i forgot to insert the bitwise OR logic there to maintain the existing value as well as add in my other value. You are correct, i need to add a couple of |'s to get it to do what i want instead of over writing the entire value. Thanks for pointing it out.
138  Using Arduino / Programming Questions / Re: why use longs? on: January 14, 2012, 06:39:41 pm
Code:
void digitalOutput(boolean button1, boolean button2, boolean output1, boolean output2){
 
  if(button1) digitalWrite(output1, LOW);
  if(button2) digitalWrite(output2, LOW);

Better go through and fix all those up, it's impossible to guess what this is doing with booleans being used everywhere in the context of numbers.

If i'm not mistaken the button states can stay boolean because i am using them as digital button presses.

ANy other stupid mistakes  smiley-confuse

Code:

#include <PS2X_lib.h>  //for v1.6

//PS2 initialization values
PS2X ps2x; // create PS2 Controller Class
int error = 0;
byte type = 0;
byte vibrate = 0;

//PS2 input variables
boolean inTetherIn, inTetherOut, inJawOpen, inJawClose, inPanUp, inPanDown, inPanLeft, inPanRight, inGain; //digital function inputs
int inForAft, inLat, inTurn, inVert; //analog funtion inputs
int outForAft, outLat, outTurn, outVert; //analog functions to send to DAC Chip

//Out Pin Assignments
const int outTetherIn = 22;  //Pins to connect to DB25 for digital functions. All functions will be active low.
const int outTetherOut = 23;
const int outJawOpen = 24;
const int outJawClose = 25;
const int outPanUp = 26;
const int outPanDown = 27;
const int outPanLeft = 28;
const int outPanRight = 29;
const int outGainHigh = 30;
const int outGainLow = 31;

const int pinData = 2; //Data, Clock, and Chip Select Pins
const int pinCLK = 3;
const int pinCS = 4;

void setup(){
 Serial.begin(9600);
 
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 
 if(error == 0){
   Serial.println("Found Controller, configured successful");
 }
   
  else if(error == 1)
   Serial.println("No controller found, check wiring, see readme.txt to enable debug.");
   
  else if(error == 2)
   Serial.println("Controller found but not accepting commands");
   
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it.");
   
   //Serial.print(ps2x.Analog(1), HEX);
   
   type = ps2x.readType();
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
       case 2:
         Serial.println("GuitarHero Controller Found");
       break;
     }
 
 pinMode(outTetherIn, OUTPUT); 
 pinMode(outTetherOut, OUTPUT);
 pinMode(outJawOpen, OUTPUT);
 pinMode(outJawClose, OUTPUT);
 pinMode(outPanUp, OUTPUT);
 pinMode(outPanDown, OUTPUT);
 pinMode(outPanLeft, OUTPUT);
 pinMode(outPanRight, OUTPUT);
 
 pinMode(pinData, OUTPUT);
 pinMode(pinCLK, OUTPUT);
 pinMode(pinCS, OUTPUT);
 
 digitalWrite(pinData, LOW);
 digitalWrite(pinCLK, LOW);
 digitalWrite(pinCS, HIGH);
 
}


void loop(){
 
 ps2x.read_gamepad(false, vibrate);          //read controller and set motor to spin at 'vibrate' speed
 
  inTetherIn = ps2x.Button(PSB_L1);          //read digital in's from controller
  inTetherOut = ps2x.Button(PSB_L2);
  inJawOpen = ps2x.Button(PSB_R2);
  inJawClose = ps2x.Button(PSB_R1);
  inPanUp = ps2x.Button(PSB_PAD_UP);
  inPanDown = ps2x.Button(PSB_PAD_DOWN);
  inPanLeft = ps2x.Button(PSB_PAD_LEFT);
  inPanRight = ps2x.Button(PSB_PAD_RIGHT);
 
  inForAft = ps2x.Analog(PSS_LY);
  inLat = ps2x.Analog(PSS_LX);
  inTurn = ps2x.Analog(PSS_RX);
  inVert = ps2x.Analog(PSS_RY);
 
digitalOutput(inTetherIn, inTetherOut, outTetherIn, outTetherOut);
digitalOutput(inJawOpen, inJawClose, outJawOpen, outJawClose);
digitalOutput(inPanUp, inPanDown, outPanUp, outPanDown);
digitalOuput(inPanLeft, inPanRight, outPanLeft, outPanRight);

analogOutput(0, inForAft);
analogOutput(1, inLat);
analogOutput(2, inTurn);
analogOutput(3, inVert);

}

void digitalOutput(boolean button1, boolean button2, int output1, int output2){
 
  if(button1) {
    digitalWrite(output1, LOW);
    digitalWrite(output2, HIGH);
  }
 
  if(button2) {
    digitalWrite(output2, LOW);
    digitalWrite(output1, HIGH);
  }
 
  if(button1 && button2){
  digitalWrite(output1, HIGH);
  digitalWrite(output2, HIGH);
  }
}

void analogOutput(unsigned int channel, unsigned int value) {
  unsigned int output = channel << 12; //build a new variable and store the channel number as the first 4 bits
  unsigned int output = value << 2; //put the value in place and put 2 0's in the LSB spots since the LTC1660 ignores them
 
  digitalWrite (pinCS, LOW); //Set chip to start pulling data to buffer
  Serial.println ("Chip Select Low");
 
  for (int8_t i = 15; i >= 0; i--){   //check each bit in the command and output them through the data line
    byte pinState = (output >> i) & 1;
    Serial.print (pinState);
    digitalWrite(pinCLK, HIGH);  //cycle the clock pin so the chip knows when to pull in each bit
    digitalWrite(pinCLK, LOW);
  }
  Serial.println("End Command");
 
  digitalWrite(pinCS, HIGH);  //Tell the chip that the command is ended and to complete the command change
  Serial.println("Chip Select High");
 
}
139  Using Arduino / Programming Questions / Re: why use longs? on: January 14, 2012, 06:24:46 pm
Code:
const boolean outTetherOut = 23;

Booleans are true or false, not 23.

I was thinking it is pin 23 but will always be either HIGH or LOW. I was putting it boolean as the state was in my mind not the pin number. it's always the details that snag me up........
140  Using Arduino / Programming Questions / Re: why use longs? on: January 14, 2012, 06:12:35 pm
The byte type is unsigned, therefore it can never be negative, so your loop would never exit (it will always be >= 0).

AHHHHHHHHHHH. That threw me off for a second, brain fart.

I understand what you are saying..

As far as the rest... no fundamental errors jumping out at you?

Thanks very much for your assistance.
141  Using Arduino / Programming Questions / Re: why use longs? on: January 14, 2012, 03:10:45 pm

You hardly need a long to hold a number from 0 to 15. That wastes memory and time. Try:

Code:
for (int8_t i = 15; i >= 0; i--)

in my code i used

Code:
for (byte i=15; i>=0; i--)

would your suggestion be better than that as well?
142  Using Arduino / Programming Questions / why use longs? on: January 14, 2012, 02:42:17 pm
This fine fellow wrote some code to output a serial string to an LTC1660/1665.


When he outputs the serial string he uses this piece of code

Code:
void output(long chn, long val)
{
  //the control word is 16 bits
  //the high 4 bits defines the output channel
  long t = chn << 12;
 
  //the lower 4 bits are don't cares so we make
  //them zeros.
  t = t | val << 4;
  //for LTC1660 it has 10bit resolution this line will
  //need to change to:
  //t = t | val << 2;
 
  digitalWrite(pinCSLD, LOW);
  for (long i = 15; i >= 0; i--)
  {
    long b = (t >> i) & 1;
    digitalWrite(pinIN, b);
    digitalWrite(pinSCK, HIGH);
    digitalWrite(pinSCK, LOW);
  }
 
  digitalWrite(pinCSLD, HIGH);
}
 

I liked the way he output his information in the for loop so i did something similar in my code once i put it together.

I, however, saw no need to use longs as variable types. The control word is 16 bits, an int type value is 2 bytes. So int works fine.... in my mind. Am i incorrect?

My code is below for reference.... am i missing something that would require a long there?

For anyone who is curious.... it will be a ps2 controller input using Bill Porter's library to control some hardware i use at work. The input side on the controller is active low for digitals and analog is a 0 to 5 with 2.5 being "No Command" state.

Code:
#include <PS2X_lib.h>  //for v1.6

//PS2 initialization values
PS2X ps2x; // create PS2 Controller Class
int error = 0;
byte type = 0;
byte vibrate = 0;

//PS2 input variables
boolean inTetherIn, inTetherOut, inJawOpen, inJawClose, inPanUp, inPanDown, inPanLeft, inPanRight, inGain; //digital function inputs
int inForAft, inLat, inTurn, inVert; //analog funtion inputs
int outForAft, outLat, outTurn, outVert; //analog functions to send to DAC Chip

//Out Pin Assignments
const boolean outTetherIn = 22;  //Pins to connect to DB25 for digital functions. All functions will be active low.
const boolean outTetherOut = 23;
const boolean outJawOpen = 24;
const boolean outJawClose = 25;
const boolean outPanUp = 26;
const boolean outPanDown = 27;
const boolean outPanLeft = 28;
const boolean outPanRight = 29;
const boolean outGainHigh = 30;
const boolean outGainLow = 31;

const boolean pinData = 2; //Data, Clock, and Chip Select Pins
const boolean pinCLK = 3;
const boolean pinCS = 4;

void setup(){
 Serial.begin(9600);
  
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 
 if(error == 0){
   Serial.println("Found Controller, configured successful");
 }
  
  else if(error == 1)
   Serial.println("No controller found, check wiring, see readme.txt to enable debug.");
  
  else if(error == 2)
   Serial.println("Controller found but not accepting commands");
  
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it.");
  
   //Serial.print(ps2x.Analog(1), HEX);
  
   type = ps2x.readType();
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
       case 2:
         Serial.println("GuitarHero Controller Found");
       break;
     }
 
 pinMode(outTetherIn, OUTPUT);  
 pinMode(outTetherOut, OUTPUT);
 pinMode(outJawOpen, OUTPUT);
 pinMode(outJawClose, OUTPUT);
 pinMode(outPanUp, OUTPUT);
 pinMode(outPanDown, OUTPUT);
 pinMode(outPanLeft, OUTPUT);
 pinMode(outPanRight, OUTPUT);
 
 pinMode(pinData, OUTPUT);
 pinMode(pinCLK, OUTPUT);
 pinMode(pinCS, OUTPUT);
 
 digitalWrite(pinData, LOW);
 digitalWrite(pinCLK, LOW);
 digitalWrite(pinCS, HIGH);
 
}


void loop(){
  
 ps2x.read_gamepad(false, vibrate);          //read controller and set motor to spin at 'vibrate' speed
 
  inTetherIn = ps2x.Button(PSB_L1);          //read digital in's from controller
  inTetherOut = ps2x.Button(PSB_L2);
  inJawOpen = ps2x.Button(PSB_R2);
  inJawClose = ps2x.Button(PSB_R1);
  inPanUp = ps2x.Button(PSB_PAD_UP);
  inPanDown = ps2x.Button(PSB_PAD_DOWN);
  inPanLeft = ps2x.Button(PSB_PAD_LEFT);
  inPanRight = ps2x.Button(PSB_PAD_RIGHT);
  
  inForAft = ps2x.Analog(PSS_LY);
  inLat = ps2x.Analog(PSS_LX);
  inTurn = ps2x.Analog(PSS_RX);
  inVert = ps2x.Analog(PSS_RY);
  
digitalOutput(inTetherIn, inTetherOut, outTetherIn, outTetherOut);
digitalOutput(inJawOpen, inJawClose, outJawOpen, outJawClose);
digitalOutput(inPanUp, inPanDown, outPanUp, outPanDown);
digitalOuput(inPanLeft, inPanRight, outPanLeft, outPanRight);

analogOutput(0, inForAft);
analogOutput(1, inLat);
analogOutput(2, inTurn);
analogOutput(3, inVert);

}

void digitalOutput(boolean button1, boolean button2, boolean output1, boolean output2){
  
  if(button1) digitalWrite(output1, LOW);
  if(button2) digitalWrite(output2, LOW);
  if(button1 && button2){
  digitalWrite(output1, HIGH);
  digitalWrite(output2, HIGH);
  }

void analogOutput(int channel, int value) {
  int output = channel << 12; //build a new variable and store the channel number as the first 4 bits
  int output = value << 2; //put the value in place and put 2 0's in the LSB spots since the LTC1660 ignores them
  
  digitalWrite (pinCS, LOW); //Set chip to start pulling data to buffer
  Serial.println ("Chip Select Low");
  
  for (byte i=15; i>=0; i--){   //check each bit in the command and output them through the data line
    byte pinState = (output >> i) & 1;
    Serial.print (pinState);
    digitalWrite(pinCLK, HIGH);  //cycle the clock pin so the chip knows when to pull in each bit
    digitalWrite(pinCLK, LOW);
  }
  Serial.println("End Command");
  
  digitalWrite(pinCS, HIGH);  //Tell the chip that the command is ended and to complete the command change
  Serial.println("Chip Select High");
  
}

*edit - After thought...... Before anyone asks. I haven't put together the level shifters for the controller and chip yet for the hardware interface, with probably start on that this afternoon. Just wonder is there is a fundamental issue with my code that could be repaired before i start pulling my hair out later.
143  Using Arduino / General Electronics / Re: Maximum cable length? on: January 11, 2012, 06:46:47 pm
I don't think you should have an issue with 10 feet. best thing to do is get an arduino and one sensor and do some testing to see how your idea works in practice.

I would be very interested in how you would control the temp of individual rooms that sharw a thermostat. maybe servo controlled air baffles?
144  Using Arduino / General Electronics / Re: Control an Xbox 360 controller analog stick on: January 06, 2012, 03:16:14 pm
Absolutely. That looks really cool. It's just nice to see what the end result is. My friend is here now and just read through the posts and says he will get on later and give you a more detailed idea of what he did to get it all working.

*edit. This chip is that he used. http://www.arduino.cc/en/Tutorial/SPIDigitalPot
145  Using Arduino / General Electronics / Re: Control an Xbox 360 controller analog stick on: January 06, 2012, 12:47:27 pm
My typical projects use DAC instead of digital pots. I have not used any specific ones to speak of.

You could probably use a DAC chip if you wanted. My current project is with a LTC1660CN chip.

Quick search shows this guy  (http://forums.hak5.org/index.php?showtopic=13959) intending to use these 256 step ones http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad5206/products/product.html.

Maybe a better explanation of why the stick needs to be precisely held a certain spot would shed more light as to the resolution you need on it. I would say most cases 127 or 256 steps would be fine because most people really cant hold their finger within 1/127th of the joystick swing anyway.
146  Using Arduino / General Electronics / Re: New Member on: January 06, 2012, 10:09:31 am
Very niiiiice.
147  Using Arduino / General Electronics / Re: Control an Xbox 360 controller analog stick on: January 06, 2012, 10:06:55 am
A multimeter is not your best choice of devices to look at a PWM signal.

Essentially a multimeter takes a sample of voltage data over a small amount of time the shows you the average of that information. A pulsed signal or PWM signal will not show you the high or the low it will show you the average reading over the time of the sample.

PWM as you are sending it to my understanding is directly from the arduino. So the processor that is expecting to see a smooth sweep from 0 to 1.5 volts is actually seeing a TTL level signal (5 Volts that it shouldn't see in any case because the controller run on 3.3 if i am not mistaken).

So instead of a constant voltage the controller is seeing:

505050505500550055005500505050055000055500005555000505500550505050

At no time is this voltage ever in the range the controller wants to see.
*edit: I suppose this statement is incorrect, it doesn't mind seeing the 0 volts.....  :-/

This voltage does matter. The resistance (typically) less so. Your statement that a 1K, 100K, or 1M will work is partially correct, but not for the reason you think. The 3 pots you list will take the voltage off the wiper in exactly the same fashion because when the pot is centered up the resistance between the wiper and ground is ==  to the resistance between the wiper and ground. See this Wiki to understand the principle better http://en.wikipedia.org/wiki/Voltage_divider.

Something looking for an analog input may or may not care about the resistance but the voltage absolutely matters unless the 360 controller is doing something completely out of the norm (which is very unlikely as many other people have modded these controllers).

If you take a chip that expects to see an analog voltage, that's what it knows how to handle, and give it the above string of on's and off's it won't be able to decipher that information. That is why there are chips that accept PWM and chips that accept  analog in... but rarely is it in one chip and i have never seen one where it is on the same pin.

It may be possible to do with the capacitor to filter the PWM which functionally makes the PWM into an analog voltage as long as you narrow the output voltage into the range the controller is expecting to see. This would involve doing some research on how best to set it up, what resistor you would want in line, and which type/rating of cap will best suite the purpose.

Could you post some links to these multiple forums that say the voltage doesn't matter? I would be very interested in what they are doing to make that statement true.

Personally if I couldn't find 1.50 in the couch to buy a chip and do the job then i would probably postpone until a better time to tackle projects. But that's just me.

Similar issue from the archived forums.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285266211

148  Using Arduino / General Electronics / Re: software for electrical diagrams on: January 05, 2012, 10:43:18 pm
expresspcb.com is really handy for drawing up simple things for discussions.

Eagle from cadsoft for designing boards.

I use both, depending on what I am doing.



x2 on express pcb. fairly intuitive and easy to make new  components. not professional grade but for free software it very nice.
149  Using Arduino / General Electronics / Re: Control an Xbox 360 controller analog stick on: January 05, 2012, 10:24:15 pm
a few points.

1. using analog write for a value of 127 is a duty cycle of 50%. NOT the same as the middle of a pot.

2. the voltage into the pot absolutly makes a difference in what you need to make your controller work.

3. a digital pot induces much less noise and a smoother transition than you will see with filtered pwm.

the controller processor is expecting a voltage sweep from 0 volts to 1.5 volts according to your information so the sweeper of the pot should sit at .75 at null. the best way to do this ,that I know of, is a digital pot.

I know a guy who got a wiimote to work with his xbox 360 using this method and he said it was very
 smooth with the digital pot using the tap in method you are describing.

digital pot at sparkfun

http://www.sparkfun.com/products/10613
150  Using Arduino / Programming Questions / Re: Parsing serial input on: December 15, 2011, 09:48:16 pm

This subject comes up so often I did a forum post about it here:

http://www.gammon.com.au/forum/?id=11425

Using delay is going to slow the program down for sure. Using the technique I show in the post above doesn't.

Side note, same subject. In your code you have this

if (input_pos < (MAX_INPUT - 1))

why is this better than

if (input_pos <= MAX_INPUT)

Just curious if one is more efficient than the other
Pages: 1 ... 8 9 [10] 11 12