Control a joystick without switching input?

Hello everyone! Been playing with this Arduino Uno project for about a year now, and I have hit a brick wall. The project is pretty much a macro maker, so you press some buttons, and then it can play them back. I was feeling pretty good about it until I entered the world of analog!

I should probably say this first, I have experience programming, but my electronics experience is definitely lacking - I am learning fast though!

I am having an issue trying to read an analog wire, and then write back to it with the same value - the analog being a joystick's x or y value (wires just soldered to the x and y output of the joystick's potentiometer). The joystick that I have been testing with is a Gamecube controller joystick.

My set up is very similar to the one here:, but I am reading the analog value as well as writing. I have an Arduino Uno that I use to read in the value, and a digipot to write the value.

Everything looks good - so if I read in a value of 128 and I write a value of 128, it is the same voltage when leaving the digipot.

The issue is (I think), that the digipot is turned off when I am not using it, so it doesn't affect the read in voltage (good). When I write a value though, the actual potentiometer in the joystick is affecting that voltage I am writing, causing it to be incorrect (bad).

Is there a way to get the value I am writing to be correct (the same as the voltage I read in), with the joystick's potentiometer still connected?

I've seen 3DS mods that seem to be able to do this for their analog stick, like the the one here: Gamecube controller mod - Page 11 -

If someone could point me down the right path, that would be great. Thank you!

  1. Start by posting the code you are using.

  2. What values do you need to read from the joysticks. For instance, full left, middle, full right.... or every little step from full left to full right?

  3. I would think that the joysticks would produce a middle voltage when in the Neutral position so, if the range is 0 to 5 volts the middle position would read 2.5 volts. If this is true, I would set my starting Digipot voltage to 2.5 volts.

  4. I think the technique that would work the best if I was writing the code, would be to write it in the style of a Switch statement. Look at the example provided with Arduino IDE with the name Switch statement.

Good luck,
The more information and work you share, the more help you will get.

Thanks for the quick reply!

Sorry for not including all the info - I've been working on the project for a while now, and I was trying to see if I could isolate this one issue that I am having.

  1. The code is pretty long and ugly and is in multiple files. I don't think there is any issue with the code, I think the problem is my limited knowledge of electronics...

  2. The Arduino Uno can read 1024 bits of precision, so I would like to use all of that precision (need to get a better digipot eventually or better yet, figure out how to use a DAC). So, yes, it will be every step from full left to full right.

  3. Correct, the joystick has a middle voltage when in the neutral position. I think this is where my issue is coming from. The joystick is giving the controller the 2.5 middle volts, and then if I want to give the controller 0.5 volts to make the controller think you are moving it to the left, the values won't be 0.5 because of the voltage coming from the joystick. That is basically my question, if there is a way to get this to work with them both connected and not having to switch off the joystick when writing values.

  4. Not 100% sure what you mean here. Do you mean a switch statement in code? Like:
    switch (variable)
    case 1:

Thanks for the help so far. I'll keep trying to figure out a solution...

Edit: I was told an IDAC may be able to accomplish this. I'll have to do some researching to figure what exactly an IDAC is and how to use it... That may have solved my question...


  1. The code is pretty long and ugly and is in multiple files. I don't think there is any issue with the code, I think the problem is my limited knowledge of electronics...

But it might help us figure out what's going on in your project.

Another thing that might help even more would be a simple schematic.

You are probably right - I'll try to round up the code relevant to the question and post here.

I'll do my best to get you a schematic - I've never made one before...

I'll post back soon. Sorry, I seem to be doing a bad job at helping you guys help me...

OK, I trimmed out the code to be a very small example of (basically) what I am doing. Here it is:

#include <SPI.h>               // Used for SD, and DAC currently

#define DAC_CHIP_SEL 9

void setup()
	// This is initializing the DAC's chip select
	digitalWrite(DAC_CHIP_SEL, HIGH);
	while (true)
		// Do this to read in the values...
		int val = analogRead(A4) / 4; // Have to divide by 4 here since digipot can only do 256 steps and Uno's ADC is 1024 steps

		// And then at a later time, I try to write the values back...
		digitalWrite(DAC_CHIP_SEL,LOW); // take the SS pin low to select the chip:
		//  send in the address and value via SPI:
		digitalWrite(DAC_CHIP_SEL,HIGH); // take the SS pin high to de-select the chip:

I found a program called Fritzing that helped me make a picture to show how it is all hooked up. It is attached. The digipot I’m using is actually the same one used in this arduino example:

