I can't actually see how much power that amp draws, but the IO pins can supply 20mA - I think it'd be fine for a normal opamp, but if you're powering a speaker or something with it you may well hit trouble.
You could use a transistor or FET to switch the power (or even one of those relay modules). Personally I prefer FETs as they generally switch more power and usually only require one resistor.
There's actually a page on them here - including how to wire them up using Espruino's proto area: http://www.espruino.com/mosfets
You'd probably want a PFET (something that will supply a 3.3 or 5v output when needed, rather than an N-channel FET which shorts things to ground.
Also, I'm not sure what you do when you stop playing the waveform, but if you set the output to an input afterwards you'd get a lot more noise than in you just did
Hope that helps!
Lol, no, you can't power a 2W amplifier off a GPIO pin ;-)
Use a P-Channel MOSFET to switch it
Source to +3.3v, drain to the Vcc pin on amplifier, 10k pullup from gate to source, and gate connected to GPIO pin, drive low to turn on. I was not able to find any through-hole p-channel mosfets with acceptable performance at -3.3Vgs - though in SOT-23 they are cheap and plentiful - and you're using an original Espruino board, so you can plop a SOT-23 fet down in the prototyping area.
Ya, the prototyping area changed my calculus. I'd thought about (and written) using N-channel because of the more available throughhole fet, but then I remembered that prototyping area.
I wrote in more detail in this - http://www.espruino.com/mosfets - hopefully that'll be helpful.
Thanks for your help! The guy at the electronics store happened to be even less knowledgeable than myself and sold me a BD234 transistor for a MOSFET, which it isn't. But the circuit also works with a BD234, so this issue is solved :)
I am using the Espruino board to occasionally play back recorded voice waveforms through the DAC and a connected OpAmp. When not playing anything, there is a noise from bus signals leaking into the audio. Therefore I would like to only switch on the amplifier when audio is playing and then switch it off again.
I have currently connected the OpAmps power supply pins to GND and 3.3V pins on the board. The most straight-forward idea is to connect the VCC to a digital output and then switch it on and off using digitalWrite. But can the chip handle that load? If not, how should I wire it? I think that's what transistors are for but I know nothing about analog electronics.
The amplifier I use is a Digilent PModAmp1: