Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIOs suitable for Microswitches? Joysticks?

Fri Jan 27, 2012 5:23 pm

Are the GPIO pins suitable for connecting up microswitches (or a matrix of buttons with a diode each) directly to the board?

I realise that a buffer / breakout board would provide more protection and many more inputs, but I'm talking seriously low-tech wiring-only solutions.  Maybe the odd diode but no address decoding or A/D or anything.  I'm thinking that only using the voltages provided by the board itself on the GPIO pins may be a safety feature.  I've seen odd bits crop up here and there on this forum but nothing addressing this directly.  For example, there was mention of rigging up a joystick directly for running video game emulation in the MAME thread.

When it comes to kids and computing, instead of output interfaces and the age-old motor or traffic-light controllers, how about something actually interesting, like building your own joystick as a project, then using it to play your favourite game on the Pi itself?

Or building customised controllers for kids or adults with mobility issues, tailored to their needs?  I've seen interfaces for things like jog-controls and single large push-buttons for sale for a small fortune as they have to be custom designed, yet at the same time a hack to add two jack plugs to the buttons of a Poundland USB mouse to turn it into an interface for two giant push-buttons.  And then there's the whole genre of one-button game design to get into...

Thanks for reading this far, anyway.

So, are the GPIO pins suitable for connecting up microswitches (or a matrix of buttons with a diode each) directly to the board?

User avatar
Gert van Loo
Posts: 2486
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIOs suitable for Microswitches? Joysticks?

Fri Jan 27, 2012 6:11 pm

Yes, you can.

The Gertboard is really targeted at education where you expect connections to be made and unmade on a daily basis. It will also allow pupils to make mistakes whilst still protecting the main board (somewhat...)

For one-time-off designs you can connect directly to the GPIOs.

veronicathecow
Posts: 25
Joined: Wed Oct 05, 2011 9:10 pm

Re: GPIOs suitable for Microswitches? Joysticks?

Fri Jan 27, 2012 7:21 pm

Might be worth adding some protection circuitry like diodes, Zener diodes and some resisters to protect from static as I am not sure how well the GPIO are protected and for a few pence it is worth it.

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: GPIOs suitable for Microswitches? Joysticks?

Fri Jan 27, 2012 7:43 pm

This document has good advice on how to stretch GPIO devices to the limits using only resistors and diodes (see the hardware chapter).

ww1.microchip.com/downloads/en/devicedoc/40040b.pdf

This was written for a PIC, but almost everything is valid for any microcontroller.

BlueClogger
Posts: 34
Joined: Mon Dec 26, 2011 11:01 am

Re: GPIOs suitable for Microswitches? Joysticks?

Fri Jan 27, 2012 7:49 pm

http://www.picaxe.com is another microcontroller site and the manual has a number of simple interface circuits.  I think I'm going to get one of their starter packs to play with until my Pi arrives...

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIOs suitable for Microswitches? Joysticks?

Fri Jan 27, 2012 10:57 pm

Thanks, yes I've been reading up on 'Chalieplexing' and I've seen the resistor-based multiplexing trick done before in the stuff I've done with LEGO Mindstorms.  But I think 8 pins is more than enough to rig up a set of game controls, particularly if you can input and output on any of them.  Someone even more ham-fisted with a soldering iron than me could do it.

Though this is now where I begin to show my Linux noobiness.  I've tried to get to grips with Windows HID drivers before and failed, so my hope is there's someone out there who could do this in their sleep.  Or at least, can once they get one of these devices.

The concept is a generic input device driver with a single configuration file that you can define based on what you've built - so you can publish a simple schematic for someone to copy and provide the config to make it work, without having to re-code the driver yourself.  At the top of the config file you define and name how many joysticks, mice, keyboards etc. you want the driver to register (and set a speed in points for any mouse movement).  Then you have a series of strings in a simple, user-friendly (case insensitive!) syntax, something like:

pin 0,1 = Joystick0.Up

pin 0,2 = Joystick0.Down

pin 0,3 = Joystick0.Left

pin 0,4 = Joystick0.Right

pin 0,5 = Joystick0.Button0

for example for an Atari type joystick.  Meaning, if you raise the voltage on pin 0 and can detect something on pin 1, then on Joystick 0, signal someone pressing and holding 'Up'.  You could have an optional term on the end to say '.Hold' (the default) or 'Click', meaning to simulate a single tap and not repeat.  And similarly you could divert inputs to the keyboard, or make the mouse cursor move left/right/up/down by however many points you defined at the start:

pin 6,0 = Keyboard0.X.Tap

pin 6,1 = Keyboard0.Shift.Hold

pin 7,0 = Mouse0.Up.Click

pin 7,1 = Mouse0.Down.Click

...

pin 7,5 = Mouse0.LeftButton.Hold

The driver would scan sequentially by raising the voltage on each GPIO pin specified and looking for a signal on the others.  That means if you want to use diodes, the path 1->2 can be a different thing from path 2->1.  But if you don't, you could just wire in an old joystick like the first example.  Or wire up a 4x4 grid of buttons for video whack-a-mole, or multiplex 6 joysticks, or two sticks with a dozen buttons each.  But the games you play with it only need to listen to one driver.  So anyone can build any control device for anyone and (at least try to) play any game with it.