A little bit more info: The Gamecube controller is powered by the actual Gamecube system when it is plugged into it, and is 3.43 volts. So, when the joystick is centered, the Y is somewhere around 1.7V when I test with a multimeter (as is the X of course - I’m just trying to get one direction working first).

I assume the issue would be in the way I have everything hooked up. I feel that what I am trying to do is possible though, since I have seen it done with other Joysticks (like the Nintendo 3DS here: Controller mod installations from GumMods - - it works with two analog sticks being able to control the same thing). I could be assuming wrong that the joysticks for the 3DS and Gamecube work the same though.

Again, I think the issue is that when I write those read-in values, the potentiometer in the actual joystick is still connected and is affecting that value. I’m trying to write that value back with the joystick still connected. Also, precision is very important to me here - it won’t work if that value is even slightly off.

Please let me know if you need any other information - I didn’t come this far to be stopped by a little analog! Thank you for the help thus far!

I can see two ways to get this to work.

  1. Arduino can control the joystick entirely. This means that the joystick no longer connects to the console. It connects to Arduino, Arduino reads it, and Arduino sends the info out to the console. That way, you have the choice at any point in the code to either simply pass through the reading from the joystick or to ignore that reading and send the commands you want.

  2. Arduino would need some sort of control over a component that could effectively disconnect the joystick while Arduino is sending the commands. Perhaps some sort of multiplex chip so you can choose from code to have the joystick OR the Arduino connected to the console but not both.

That makes sense. I was trying to see if there was a way around it, but hey, if it works it works. I've never heard of a multiplex chip before, so I will definitely take a look at that.

This way is probably much more precise anyway. Thanks to everyone for the help!

I've never heard of a multiplex chip before,

When you search for it it will probably be called a "Mux/Demux"

Here's one example, but it has a 3.6V limit so it might not be the exact one you need.

Delta_G already suggested my top two possible solutions.

  1. Have the Arduino either pass through the input from the joystick or send it's own data.

  2. Use an analog demux chip. I have one of the retired ones from SparkFun and was really surprised how well it worked.

I have a third idea which is more of a variation on the demuxer. Instead of using a chip to switch signals, you could use a relay. The relay default position could pass the joystick's output through to the controller but when the Arduino wanted to override the joystick's output, it could switch the signal source with the relay.

There are latching relays which only require power to change position. If your device is battery operated, you might want to use latching relays.

If you use relays, you need some additional components. Don't try to control a relay directly from an I/O pin.

Are you sure you need a Digipot to simulate the joystick? Have you tried just sending an analog output to the position where the pot's wiper would connect?

I have a Gamecube controller on it's way from an ebay seller. I recall really liking the analog shoulder triggers.

Most of the buttons on the PlayStation 2 are pressure sensitive but the trigger buttons don't have the same travel as I remember the Gamecube's trigger having. I borrowed a Gamecube controller a few years ago and I remember being impressed by the analog triggers.

I just thought of a fourth idea for switching between joystick control and Arduino control. It's similar to Delta_G's idea #2 (as I numbered them) in that the Arduino would be in constant control of the output. Instead of having the Arduino simulating an analog output, have the Arduino simulate the digital output of the controller.

The GameCube and PlayStation 2 controllers use a protocol which shouldn't be too hard for a microcontroller to produce. Instead of monitoring the joystick's analog output, just tap into the digital stream and substitute new data into the stream when you want.

This fourth alternative would likely be the easiest method to implement as far as hardware goes but the software would be a little more involved.

I personally don't play video games since I don't trust myself to use moderation while playing them and I can see myself spending most of the day playing a game I really liked. My main interest in game controller is to use as input devices for robots.

Here's link to a list of a couple of my robots. I asked about controllers people liked in this thread. Apparently the XBox 360 is a nice controller. Unfortunately the XBox 360 controller's protocol isn't easy for a microcontroller to read much less imitate.

I went on about this longer than I had planned. Hopefully I didn't go too far off topic.

Thanks for all the info DuaneDegn!

Your fourth idea is something I will definitely be working on just because it looks super cool. My day job is programming, so the extra software complexity shouldn't be an issue. It will work wonders for a gamecube controller since all that information is going to the console through one wire. I am doing all my testing on the gamecube controller since I have a bunch of them and I can afford to fry a few while testing. My ultimate goal is to get this working in a Nintendo 3DS, which is a handhold device and doesn't have that super-cool one wire thing though.

When I was looking at switching, I think I was going to try to get a JFET (pretty sure that is what is was), since relays were pretty bulky. I'd have to take another look at it. To keep things simple, I was actually thinking of doing my switching manually, having a little jumper to go from controller or arduino (like those old computer motherboards and those "master" "slave" select things).

