Random Question about Microcontroller Chips, because why not?

Faust

Supporter
27 September 2021
1,431
1,742
113
48
So, here's the dealio.

I'm trying to put together a simple light-and-sound circuit for cosplay props, and I need to make a speaker driver. But I'm a perfectionist. Sure, I can use pulse-width modulation to get a cheapo speaker to make a musical tone of sorts, but I want more flexible control over the waveform, and that means being able to control the amplitude (and therefore volume) of the sound wave rather than a simple on-off state. I want to be able to generate at least approximations of sine waves, triangle waves and sawtooth waves too. To do that, I need to be able to send an adjustable amount of current, not just a flat-out all-or-nothing.

The circuit also needs to be relatively small so it will fit into a handheld device, so the ideal solution would use a simple microcontroller circuit. But this is where I hit a bit of a snag: I'm having difficulty finding a microcontroller chip with a built-in Analog Output pin. It seems like such a simple requirement, but I'm not an electrician by trade and I'm having real difficulty finding something suitable because I don't really know what to look for.

I could use pulse-width modulation to simulate it, but I've not had very good results using this method, and that's all the majority of microcontroller chips offer. The ATTiny range of chips would have been perfect otherwise, as there's a teeny little 8-pin chip that has all the other options I need. It also seems to be the only option on Arduino and Raspberry Pi.

Now, I could use a DAC chip (Digital-Analog Converter) but that will add bulk to the electronics and, furthermore, will require several outputs from my microcontroller in order to actually drive it. Anything less than 4-bit (requiring 4 binary outputs) probably wouldn't be worth the hassle. Ideally, what I'd like is to use a small, cheap microcontroller with a built-in DAC on one of its output pins.

BUT! I don't have very good soldering skills, so it also can't be a chip that requires microsoldering. Honestly, I think my cheapo soldering iron wouldn't be capable of it even if I was! In fact, I'd vastly prefer something that I could slot into a breadboard or chip-holder, so that it was easy to take out and reprogram.

Does anyone know a chip that satisfies all these requirements?
  • Small size microcontroller chip
  • 1+ analog output pins
  • 3+ additional PWM outputs
  • 1 digital input pin for the button
  • Optionally but preferably:
    • Breadboard-compatible; no microsoldering
    • Operating voltage between 3v and 6v
    • Cost < $25
 
For the record, so far the only option I've found that MIGHT be suitable - and I stress the 'might' because I'm having difficulty finding out if it actually does have a DAC output - is the ESP32-C3. It's a breakout board, but a fairly small one so I might be able to work with it.

The ATTiny 1614 is the only other chip I've found so far, but I can only find surface-mount options and it seems expensive.
 
Hold my beer... this is exactly my thing.
Actually, I'm in the middle of designing a little analogue synthesiser gadget with a CPU to do all the sequencing etc.
I've done TONS of electronics projects so if you like, I can help out with some designs.

If you want to use PWM, you need to put in a capacitor/resistor filter to make it sound nice.
If you want basic waveforms, then the electronics is pretty easy once you know the tricks. Schmitt trigger, cap, diode and op-amp will get you a triangle wave that you can then shape.

LEDs. If you want to put in quite a few, then neopixels make the wiring much simpler and the code is pretty easy. I use AVR micros, they're SO powerful, have lots of peripherals and very cheap. I have some assembler code that I use for neopixels to get the timing right.

If you explain exactly what you want to build then I can give you some pointers.
 
  • Like
Reactions: Faust
@JakeTheDog I'm now using a double ATtiny-85 configuration. One controls the lights and receives signals from the button, the other plays appropriate sound effects based on signals it receives from the control chip. One ATtiny on its own simply won't hack it. Now, it's capable of driving a small speaker quite nicely without any amplification, although the speaker has to be pretty good quality or it's extremely quiet (currently using a 0.5w 4 ohm mini-speaker). The sound quality is just fine without any major bells and whistles, even only using PWM rather than true analogue out.

The issue I'm having right now is amplification. I've tried several different circuits, including a basic LM386, a basic transistor amp and what I think was supposed to be a Wheatstone bridge. And every single one I've tried either doesn't work at all, or actually makes the speaker QUIETER. Go figure! That said, I might not need to worry. If the speaker itself has enough oomph I might be ok, since it's a tiny little thing due to space limitations and I don't think any of these tiny speakers will ever be super-loud, regardless of amplification.

I'm actually pretty pleased with how it's working at the moment, although I do need to add code to power-down the ATtinies when there's no sound and light going on.
 
ATTinys have great shutdown modes, drawing microamps. They'll power up on button interrupts.
I need to design the speaker module for my little synth, so I'll let you know how I get on. I made a lttle speaker module a while ago but not debugged it yet. It's using a little speaker much like a mobile phone one - SUPER loud. I tend to work with SMD components, with my own home etched PCBs to begin with, then JLCPCB when I'm happy with design.
Embrace SMD! It's not as scary as it seems. though I DO use a lab microscope to solder those little blighters.
 
ATTinys have great shutdown modes, drawing microamps. They'll power up on button interrupts.
Yeah I know :) The programming part is easy as I'm a programmer by trade, just not of chips. It's the electronics that occasionally trip me up.

My hands aren't steady enough for microsoldering, and I don't know if it's worth my while paying for custom boards yet.
 
The trick is not to breathe. And definitely don't COUGH, you'll blow those teeny parts away. I can go as small as 0402 but prefer 0805 for my passives which seem positively CHONKY in comparison. Like all things, it's all in the practice.

Looking forward to seeing what you build.
 
Honestly, if I could micro solder, I'd probably use an RP2040. The breakout boards are a touch too big for my purposes though.
 
Honestly, if I could micro solder, I'd probably use an RP2040. The breakout boards are a touch too big for my purposes though.
Nice. those QFN packages give me the willies though. I've done it, but it didn't bring me any joy to do it.
Probably should have just used solder paste and hit it with the air gun.
 

Users who are viewing this thread