5

Forgive my naivety but I seem to lack a vocabulary for the whole electronics domain...

I'm interested in building something to measure wind direction. Inspired by this design I would like to build a circuit of a number of reed switches (say, 8). For the sake of simplicity, let's say only one of them will be active at the same time. Although I could connect each switch directly to separate pins on the Pi I would like to combine the switches into one, common output to the Pi. Somehow.

I'm picturing me some sort of chip that could go in between my circuit and the Pi. The switches could be numbered 0-7 and the chip could output a binary number corresponding to the currently active switch.

The question is, does something like this exist? Could it be built relatively easy?

fiskeben
  • 221
  • 4
  • 9

4 Answers4

4

The B+ has 26 usable gpios. In that context 8 doesn't seem a lot.

In effect you are trying to trade off the number of gpios used against complicating the circuit.

Have you considered a port expander, such as the popular MCP23017? That connects to the I2C bus (two gpios, SDA and SCL) and provides an additional 16 gpios per chip. Up to 8 MCP23017 may be connected to the same I2C bus. Additional types of I2C devices may also be connected to the I2C bus at the same time.

There are plenty of tutorials on the www of talking to the MCP23017 and similar using Arduinos and the Raspberry Pi.

Any other solution you come up with may be more complicated in hardware and software.

joan
  • 71,852
  • 5
  • 76
  • 108
1

A simple star analogue design.

Feed your voltage in 3.3volts lets say. Then from the "centre point" (Pin 1 Vcc) you calculate a set of resistors that will give you various output voltages when the reed switches activate which can be measured (Pin 4 Vdd)

enter image description here

image source Weather Sensor Assembly p/n 80422

This is a truth table based on 5volts input but it shows you an example of the resistors used. You need to take into consideration the 10K resistor on input (not shown on diagrams) to prevent short circuit.

enter image description here

image source Weather Sensor Assembly p/n 80422

You have to take into consideration that two reeds may be active at the same time and they should not give the same value as any other 1 reed.

You then only need 1 channel to read 8 switches. Here is a cheap 2USD chip on its own but ebay has pre built or kits for a similar price using I2C

enter image description here

You can then wire it up like this. All I2C will be the same..

enter image description here

You then have the freedom to code in Python (I2C Library), Mono C# (sharp IO) or direct from the console with scripts (using GPIO Utility).

Piotr Kula
  • 17,336
  • 6
  • 66
  • 105
0

What you are asking for is a port expander, like joan said.

If you want a lower-level or cheaper solution, you could control 12 devices with 4 wires using Charlieplexing, but that is more complicated.

Like joan said, GPIOs are plentiful on the rPi, but if you are hoping for a low-wire count solution to have your sensors far away from the rPi, you will almost certainly need at least 3 or 4 wires, either Charlieplexing or i2c with power and ground. If you have a long i2c line, be careful to have a sufficient pull-up resistor. Good luck!

krs013
  • 366
  • 2
  • 8
-1

Does not sound robust to me. What when NO reed switch is closed? Mechanical adjustment must be perfect to have a single switch closed and not two or none. It is easier to get all switch states into the Pi and sort the wind direction out in software.