Maker Pro
Maker Pro

Modular Controller build with Arduino (Teensy 3.5)

solsnare

Dec 23, 2017
5
Joined
Dec 23, 2017
Messages
5
Hello all!

New to this forum so please excuse any formatting issues.

Anyways, here's a picture for starters:

Modular_Board_Concept_Diagram2.png


FYI, I'm not an electric engineer, very little understanding of circuity apart from fundamentals.
I'm a code monkey :p

OK, if the picture wasn't descriptive enough of the problem.

I just want to essentially make a way to jump through a bunch of buttons that i connect to a "controller" module, without knowing HOW many of these buttons are gonna be set up in sequence. This means that i can't use the multiplexer, I COULD just forward all the outputs of the controller to each button, but i think it would be more efficient to just use a single digital pin on the teensy to figure out the states of all my buttons by performing some sort of logical loop in my arduino software.

Any ideas on how i'd do this?
Thanks!
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
You could use an analog input line using different resistor values for each switch and then just do a calculation to determine which has been pressed.

This doesn't allow for multiple button presses where confusion would reign.
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,878
Joined
Jun 21, 2012
Messages
4,878
You have more or less described HOW you want to DO something, i.e., proposed a solution, but I don't see anything that describes WHAT you want to DO. There may be other, maybe simpler, solutions.

So... what is the purpose of all those buttons, of unknown number, that the "controller" connects with? Is it important to know which button is actuated (pressed) in real time? If a button is pressed and released before the "controller" becomes knowledgeable of that event, what happens? Is it important to know the order in which the buttons are actuated? In other words, please tell us WTF you are trying to DO without direction on your part of how you think it should be done. Someone here will take it from there and propose one or more solutions. Note: depending on what you think "controller" does with the button-press events, this may or may not involve an Arduino.
 

solsnare

Dec 23, 2017
5
Joined
Dec 23, 2017
Messages
5
I'm trying to make a modular sort of gamepad. Where you can attach a bunch of different modules together. (Buttons, Joysticks, Pedals, etc..)

As long as they're connected to a controller, the buttons outputs should be read in sequence they are connected (pressed or not pressed). However, it will loop through this sequence as quick as possible, and also tell the user if multiple buttons have been pressed (there will be a limit to the amount of buttons connected, which will depend on the speed of the loop).

I'm going to be connecting modules to it that will be giving back digital, and analog outputs which i'll be pushing back into the respective ports on my Arduino so i can issue the right commands to my PC.