Will it work?  Open to suggestions...

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIOs suitable for Microswitches? Joysticks?

Tue Jan 31, 2012 2:17 pm

On the other hand, if the Gertboard is going to be the popular way of interfacing i/o projects, could this sort of functionality be written into the software?  Not specifically as a driver, but maybe provided as a background application (something along the lines of 'JoyToKey') that maps sensor inputs directly onto simulated keypresses for controlling another application?

That may not be suitable for arcade-type control systems but it should meet the needs of improvised or customised control systems for hobbyists or disabled users.

User avatar
TonyD
Posts: 448
Joined: Thu Sep 08, 2011 10:58 am
Location: Newcastle, UK
Contact: Website

Re: GPIOs suitable for Microswitches? Joysticks?

Wed Feb 01, 2012 3:10 pm

How many switches / buttons do you want to interface?

You can interface an old Nintendo NES or SNES controller using 3 or 4 GPIO pins quite easily and wire your switches straight to its PCB. The 4021 chip used in the NES/SNES controllers is a CMOS device and should work at 3.3V, so no need to mess around with level converters.
Tony

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: GPIOs suitable for Microswitches? Joysticks?

Wed Feb 01, 2012 3:30 pm

Just picked up a CD4021 chip last night, not what I planned to get (CD4094) but was passing the shop and didn"t have any notes with me (and the shop didn"t have any info on them).

Will try wiring it up at some point for a demo (using TI LaunchPad), and see if it works (will add to the Easy GPIO tutorial I'm working on in the wiki).

CD4021 – 8Bit shift register (parallel in/serial out) <<wasn"t far off then!

CD4094 - 8Bit shift register (serial in/parallel out)

I"m not even 100% sure if they will function at 3.3V or not, so will test them and see.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

Joefish
Posts: 95
Joined: Wed Jan 25, 2012 10:31 am

Re: GPIOs suitable for Microswitches? Joysticks?

Wed Feb 01, 2012 5:26 pm

Well, my concept was to only use switches (and diodes as an extension of that), and a canny bit of software to make sense of it all.  To allow custom control rigs to be built with no more knowledge of interfacing than how to connect a battery to a light bulb.  So someone who might make a custom controller from LEGO or in their home woodworking shop could just plug in some switches to the GPIO header and go.

If it comes to hooking up serial connected devices with their own on-board interpreters then hundreds of solutions already exist.  You can start with the Gertboard or a parallel to serial link or the guts ripped out of a gamepad but really, any number of adaptors could go into the USB port and already be supported by existing Linux keyboard and joypad drivers.

Now if you want to control something like home automation then it makes sense to multiplex the GPIO pins by making each one a serial comms channel and get loads of inputs and outputs going.  But for just a dozen or two digital inputs I think it's unnecessary, and raises a technological barrier that will put some people off from trying.

User avatar
TonyD
Posts: 448
Joined: Thu Sep 08, 2011 10:58 am
Location: Newcastle, UK
Contact: Website

Re: GPIOs suitable for Microswitches? Joysticks?

Thu Feb 02, 2012 1:47 pm

meltwater said:


Just picked up a CD4021 chip last night, ..

I"m not even 100% sure if they will function at 3.3V or not, so will test them and see.


I pulled a datasheet for NXP HEF4021 and it operates down to 3V so should work at 3.3V but testing them at 3.3V will definitely be the thing to do.
Tony

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: GPIOs suitable for Microswitches? Joysticks?

Thu Feb 02, 2012 2:32 pm

TonyD said:


meltwater said:


Just picked up a CD4021 chip last night, ..

I"m not even 100% sure if they will function at 3.3V or not, so will test them and see.


I pulled a datasheet for NXP HEF4021 and it operates down to 3V so should work at 3.3V but testing them at 3.3V will definitely be the thing to do.


Yep, at least it is only 80p if it doesn't.  Cheers!
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

george.endrulat
Posts: 10
Joined: Tue Nov 29, 2011 4:17 pm

Re: GPIOs suitable for Microswitches? Joysticks?

Thu Feb 02, 2012 5:23 pm

XBOX 360 Controller --> Arcade controller build out: Arcade controller will give you button envy

It's a simple solution to a problem that can easily get overly complex.

User avatar
Redrobes
Posts: 80
Joined: Mon Dec 26, 2011 9:19 pm
Location: S.W. UK
Contact: Website

Re: GPIOs suitable for Microswitches? Joysticks?

Sat Feb 04, 2012 2:00 am

I made a MAME joystick console a lot like that in the image except I programmed up a PIC to do PS2 style keyboard IO to a PC. My mate tho just took an old USB keyboard apart and hacked the button wires directly onto the keys button pads and used its existing USB interface. His worked better and sometimes my buttons stick from not implementing the interface exactly. So my 2 penny is to get hold of an old keyboard and strip it - cheap and quick and no interfacing at all.

If I were considering using an XBox controller, id keep it in its original form factor...

dbinaz
Posts: 8
Joined: Sat Nov 17, 2012 7:32 pm

Re: GPIOs suitable for Microswitches? Joysticks?

Sun Nov 18, 2012 4:14 pm

@JoeFish - Anything ever come of this?

Return to “Other projects”