Total beginner needs MCU recommendation  - Page 1
Forum section: electronics / general

author: mkiijam
author_rank: Regular Contributor
timestamp: December 10, 2024, 06:28:06 am
content: Hi Guys,I'm getting ready to design an input and output selector for my audio system and it seems like some sort of MCU would be the best device to operate the following ideas.1. I will have 4-5 input sources that I will want momentary switches to select. The switches will light up when pressed with one color LED then remain lit, but I different color.2. This switch press will actually engage a relay, so I'm guessing the output of the MCU needs to be able to source enough current to drive a relay? Or maybe I should come up with a relay driver circuit?3. The relay will connect the physical input connectors with a BUS, but I doubt this matters for this discussion.4. When selecting a different input, say CD input, whatever was selected before, say TUNER, needs to "deselect" automatically, much like a standard Home HIfi system / receiver5. There is also another 3-4 output selectors that work in a similar fashion, BUT I want to be able to program a modification and offer myself the option of LATCHING the outputs so they can all be on at once instead of exclusive if I want. Say holding down OUT switch 2 and 4 for 5 seconds would switch the MCU into lathicng mode instead.6. I would also like the MCU to do stereo reversing and other things, but these ideas are all really just controlling relays, as I have already designed the analog circuits...So, my question is which MCU? I know that's a big question with 1 million answers, but I have no base level so any input is helpful.Thank you!

author: pcprogrammer
author_rank: Super Contributor
timestamp: December 10, 2024, 07:31:56 am
content: This can be done with the simplest and, depending on the number of relays to control, smallest MCU out there. An ATtiny variant springs to mind.parametric searchTo control a relay it is best to use an additional driver transistor unless the relay current is low enough to be driven from an IO pin, but do keep in mind that when you want them all turned on the chip has to be able to source or sink the total current.Also do not forget to add a diode across the relay coil to suppress turn of voltage spikes.https://electronics.stackexchange.com/questions/110574/how-to-choose-a-flyback-diode-for-a-relayAn easy test solution can be to just get an Arduino nano or mini and make a prototype with that, or if it is a one of, just use that to do the job.https://aliexpress.com/item/1005006139230424.htmlhttps://aliexpress.com/item/1005006128051481.htmEdit: removed the nl. from the ali links

author: Smokey
author_rank: Super Contributor
timestamp: December 10, 2024, 07:56:17 am
content: Find a similar project and copy/modify what they did.

author: AndyC_772
author_rank: Super Contributor
timestamp: December 10, 2024, 08:23:56 am
content: Any microcontroller with enough physical pins can do what you're looking for.Don't try to drive relays directly from an MCU pin. At the very least, use an external transistor with a snubber diode across the coil to protect it.Personally I'd probably use a PIC16F or PIC18F device for a job like this - but that may be because they're parts I've been using for years, I know them well and so don't have a learning curve to deal with. Maybe something newer would be 'better' in some way - if only not to have to deal with Microchip's dev tools.

author: brucehoult
author_rank: Super Contributor
timestamp: December 10, 2024, 09:11:41 am
content: That would be easy to do with 7400-series digital logic chips, but a microcontroller would let you do it with one chip, plus maybe some drivers to give the current necessary for a relay. SN74LS06 and SN74LO07 can switch 40mA at up to 20V. I don't know if that's enough.This is a very low speed application so basically anything programmable with even 16 or 32 bytes of RAM and a few hundred bytes of program ROM/flash will do the job. The main issue seems like having enough I/O pins.You'll pretty much want to have a dedicated input pin for each switch.It would be nice to have a dedicated output pin for each switch too, which would mean you're getting to 16 or 18 pins for that, which is getting near the limit of very cheap devices. You could use daisy-chained "595" 8 bit shift registers to expand to any sensible number of output lines, all updated at the same instant, using just 3 microcontroller output pins.You can run any reasonable number (thousands) of daisy-chained WS2812 RGB LEDs from a single data pin (plus power). These do need fairly precise timing for the signal to update the LEDs, but a 16 MHz AVR e.g. ATTiny85 or ATMega328 can do that easily (I've done it with an ATTiny85).The ATMega328 (or 168) have 23 GPIO pins, which can do 20mA each. They are pretty old tech now, introduced in 2008, but extremely popular in Arduino Uno, Nano, Pro Mini boards and numerous clones which are easy to program using the Arduino IDE and libraries and have vast swathes of examp;les and tutorials. They're a little on the expensive side at $3 or $4 for a chip, and $12 or $15 for A Uno clone board (e.g. Elegoo)A more modern popular alternative is the WCH series of RISC-V microcontrollers, with 20 pin CH32V003 chips available for around $0.15 in qty 50 (so $7.50). Those have just 18 GPIOs which might or might not be enough for you -- it would limit you to 8 total switch/relay pin pairs, plus 1 pin for driving RGBs and 1 spare.Both this and the 328P have 2048 bytes of RAM (you'll use basically none of it -- the 32 CPU registers would be enough! -- and 16k or 32k of ROM space, also far far more than you need.The CH32V203 has 37 GPIOs and doesn't cost much more -- and you for sure won't need anything other than buffers to drive the relays.If you just want one then the ATMega328 is incredibly easy to get started with, especially with all the tutorials.

author: pcprogrammer
author_rank: Super Contributor
timestamp: December 10, 2024, 09:39:30 am
content: A bit more expensive but also well supported are the STM32G431 boards like thesehttps://aliexpress.com/item/1005005303669884.htmlWith 36 IO pins surely enough for reading the switches, driving the LED's and the relays.For driving LED's and relays it might be best to use some drivers in between. Even though a single IO pin is capable of driving either one (depending on the current needed of course) with multiples being driven on the max current via the supply pins may be exceeded.Check out the datasheet for more info.https://www.st.com/resource/en/datasheet/stm32g431c6.pdfEdit: removed the nl. from the ali link

author: jpanhalt
author_rank: Super Contributor
timestamp: December 10, 2024, 09:43:49 am
content: I don't really see the need for an MICU. Switch panels existed long before MCU's were common. However, since you're asking and have no experience with them, I second a simple device like an 8-bit PIC, 16F1xxx PIC. Earlier PIC's of of the 12F6xx and 12F1xxx series are essentially the same with lower pin count. The 12F only have 8 pins of which only 6 at most can be used for input. Only 5 can be used for output.If you know C or a higher level language, that may make it simpler. If not, then the PIC's mentioned were seemingly designed for Assembly language and have only about 47 instructions to learn. You can be up an flashing an LED in half a day.

author: tggzzz
author_rank: Super Contributor
timestamp: December 10, 2024, 09:54:31 am
content: Quote from: mkiijam on December 10, 2024, 06:28:06 amFor a beginner, the MCU is theleastimportant consideration.Much more important is the general ecosystem:the tool chain - language, IDE, development/production board, librariesthe support and communityperipherals boardsDuring an interview for my first job the interviewer asked that question, and was impressed when I gave that answer. He offered me a job and I accepted.That was in 1978;nothing changes

author: brucehoult
author_rank: Super Contributor
timestamp: December 10, 2024, 09:55:13 am
content: Could you please take a moment to remove the "nl." from Aliexpress URLs when you post them?When you do that, and people just click them, Ali then thinks you want Dutch even when you later enter a plain aliexpress.com and it takes a little bit of fiddling to convince it to use your normal language and currency again.Just a thought.

author: peter-h
author_rank: Super Contributor
timestamp: December 10, 2024, 09:58:10 am
content: Yes this is best done with one of those CPU evaluation boards. They bring out the IO on pins on the edge of the PCB. And they cost peanuts. Examples:https://uk.farnell.com/c/embedded-computers-education-maker-boards/avr/embedded-development-kits-avr?silicon-manufacturer=atmelAs to which one, it's a religion, you must understandIf it was me, I would go the STM 32F4 way but then I know it... spent years with a 32F417 project. I also use Atmel AVR in some simple products (90S1200, the 8313 is the newer version) and they weremucheasier to get into. I am not up to date with Atmel (I programmed these in assembler) but would hope they have a really simple devkit. STM's devkit is called Cube MX and I would really not recommend it for this job!Also think whether you may want to develop the skills for knocking up a software project in other areas. It is a very useful skill. A bit of C is all you need. Of course it can be done in hardwired logic but then you need a custom PCB, or a birdsnest like below, every timehttps://www.eevblog.com/forum/beginners/how-can-i-disable-auto-standby-on-tv-soundbar/msg5733739/#msg5733739

author: Lindley
author_rank: Regular Contributor
timestamp: December 10, 2024, 10:38:26 am
content: Would suggest for a beginner using the popular Arduino IDE and their boards like the Uno, though the genuine boards are expensive, there are many cheap, and good, clone boards around, like we use.While your input selector idea is sound and worth building to learn with, you could improve it later using a more modern approach as your skills develop.A LCD display would seem ideal to give you confirmation of what channel is selected and instead if a row of switches you could use a rotary encoder.Even more advanced you could use a TFT touch screen so no switches or leds needed at all.For any micro you need a relay driver chip like the low cost UNL2803A which can drive 8 relays ,However, as per your previous posts there are audio switching chips around, though practical no expereince of them.

author: pcprogrammer
author_rank: Super Contributor
timestamp: December 10, 2024, 10:50:25 am
content: Quote from: brucehoult on December 10, 2024, 09:55:13 amDone. Hope that it works, because when I click on them it just reverts back to the nl. one, but that is most likely due to cookies on my system.

author: mariush
author_rank: Super Contributor
timestamp: December 10, 2024, 11:06:01 am
content: Yes, any microcontroller would work.The LEDs, you can drive directly from the microcontroller, it usually can output enough current on each IO pin to do that. If you want to use a microcontroller with fewer IO pins, then you can use a led driver that can control the number of leds you're planning to use (there are shift register like led drivers that have 16 channels, so you only need two wires to transfer 16 bits to the driver, one bit for each channel you want to turn on or offYou could also use addressable rgb leds where you can basically connect the rgb leds in a series of 6 leds and then each time you need to update a led, you send the data for all leds again through a single wire.You don't power relays directly from the microcontroller.You power the relays from 5v or 12v or even 24v, whatever is available in your device. 12v would be preferred, as it means less current will be used in the primary coil to keep the relay energized.You use npn transistors or n-channel mosfets to close the circuit and make the relay work, and you control that transistor or mosfet with 3.3v - 5v from your microcontroller pin.There's chips like ULN2003A - 7 channel darlington transistor array - basically 7 on/off switches you can control directly from your microcontroller. These are cheap and will work with 12v relays well, but won't work well with 5v relays because there's a voltage drop of around 1v inside the chip, so the relay's coil would receive only around 4v, which could be too low for the relay to work reliably.For 5v relays, you could use the mosfet version of the chip, ULN2003V12-https://www.digikey.com/short/ztp997jjAs it uses mosfets instead of darlington transistors, the voltage drop on each channel is very low so it would work with 5v relays.All the above are lo-side switching (the relay's primary coil is connected to ground to close the circuit and turn on the relay.ULN2803A mentioned above would also work but would be used to source, as hi-side switching, it gives voltage to the coil of the relay and the other side of the primary coil is connected to ground by default. It's less common method to control relays.for flipping stereo channels , look into analogue switches ... you could use them to switch one input between 2 or more outputs with minimal added resistance.So for example by default each channel would be connected to output 1, and if you want to flip them , you switch both inputs to output 2Code:channel 1 (L) ---- L ---- RIN1 OUT1.1 OUT1.2channel 2 (R) ---- R ---- LIN2 OUT2.1 OUT2.2

author: xvr
author_rank: Frequent Contributor
timestamp: December 10, 2024, 12:04:07 pm
content: I'd recommend Raspberry Pi Pico. It is ready made devboard, easily programmable in Python. No any programmator hardware needed. Support direct driving of WS2812 chain (or any other time critical peripheral via its Programmable IO). Relatively cheap ($4 - $6).

author: brucehoult
author_rank: Super Contributor
timestamp: December 10, 2024, 12:14:23 pm
content: Quote from: pcprogrammer on December 10, 2024, 10:50:25 amYup, perfect, thanks!

author: Lindley
author_rank: Regular Contributor
timestamp: December 10, 2024, 08:43:06 pm
content: This Arduino code based kit might be what you need, they also list the program code so you could build and modify to your exact needs.https://www.muffsy.com/muffsy-relay-input-selector-4Or you could program one up yourself like the touch screen we did below, just rough text to show what we mean.

author: nctnico
author_rank: Super Contributor
timestamp: December 10, 2024, 10:07:08 pm
content: Quote from: tggzzz on December 10, 2024, 09:54:31 amThere are two very important items missing from that list:- good documentation and devices which actually work as documented.- short errata sheetsThe NXP LPC series really shines for these (two) items. These have been my goto microcontrollers for the last 2 decades because of their ease of use. A lot of people penny pinch to save a buck on hardware but then end up spending oodles of time working through idiosyncrasies due to the chip designer needing to finish the chip design and documentation before lunch on Monday.

author: tggzzz
author_rank: Super Contributor
timestamp: December 10, 2024, 10:21:46 pm
content: Quote from: nctnico on December 10, 2024, 10:07:08 pmArguably those were part of "support and community", but it is valuable to have them split out.Of course there shouldn't be any errata sheet. I couldn't find any on the last devices I've used, and they just worked as advertised.The manual should also be short. If it isn't then it is a sign of lots of half-considered things being thrown together, often without considering how software will use them. Again, the last devices I used had remarkably, pleasingly short hardware and software manuals. I was doing parallel hard realtime code within a day of starting to use them, and there were zero surprises in hardware and zero surprises in software. I was gobsmacked.QuoteYes, unfortunately. Add crap ill-considered languages and tools that have been thrown together.

author: Lindley
author_rank: Regular Contributor
timestamp: December 11, 2024, 05:20:16 pm
content: Out of interest just run up that Muffsy project code at it seems to work well, though we did not use its IR remote control as that ESP micro has BT and Wifi built in so its also possible to control it with your smart phone as well as the rotary encoder.Would seem a good base for your project, readliy expandable hardware and program code for more relays and functions, even with a display and / or touch screen if you want.

author: mkiijam
author_rank: Regular Contributor
timestamp: January 04, 2025, 06:38:23 am
content: Okay guys, thanks for all the input.With all of these options, like the PIC chips and STM chips, ATMega etc... do I need to just program the chip and drop it in with VCC etc, or will it need the DEV pcb included or I2C clock data etc?

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 04, 2025, 07:29:38 am
content: Quote from: mkiijam on January 04, 2025, 06:38:23 amYou can design your own PCB, of course, with all the switch stuff you need for the audio part and the MCU of choice. It will need some extras like decoupling caps and maybe a crystal for the MCU clock. The programming can be done when the MCU is on the board, at least with the STM and ATMega chips. I'm not familiar with the PIC chips.For STM chips you just have to add a 3 or 4 pin header to make the SWD interface accessible. For the ATMega chips it is the SPI interface with the reset line that is needed on a header to be able to program it, at least for a blank chip.You can find schematics for a lot of the MCU development boards out there and use these as a reference to make your own.When you have no or little experience with PCB design then it might be better to just use a small MCU development board and build your system around it.

author: jpanhalt
author_rank: Super Contributor
timestamp: January 04, 2025, 11:03:37 am
content: PIC chips can also be programmed installed on a final/product board. Microchip refers to the process in ICSP (in circuit serial programming). All that's needed is a small header.

author: mkiijam
author_rank: Regular Contributor
timestamp: January 04, 2025, 04:57:47 pm
content: I have tons / plenty of experience designing PCB's, it's just been all audio/power/analog stuff up till now. Back in my day of working on TV's the "processor" stuff I came across had what we called "Clock" and "Data" lines. There was often (maybe always?) crystals nearby, and another thing we called "I squared C bus." We stayed away from this stuff, and I never really learned much about it. But remembering it made me wonder if this chips needed stuff like that.

author: mariush
author_rank: Super Contributor
timestamp: January 04, 2025, 05:34:19 pm
content: i2c is a protocol to communicate between chips - you can use a microcontroller in a project without ever using i2c.Crystals are used to set the frequency of the microcontroller ... think of it like metronome, the microcontroller does some operation with every tick.A lot of microcontrollers have built in oscillator, and / or cheaper methods to create the operating frequency. Most PICs have it, Arduino has it.. Usually the built in oscillators are good enough for most projects, but they're not super precise. For example the frequency may drift from the 16 Mhz up and down by a few thousand Hz over time...If you need a particular frequency or you need an oscillator or crystal that's very precise for some reason, most microcontrollers will allow you to use external crystal or oscillator. For example, if you want to make a microcontroller to output a VGA signal, it would be convenient to use a crystal or oscillator that runs at the frequency of your vga signal (25.175 Mhz for 640x480 60hz)

author: Buriedcode
author_rank: Super Contributor
timestamp: January 04, 2025, 11:07:40 pm
content: I'll also say "Arduino UNO" just because:- Its cheap- Available everywhere- The IDE is easy to install- Doesn't require a programmer- Plenty of examples built into the IDE- Endless libraries, which may be a hindrance since there are so many, and some are pretty poorly made- Lots of "shields" of reasonable quality, minimising the amount of extra circuitry you'll need to add (relay boards, displays, buttons etc..)It really is easy ot set up, meaning you spend most of your time actually writing code to do what you want to do. The libraries can handle the finer things like speaking to external devices, so the bulk of your code is functional - the actual logic of the application, responding to user inputs etc..

author: MathWizard
author_rank: Super Contributor
timestamp: January 05, 2025, 06:45:25 pm
content: I'm currently using an AVR type ATtiny44A with 12 I/O pins, to help out the main MCU and input CH/vol chips in my stereo. Even just for that, I'm running out of pins, and that's with OR'ing some signals together. Come to think of it, I could add some more hardware mods, and make my MCU program easier.The main MCU, is 100pins or so, and seems to be failing. I don't need most of the functions on the stereo, especially all the digital and TV related inputs, so I really should start working on a total MCU replacement project, with some 64-pin AVR MCU's I have, so maybe 2 of them if I want to do it all. Hopefully the MCU lasts long enough to decode all the functions involved. But again, I can do the main ones for EXT.IN and the VFD without to many problems. For me, this is just a good learning experience.

author: ahsrabrifat
author_rank: Regular Contributor
timestamp: January 15, 2025, 05:34:30 am
content: Like so many others have already stated, I vote for Arduino UNO. It is easy to use. Its number of I/O pins are sufficient for your project. It can control relays.You can also handle the denouncing problem by coding. Here is all the necessary info about this board.https://www.theengineeringprojects.com/2018/06/introduction-to-arduino-uno.htmlHere is the code and details of relay integrationhttps://randomnerdtutorials.com/guide-for-relay-module-with-arduino/

author: SteveThackery
author_rank: Super Contributor
timestamp: January 15, 2025, 10:44:02 am
content: Yep, my voice is for Arduino Uno, too.If you need a much smaller Arduino - albeit with slightly fewer I/O pins - Arduino Pro Mini is great, although you need a cheap 'n' cheerful programming adapter.

author: drspastic
author_rank: Contributor
timestamp: January 16, 2025, 06:34:18 pm
content: esp32 module because cheap, program via usb, includes bluetooth and wifi for remote control from your phone. no need to make extra boards

author: Kasper
author_rank: Frequent Contributor
timestamp: February 01, 2025, 06:11:20 pm
content: Quote from: mkiijam on January 04, 2025, 04:57:47 pmMost MCUs can fulfill your requirements. I'd pick the easiest to work with.Arduino UNO (ATMEGA328P) used to be my go to for quick and easy but now I'm into the RP2040. Made a few PCBs with each.With the RP2040, you can program with USB. No special programming cable required!There are also a lot of little modules to play with until you are ready to make a PCB.If you make a PCB, you can include headers to plug in the modules or you can copy the module and have someone like JLCPCB solder it on for you. Adafruit and sparkfun have lots of modules, schematics and example code.You may need to include a crystal. I dont see a need for it though, unless you use addressable LEDs, then you might need one.