Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Problem with unojoy and potentiometer range on: September 10, 2013, 03:35:53 pm
Woah woah woah woah woah; you don't want to mess around in the UnoJoy.h file; you'll break everything forever. Well, not really, but you won't fix anything, and it won't work until you change that back to what it was.

<boring explanation>
What that :8 and :16 are are lengths of bitfields that the UnoJoy library is sending over to the code on the ATmega8u2, and ultimately turning that into controller data. When you changed it from 8 to 16, you were telling the UnoJoy library 'I'm sending 16 bits of data in my X axis now', but the ATmega8u2 chip doesn't know that, so it's using the first 8 bits of data you're sending for the X axis, then the next 8 bits for the Y axis.
</boring explanation>

So, all the changes you want to make are going to be in the UnoJoyArduinoSample.ino file (which you should Save As... something else, so you'll still have the original sample reference implementation intact when you want to make something else).
You're on the right track when you're looking at the
Code:
// Set the analog sticks
  //  Since analogRead(pin) returns a 10 bit value,
  //  we need to perform a bit shift operation to
  //  lose the 2 least significant bits and get an
  //  8 bit number that we can use 
  controllerData.leftStickX = analogRead(A0) >> 2;
  controllerData.leftStickY = analogRead(A1) >> 2;
  controllerData.rightStickX = analogRead(A2) >> 2;
  controllerData.rightStickY = analogRead(A3) >> 2;
block - In this block, you're setting the values you want the controller axes to be at. All of the stick axes UnoJoy uses are 8 bits long, so we need to make sure that we're giving it 8 bit data.  That's why this code takes the raw analogRead data and shifts it over by 2 bits, turning a 10 bit value into an 8 bit value.

What you want to do is to take the range of values that your potentiometer actually gives you and map that to the range that UnoJoy can use (0 to 255). For that, I'd use the map() function built into Arduino.
http://arduino.cc/en/Reference/map
So, figure out what range of values your pot sends out (look in the Examples->Basics->AnalogReadSerial), then put in some code like:

Code:
uint8_t lStickX = map(analogRead(A0), whatever your minimum was, whatever your maximum was, 0, 255);
LStickX = constrain(LStickX, 0, 255); // Make sure you don't have too high or low a number
controllerData.leftStickX = lStickX;

Anyhow, that should map the values your Arduino actually sees to the values you want the controller to give. Hope it helps!
-Chatham
UnoJoy.com
2  Using Arduino / Microcontrollers / R3-compatible dfu-programmer binary for OSX on: May 25, 2012, 01:26:27 am
Hey there - for any of you out there allergic to source code distributions like me, I've put together a neat little zip file with the dfu-programmer application for re-flashing the Arduino Uno's communication chip (the ATmega8u2 on the R1 and R2 Unos, and the ATmega16u2 on the R3).  It includes the patch for the ATmega16u2, AND some installers for libusb for both Snow Leopard and Lion.  Hopefully this saves somebody a few hours of hunting down the source, installing XCode, figuring out the patch...

http://code.google.com/p/unojoy/downloads/detail?name=OSX-dfu-programmer-binary.zip&can=2&q=#makechanges
3  Forum 2005-2010 (read only) / Interfacing / Re: Playstation Controller on: June 19, 2008, 02:51:26 am
Wow, thanks Ben!  That's going to help me alot I think!  Mostly, I'm pretty new to messing with low-level stuff - I'm coming in from a Python/Java background (also an Economics major background), so the more EE stuff of these projects is all new stuff to me.  Thanks though, and I'll try and get some controller emulation stuff done up.
4  Forum 2005-2010 (read only) / Interfacing / Re: Playstation Controller on: June 18, 2008, 07:39:20 pm
Hi there -

So I'm basically working on the opposite of your project, that is, making a controller to interface with a PlayStation 2. I feel like the code you've got posted seems like it'd be able to do the job with a couple of modifications, but I don't really understand what it's doing exactly...

Really, it's these lines that I don't really understand -

#define PS2PORT PORTB
#define PS2IN PINB
#define CTRL_CLK 20
#define CTRL_BYTE_DELAY 20

...

#define SET(x,y) (x|=(1<<y))
#define CLR(x,y) (x&smiley-cry~(1<<y)))
#define CHK(x,y) (x & (1<<y))
#define TOG(x,y) (x^=(1<<y))


I think if I knew what was going on in those lines, I could pretty easily figure out how to modify the rest of the program to emulate a controller instead of a playstation...So if anyone could help me out, it'd be  a great help!
Pages: [1]