Hello everyone! I have a Raspberry Pi Pico project (spectrum visualizer) with 2 possible audio inputs connected to ADC (pin GP26) - one from a microphone module with MAX9814 amp, another from a stereo mini-jack (to connect a phone or smh). Both of them will be in a DC range 0 - 3.3V. How can I switch between them with a microcontroller (e.g. with pin GP20)? Can I use a relay? If so, which specs of a relay are important here? Thanks.
Can't you just use 2 analog inputs, 1 for each sound source, and have the program only read the input of the selected source?
Yeah, I can, but I thought a hardware switch would make the code a bit easier. Also, it's more flexible if I want to add more inputs. Thanks for your help.
A hardware switch will make the code harder as you have to control the hardware. If you have enough analogue input pins spare then use those and switch in software (it's not that hard to do!) If you need more inputs than you have pins for then:
- 74HC4051 will give you 8 inputs at the cost of 3 digital pins to control it (or 4 if you want output enable)
- 74HC4067 will give you 16 inputs at the cost of 4 digital pins to control it (or 5 if you want output enable)
Well, yes, but a relay has problems:
- Relays don't switch cleanly
- Relays require something to drive them, you can't just connect to a pin on a micro-controller
- Relays are a lot bigger than an IC like the 4051
- Relays require 1 digital pin per relay, so you end up using a lot more pins
Unless you have a very specific reason for using a relay then don't use a relay.
If I read your question correctly you need 2 analogue inputs, the Pi Pico has 3, use 2 of them.
