1

Okey, so I never had anything to do with a Raspberry Pi or Arduino and my question may sound dumb. I know some Python but I'm bad in electronics.

Lets say I need a system, where there are 10 work stations at an assembly line.

Now, the assembly lines speed is dependent of the slowest work station (it waits for all 10 work stations to finish). The system's job is to measure the efficiency of work stations. Simply put. At each work station, there should be a button and when the line starts to roll, a timer starts, and the button records the time for that particular work station. When each button is pressed, the timer resets, starts again and the cycle goes on. I know how to program that, I know how to get the data from Python code. I just have no idea how to make the hardware.

What would be better. Arduino or Raspberry Pi? Is there a way to get 20-30 independent buttons, which would be about 10 meters apart from each other? Of course, there should be some error handling. Like, someone may press the button but didn't intend so. So if someone is ready, he presses the button and changes the state of an variable and a LED lights up if he is ready. If he pressed it by accident, he just presses it again, or he has to press two buttons instead of one, so that it's safer against human error.

My main question to this would be, is this something hard to do? I'm a second year Computer Science student but we didn't cover a lot in Hardware sadly. Is this doable on one Raspberry Pi? If not, is it hard to connect a couple of Raspberries to have more USB/GPIO inputs? Or maybe should there be a microcontroller/chip?

I'm eager to learn and this, when going over it in my head, does not look like something very hard to do. Maybe some book recommendations or projects I should begin with?

  • 1
    Search for adding a single button. Repeat that process ten times. – joan Mar 19 '16 at 9:09
  • I did. Problem is in the end i will need probably more then 10 buttons. There is not enough GPIO to cover that. I could make maybe a cluster from a guide and then use the GPIO's or maybe input USB Game Controlers? – Repcak Mar 19 '16 at 10:35
  • 1
    GPIO port expanders? A MCP23017 for instance adds 16 additional GPIO. Eight may be added to the Pi's I2C bus. So for the sacrifice of two GPIO you can connect another 128. – joan Mar 19 '16 at 10:57
  • The problem is i need to have them be operational independent. For example all 10 buttons could be pressed at once and the PI should register that. This i think complicates it a bit or i may be wrong. – Repcak Mar 19 '16 at 11:21
  • as @joan wrote, an MCP23017 would be good. In fact it always sets or sends the state of an entire GPIO bank (one side of the chip) in one go/byte. There's no way of reading a single pin alone. It has interrupt capability as well although I never used it on mine. You'd hook the interrupt pin on the MCP23017 to the Pi's GPIO to avoid constantly polling for pin state changes. Even if you don't end up using an MCP23017, I don't think 10 separately operating buttons connected to the Pi would be a problem. – jDo Mar 19 '16 at 15:35
2

The Rasperry Pi has lots of digital inputs (see here) so you can easily do as many buttons as digital inputs. Some models have 26 GPIOs, so that's 26 buttons easily.

If that's not enough, you can create a matrix. This is a little bit more complex, but really not very. There's a good explanation here.

In short, imagine you needed 100 buttons. You'd arrange them in a grid of 10x10. Each button would be on the junction between a row and a column: when you press it, it connects the row to the column. Each row and each column is connected to a separate GPIO - so you need 20 GPIOs in total.

Set your rows (say) to outputs and your columns to inputs. Enable the internal pull-up resistor for the columns - which means if nothing is connected to them, they'll read "high" (value 1).

Now to read your keys, you start at the first row: set its pin to low (=value 0, or 0v), and read each of the 10 columns. If any of the buttons on the first row are pressed, it'll pull the input down to 0v and you'll see 0 on the appropriate input, otherwise you'll see 1. Set it back to high (=value 1, or 5v) and repeat for all 10 rows, and you've read all 100 keys.

This approach needs no external components to understand or get working. The main downside is that you get ghosting of keys: if I press three or more keys together, depending on which combination it is, it can be hard to work out which have been pressed. For your scenario I'd have thought this was an acceptable compromise.

The other disadvantage is that you're going to have a huge jungle of wires, but you're hardly going to be able to avoid that to be honest.

This is how just about all keyboards and keypads work, by the way.

  • Thanks for the advice. The problem is that i cant have ghosting keys. There could be a scenario, when people click at the same moment 3 or more keys. Its very unlikely but still. So a follow up question. Can i connect somehow 2 raspberries so i can have more GPIOs? I saw some cluster guides connecting raspberries with a switch. Could i then have access to all the GPIOs? I thought about a USB Decoder which are used in gaming pads for each button but i imagine button ghosting would be there an issue also but then i could have for 1 USB port about 10-14 buttons. – Repcak Mar 19 '16 at 17:38
  • If you are careful about how you arrange the keys you can reduce ghosting. You can also detect it in software (given than you can scan very fast and the chance of multiple presses simultaneously is astronomically small) and mostly correct for it. – Mark Smith Mar 19 '16 at 17:40
  • This sounds really good. If i have 26 GPIOs, i can make 6x6 matrix, having 36 buttons (10 work stations, so for a single one i have 3 buttons). Im left with 14, i can use 10 for LEDs for every work station(10) that they button press was registered by the software and im left with 4. I need also a clock on the wall with the Main timer. 4 bits is not enough. USB handling could be difficult. Building a HEX display on LED's isnt a problem really. More the data what to display handling.. – Repcak Mar 19 '16 at 18:31
  • You can get individually addressable LEDs which would allow you to address any number of them from a single output, but it'll make your wiring a headache if you use them for the workstations. As for the clock, how you want to do that is an issue for a separate question, I think - it's quite a big topic. – Mark Smith Mar 20 '16 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.