Personally, I love the gamecube and playstation 2 controllers. I probably play too much video games, but at least I am using that passion to fuel learning more about electronics!

Are you sure you need a Digipot to simulate the joystick? Have you tried just sending an analog output to the position where the pot's wiper would connect?

I think I am reading this question right (let me know if I am running down the wrong path). The arduino PWM signals work great for things like LEDs, but since it is not a "true" analog signal, I don't get the correct result. I need something to get a correct, steady voltage, be it a filter, a digipot, or a DAC. At least that is my understanding.

Again thanks for the help! Feel free to ramble some more - I don't mind listening to the ramblings of one that knows a thing or two about electronics!

If you were going to stick with the GameCube controller, I'd think taking control of the data line is the most elegant solution but as you point out, this strategy isn't likely to work on the 3DS.

The JFET idea seems like a good one. I'm guessing that's pretty close to how this optical relay would perform.

You understand what I mean about using the Arduino's analog output directly. I agree the analog output isn't the same as the output from a pot or DAC but I wonder if it would work. Maybe a high PWM frequency with a cap to smooth out the voltage (I'm very unsure this would work).

It's been awhile since I've purchased a digital pot but I think digital pots cost more than DACs. You might be able to save some money by using a DAC instead of a digital pot. Nope, I just checked. Digital pots aren't as expensive as I remembered. Here's a 7-bit digital pot for $0.56. This one has two 8-bit pots in one chip for $2.72. Most of the game controllers I've tried use 8-bits of data for each axis of the joystick so you wouldn't need a pot with more than 8-bits of resolution. (One wired PS2 clone I tried had 5-bits of data on each axis but it was scaled to 8-bits.

Personally, I love the gamecube and playstation 2 controllers.

I haven't received the GameCube controller I ordered yet but I've received two different wireless PlayStation 2 controllers. Both of the PS2 controllers are junk.

The wireless PS2 controllers have three large dead zones on each axis of the joysticks. There's a large dead zone in the center of the joystick and large dead zones at either extreme of the joystick. All the analog control is compressed to a very small range of motion.

These large dead zones are a result of the controller's firmware and not caused by the physical characteristics of the pots used in the joysticks. I can't figure out why they would cripple the control with firmware.

The joysticks are so bad on these wireless PS2 clones, I think it would be easier to use the pressure sensitive buttons for proportional control than using the joysticks for proportional control.

As long as you don't mind my ramblings, I'll mention my intention of making my own controller sometime.

I'm not sure all I'd like in a controller, but I'm pretty sure, I'd like to get rid of the pots in the joysticks. Pots wear out. I'd really like to have a joystick which doesn't wear out.

I've played with some magnetic encoders and I've wondered about using these to replace pots. Apparently the PS3 controller used Hall effect sensors in its pots. My first post to the Arduino forum was to bump an old thread about these Hall effect PS3 joysticks. It would be nice if these 4-pin "pots" were easy to use. As I mentioned in the other thread, I think these joysticks will require an opamp of some sort. I don't know enough about this stuff to make these work yet.

Here's a link to one of my many unfinished projects. I was attempting to combine a PlayStation 2 controller with a touchscreen. I used a wired version of a Sony PS2 controller. I used a Nordic nRF24L01+ module for wireless communication. One of these days, I'll get back to work on the project.

If you get a chance to take pictures of the mods you're making, it would be fun to see them. A video would also be fun.

I hope you keep us updated on how your project is coming along.

Apparently the PS3 controller used Hall effect sensors in its pots

That is pretty crazy - I haven't messed with a PS3 controller yet, but if I do, that will definitely be something to take a look at.

Funny how you have used a touch screen with your PS2. The Nintendo 3DS has a touch screen, and as soon as I figured out a good solution to the joystick analog problem I was having, I was going to see if I could record/playback touch screen events. I haven't looked into it much yet, but it shouldn't be too tough (though I thought the same thing about analog, and it has been pretty tough, heh).

Sorry to hear about your negative experience with the wireless PS2 controllers! I honestly haven't used them for anything other than playing on the Playstation 2, and they work great there. I am pretty sure I have a Logitech wireless controller and I love that one.

I will definitely be posting a video or something somewhere when I get all this stuff working the way I want. It might be a long while though. I should probably take an electronics class or something; this is my first electronics project, and every time I run into a problem (and there are LOTS of problems), it takes me a while to figure it out. That and I don't have unlimited time to work on it. I'll finish it one day though!