My problem is trying to figure out what circuity i'd need in each button so that the Arduino can issue commands to:
  1. Traverse sequentially through each module
  2. returning what it's digital, or analog state is, depending on what kind of module it is.
  3. Needs to know what the traversal limit is, which will be indicated by the amount of these modules are connected (I was thinking of some switch that gets flicked when a module is connected to another, that tells the circuit if we're attached to something or not, which can tell the Arduino if we're at the end or not.
I want to try to do this with only:
1 digital pin: Digital Input (to read digital module data, buttons, switches etc..)
1 analog pin: Analog Input (to read analog module data, Joysticks, Pedals etc..)
1 digital pin - Traversal Pin: (to issue traversal commands to either skip the module, or to read it it's state)
1 digital pin - Dead End Pin: that tells the board if at the current module you're traversing to is at the end, or there are more ahead.


This way, in code:

I'd be telling the traversal digital out to output a 1, which gives me the first modules data,
then i'll tell it to output a 0, 1, which skips the first module, and tells me the second one.
then i'll tell it to output a 0, 0, 1, which skipps the first modulee, aand tells me the third one.
etc..

Or if there was a way that was simpler, i'd like to just:

tell the traversal pin to digital out a 1, it hops the first module and reads back itt's output
tell the traversal pin to digital out a 1 again, it'll hop to the next one, and reads back it's ouutput.
and on and on, only stopping the loop if when it reads a module, the digital "Dead End" pin as a 1.

I hope that was a beetter explanation, i'd edit my own post with this butt i don't see such a button.
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
The 'proper' way to do this would be to use a proprietary communications bus - like I2C or RS485 or even NMEA!! - and develop individual controllers (gamepads etc) that output to that bus.

With simple I2C comms protocols being possible in some of the smallest PIC-type microcontrollers there's no reason why this should be an expensive solution and actually quite easily achievable.

There are actually USB interfaces specifically designed for games controllers (I have one interfaced to a steering wheel that is no longer supported under Win7 but I rewired using this controller and it works perfectly).

http://www.leobodnar.com/shop/index.php?main_page=index&cPath=94

USB is, of course, 'stackable' and only two wire (excluding the power wires) but may require additional work if interfacing to the likes of Arduino.
 

solsnare

Dec 23, 2017
5
Joined
Dec 23, 2017
Messages
5
With simple I2C comms protocols being possible in some of the smallest PIC-type microcontrollers there's no reason why this should be an expensive solution and actually quite easily achievable.

Where can i get one of these I2C capable controllers i can stick into each one?

Also, why would it more proper to do this, than something as simple as what i was proposing? I'd rather not implement additional microcontrollers in something as simple as what i want, but if that's whats necessary, and the components i need to buy are cheap, then i'm game!
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
I2C is a protocol enabled in software and/or hardware and as such available as a 'sketch' for the Arduino range of processors - the Arduino range having the hardware built-in.

The ATtiny20 is the smallest (I think) with I2C built-in:

http://www.atmel.com/images/atmel-8235-8-bit-avr-microcontroller-attiny20_datasheet.pdf

but any other UART-capable device would provide a route to simple 2-wire comms.

Check out this tutorial on I2C and the links (lower down) to other resources

https://learn.sparkfun.com/tutorials/i2c

But if you implement I2C in the Arduino (whatever version) itself then you can also use the device to interface to the buttons, potentiometers, LEDs whatever that comprise your gaming devices/button modules etc. The Arduino - as a programmable module - is one of the cheapest around and the Chinese markets full of multiple-purchase cheap (CHEAP!) offers. The fact that the Arduino also comes with access to ready-written software modules makes development a piece of urine...

Here's an offer for FIVE such modules that work out at around $3 a piece.

https://www.ebay.co.uk/itm/NEW-5Pcs...314448?hash=item3d34787490:g:~gMAAOSwqYhZv41R

I couldn't recommend a simpler or cheaper solution.
 

solsnare

Dec 23, 2017
5
Joined
Dec 23, 2017
Messages
5

OK, i did a bunch of research on these, and they look really promising and incredibly easy to program using a Arduino.

I guess i can use this chip to have pre-loaded code that can send out my final outputs, just like a sensor, to my master "Teensy" (which def has the SDL, and SCL pins so i can clock and send data), which can ask each one for it's information.

I guess my last 2 things would be:

https://www.digikey.ca/products/en/.../685/page/2?k=ATTINY&k=ATTINY&pkeyword=ATTINY

I am looking at this, and i really don't understand wtf to buy for my application that would be the cheapest. They're already pretty cheap, i just don't want something overkill to handle button clicks, and some potentiometers for joysticks, would be pretty silly to do anything with a ton of processing. The only thing i really need in terms of performance is high mhz because any delay on the inputs from the modules wouldn't be very enjoyable.

And my final question would be,

How would you go about putting these things together so that when a new one is added, my arduino would automatically know it's address in the I2C and start reading from it's data. Can i loop through all of the I2C's possible memory addressses that are connected?

--- EDIT ---

I did some more research on how I'd go about assigning the addresses. I heard of something called an R2R network, and the way these modules set their own address is by checking the input voltage, and using that as a seed to figure out it's own address. I think this works because each of these modules attached in sequence would essentially add resistance as it travels down?

If that would work, how would i go about telling the Arduino (The master), what the newly connected slaves address is?

BTW: I think i found one that's incredibly cheap, and more than suits the purposes:
http://canada.newark.com/atmel/attiny45-20pu/microcontroller-mcu-8-bit-attiny/dp/68T3729

What do you peeps think?
 
Last edited:

solsnare

Dec 23, 2017
5
Joined
Dec 23, 2017
Messages
5
Oh you know what, couldn't i just make it so that the Slaves talk to the master whenever they want through some predefined address. I just send everything across the wire to the master, telling it if a buttons been pressed, what a joysticks status is etc... Or do i have to build in a way where the master queries every address?

--- EDIT ---

Oh kay,
https://electronics.stackexchange.c...-cant-masters-talk-to-each-other-in-a-i2c-bus

Looks like i fucked up on the most basic understanding of these systems. Slaves can't talk back to a master unless the master ALLOWS it to do so (lol).
What a dude said in here was interesting though, how a master could allow a slave, to act like a master, let it set the pace of the conversation and reply.
At that point it's like making all the ATTiny i2cs the masters, and they just take turns talking to the controller, which would then act like a slave.. Though i believe that makes it so simultaneously communication can't happen? Something like that?
 
Last edited:
Top