lunarkingdom
Posts: 127
Joined: Sun Jul 20, 2014 3:38 am

How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 3:56 am

Hello,

I was wondering if it would be possible to run two 2 channel analog joysticks from the GPIO header on the Raspberry Pi B+ model with 40 pins, in anticipation I have bought 2 of the MCP3002 A to D converters as well as two 2 channel analogue joystick controllers. I was also wondering how many grounds can be routed to each ground on the GPIO as in what is the maximum. I am trying to make a game system to run emulated games that has both player 1 and player 2 controls on my pI B+, any help would be most appreciated. Thank you for your time.

Lunarkingdom

NBonaparte
Posts: 9
Joined: Tue Jul 01, 2014 4:33 am

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 4:52 pm

I think it would be easier to use two comparators (LM339) for each of the analog joysticks (like Adafruit did with Cupcade: https://learn.adafruit.com/cupcade-rasp ... ce-circuit).

User avatar
mikronauts
Posts: 2740
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 5:32 pm

I'd use a single MCP3208, actually a MCP3008 (10 bit version) should work well enough.

I am running four analog joysticks on my "The Better Mousetrap Servo Tester", using an MCP3208 on RoboPi - works great.

http://www.mikronauts.com/the-better-mo ... vo-tester/

TBMST is not connected to a Pi (yet), but the usage for an MCP3208 would be the same. Just use one of the SPI ports.

If you are sure you just need two joysticks (four A/D channels) and eight bit resolution is enough, there are tons of cheap PCF8591 breakout boards on Ebay, and WirinPi supports them.

http://wiringpi.com/extensions/i2c-pcf8591/
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

lunarkingdom
Posts: 127
Joined: Sun Jul 20, 2014 3:38 am

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 5:45 pm

that is awesome but it seems he is only using one analogue joystick and as far as I could tell he uses a breakout board to solder the leads to and the numbers on it do not seem to match the gpio pins:

Image

The whole reason I wanted to know how to wire it up is I saw this video:

https://www.youtube.com/watch?v=I20lXAS_IJs

his website explains what pins he used for the A to D converter:

http://www.newsdownload.co.uk/pages/RPi ... stick.html

and specifically he uses:

Raspberry Pi MCP3002
3V3 VDD / Vref (Pin 8)
SPI0 CE1 (GPIO 7) N/C
SPI0 CE0 (GPIO 8) CS (Pin 1)
SPI0 MISO (GPIO 9) Dout (Pin 6)
SPI0 MOSI (GPIO 10) Din (Pin 5)
SPI0 SCLK (GPIO 11) CLK (Pin 7)
GND VSS (Pin 4)

PSP Joystick MCP3002
3V3 VDD / Vref (Pin 8)
X Axis CH0 (Pin 2)
GND VSS (Pin 4)
Y Axis CH1 (Pin 3)

The problem I see is that there are only one set of these on the GPIO or one of each and they are all used for the ONE dual channel (2 axis) A to D convertor:

SPI0 MISO (GPIO 9)
SPI0 MOSI (GPIO 10)
SPI0 SCLK (GPIO 11)

You can see the pinout from the B+ model GPIO here:

Image

So in conclusion do they make a 4 channel A to D chip that will run off of the single B+ Pi's GPIO or do I have to go with a digital pair of joysticks to make the whole thing easier?

OBTW I still want to know if there is a limit of grounds we can attach to any of the ground poles seen in the image above, there would be no more than 4 per each probably less but from my reading I have seen a couple people express that they did not want to overload the ground, should I b worried about this or can I hook up to 4 grounds each?

lunarkingdom
Posts: 127
Joined: Sun Jul 20, 2014 3:38 am

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 5:48 pm

mikronauts wrote:I'd use a single MCP3208, actually a MCP3008 (10 bit version) should work well enough.

I am running four analog joysticks on my "The Better Mousetrap Servo Tester", using an MCP3208 on RoboPi - works great.

http://www.mikronauts.com/the-better-mo ... vo-tester/

TBMST is not connected to a Pi (yet), but the usage for an MCP3208 would be the same. Just use one of the SPI ports.

If you are sure you just need two joysticks (four A/D channels) and eight bit resolution is enough, there are tons of cheap PCF8591 breakout boards on Ebay, and WirinPi supports them.

http://wiringpi.com/extensions/i2c-pcf8591/
Ahhh Mikronauts! that is awesome, off to read all your good stuff I will chime in when I am done thank you!

lunarkingdom
Posts: 127
Joined: Sun Jul 20, 2014 3:38 am

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 5:57 pm

so it seems you use one of these to run the analog joysticks?

http://quick2wire.com/products/quick2wi ... board-kit/

There was no documentation on that site to wire it to a B+ or any Pi for that matter I could find. Did you use one of these or more than one to use 4 joysticks?

lunarkingdom
Posts: 127
Joined: Sun Jul 20, 2014 3:38 am

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 6:20 pm

ahhh I see there is a primary board ahead of this chip that is bigger than the Pi? Rats, I am already running out of project space and am not sure if I can make more space for this, anyway I still would like to know specifically how to control 2 analogue joysticks from one Pi as I already have the parts and will be using them in another project (handheld Pi Gaming portable) in the very near future.

I ordered 2 of these just in case:

Image

http://www.digikey.com/product-detail/e ... ND/2138044

Is there a previous post that explains how to hook up digital buttons and joysticks? I bought a breakout board but am just stealing the wiring from it to save space:

Image

I am looking at 12 to 16 buttons and 2 joysticks for this build, that is for two controllers so on each controller will be 4-6 action buttons, 1 start, 1 select and a 5 pin joystick each (up, down, left, right and ground). Anything that simplifies me hooking them all up and interfacing them with the pi would be awesome. I appreciate the help guys, I really do, I am glad to have joined your community!


User avatar
mikronauts
Posts: 2740
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to run 2 analog joysticks from GPIO header Pi B+

Sun Jul 20, 2014 8:34 pm

I've used that cheap PCF8591 board, but prefer the MCP3208... if you want to use the PCF, run it at 3.3v and just attach it to the Pi's SDA and SCL lines, and GND.

http://www.arne.jachens.de/RaspberryPi#InADC

The link above will help you. If you can, run the MCP3208 at 3.3v, otherwise if you need to run it at 5v, divide MISO down as follows:

MISO from ADC -> 4k7 resitor to ground AND 2k4 resistor to the 0-5V analog input

For all your buttons, add an MCP23S17 with the other Pi chip select.

You can google for MCP3208 and MCP23S17 tutorials, schematics, etc., for the Pi
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Rushlight
Posts: 19
Joined: Wed Jun 01, 2016 7:37 am

Re: How to run 2 analog joysticks from GPIO header Pi B+

Thu Sep 22, 2016 5:55 am

Along a similar topic; im looking for the most minimal (and cheap) method ofof connecting a single analog thumbstick (VCC,X,Y,GND) to a Pi GPIO?

User avatar
mikronauts
Posts: 2740
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How to run 2 analog joysticks from GPIO header Pi B+

Thu Sep 22, 2016 4:55 pm

MCP3008 (you could use 3004, but it never hurts to have spare analog inputs)
either run at 3.3v, or divide MISO as above
Rushlight wrote:Along a similar topic; im looking for the most minimal (and cheap) method ofof connecting a single analog thumbstick (VCC,X,Y,GND) to a Pi GPIO?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Return to “Gaming”