Arduino Synth

32 views
Skip to first unread message

Michael Nicholls

unread,
Sep 3, 2009, 9:21:18 AM9/3/09
to Birmingham Hack Space
Since the first version of the IR is now built and working (will bring
it along next week), I was thinking I would like to jump into an audio
project seen as it fascinates me and would be good for 8 bit lounge.

Inspired by projects like Nikki's, I was just thinking of a simple PWM
noise generator, but building in a 16 step sequencer so you could
program the sound to be on or off at each step, or maybe change the
pitch at each step. Basically you could vary a number of parameters at
each step, but to keep it simple initially I was thinking maybe just
sound on/off.

Initially I was just going to get a speaker hooked up with some pots
and play with some sound. I remember G saying to drive a speaker I
would be best with an audio amp and looking at it I think an LM386 is
a good place to start.

Is there anything I need to be aware of or can I just hookup the LM386
to Ardunio's 5v, feed it with an Arduino pin and then hook the output
to a speaker or is there more to it than that? e.g. do I need
protection components in place? will it work ok from 5v? (I read the
one version can run from 4v - 12v). Also just trying to understand the
maths behind the Amp. How do i know how much the signal has been
amplified and how do the current/voltage levels relate to the Arduino?
(Are they uncoupled?).

Also to implement the 16 step sequencer I would have 16 LED's that
represent the steps, since this is more than the number of pins I
would presume something like a shift register would be needed. I have
read about output shift registers, but I assume you can get input
ones? (Was thinking might want a bank of switches as well).

Mike

G Bulmer

unread,
Sep 3, 2009, 8:44:30 PM9/3/09
to Birmingham Hack Space
On Sep 3, 2:21 pm, Michael Nicholls <nicholls...@googlemail.com>
wrote:
> Since the first version of the IR is now built and working (will bring
> it along next week), I was thinking I would like to jump into an audio
> project seen as it fascinates me and would be good for 8 bit lounge.
>
> Inspired by projects like Nikki's, I was just thinking of a simple PWM
> noise generator, but building in a 16 step sequencer so you could
> program the sound to be on or off at each step, or maybe change the
> pitch at each step. Basically you could vary a number of parameters at
> each step, but to keep it simple initially I was thinking maybe just
> sound on/off.
>
> Initially I was just going to get a speaker hooked up with some pots
> and play with some sound. I remember G saying to drive a speaker I
> would be best with an audio amp and looking at it I think an LM386 is
> a good place to start.
Yes, LM386 are "cheap as chips" (under 50p).

> Is there anything I need to be aware of or can I just hookup the LM386
> to Ardunio's 5v, feed it with an Arduino pin and then hook the output
> to a speaker or is there more to it than that?
That's what I'd do.
I have a 64 ohm speaker from Rapid to keep the current low (there
about 75p from Rapid)
Not HiFi, but almost disposable at that price.

> e.g. do I need
> protection components in place? will it work ok from 5v? (I read the
> one version can run from 4v - 12v). Also just trying to understand the
> maths behind the Amp. How do i know how much the signal has been
> amplified and how do the current/voltage levels relate to the Arduino?
> (Are they uncoupled?).
The LM386 are, by default set to amplify by a factor of 20x, which is
more than you need, so I'd try a potentiometer as a volume control.

> Also to implement the 16 step sequencer I would have 16 LED's that
> represent the steps, since this is more than the number of pins I
> would presume something like a shift register would be needed. I have
> read about output shift registers, but I assume you can get input
> ones?
Not exactly sure what you mean by "input ones".

Data is 'clocked' through a shift register, one bit at a time. It is
clocked with a full cycle of a square wave.
You can load data one bit at a time (Serial In - SI, only uses two
pins), or a whole "byte" in one go (Parallel In - PI).
The data can be output one bit at a time (Serial Out - SO) or
'broadside' in a whole "byte" (Parallel Out - PO, to many pins)
To expand the number of pins, use a Serial In, Parallel Out (SIPO)
shift register.
Something like a 74HC164 would do, less than 40p.
It'll take 2 pins to drive upto 8 LEDs.
A further 8 LEDs would need one more 74HC164, and one pin because you
could drive both shift registers clocks from a single pin.
A further 8 LEDs, another pin and 74HC164, and so on.

There is one extra refinement.
The Parallel Output can be 'transparent', it changes as the data is
clocked through (like the 74HC164), or it can be buffered.
A buffered version can be nicer because the LED values change once you
have all of the bits set. I haven't had a good read, but I remember
something lie a 74HC595, which looks about right.
It'd take 3 pins, an extra one to copy the data from the shift-
register into the buffer. Again the buffers of several shift registers
could be controlled with a single pin.

The alternative is to use a 16-way LEd driver, like a STP16CP05M

> (Was thinking might want a bank of switches as well).
Could read a bank of switches with a PISO shift-register; each of the
switches to an input.
There is probably no need to use buffered devices, though it'd do no
harm.

GB

Michael Nicholls

unread,
Sep 4, 2009, 6:38:21 AM9/4/09
to Birmingham Hack Space
Thanks G.

Where would I connect a pot so that it acts as a volume control and
what value pot would be best? Also would I need a log pot for volume?

I think by input ones I meant shift registers that would allow me to
read data in, but from your explanation I can see I would use a
Parallel In - Serial Out to allow me to read a bank of switches ;-)

Ultimately I was thinking of maybe going for two banks of 16 LEDS. One
bank that reflects the state of the switch associated with it and one
bank that shows the position of the currently playing 'note'.

You can get push buttons that have LED's under can't you? Was maybe
thinking that pressing a switch might toggle its state and illuminate
it, but can you read a push button like that quickly enough through
shift registers? Can you then trigger the associated LED quick enough
through a shift register? By quick enough I mean so it looks like it
lights up when you press it and turns off when you press it again?

Mike

G Bulmer

unread,
Sep 4, 2009, 12:53:19 PM9/4/09
to Birmingham Hack Space


On Sep 4, 11:38 am, Michael Nicholls <nicholls...@googlemail.com>
wrote:
> Thanks G.
>
> Where would I connect a pot so that it acts as a volume control
One end to ground, the other end to an Arduino pin, and the 'wiper' to
the input of the LM386.

> and what value pot would be best?
I'm not sure.
I think 1K would be a reasonable compromise (low-impedance into the
amplifier, and high impedance on the Arduino pin).

Thinking about it, it'd be sensible to AC couple the the amplifier to
the speaker with a capacitor (in series). I think that might be in the
datasheet anyway.

Also, it'd make sense to use a capacitor on the amplifier input as a
low-pass filter (so the very fast transitions from the PWM get
reduced). A capacitor of around 100nF sounds about the right ball-
park.

> Also would I need a log pot for volume?
That would be better, but for experiments, anything you can find. I'd
use a cheap preset until I'd understood how well it works. Presets are
pretty cheap:
http://www.rapidonline.com/Electronic-Components/Resistors-Potentiometer/Preset-Potentiometers/3-frac12-8in-Single-turn-finger-adjustable-potentiometer/81452
and less tempting to twiddle once you've got it about right :-)

>
> I think by input ones I meant shift registers that would allow me to
> read data in, but from your explanation I can see I would use a
> Parallel In - Serial Out to allow me to read a bank of switches ;-)
Exactly.
If you google for PISO or SIPO "shift register" "8-bit" you'll find
relevant parts.

>
> Ultimately I was thinking of maybe going for two banks of 16 LEDS. One
> bank that reflects the state of the switch associated with it and one
> bank that shows the position of the currently playing 'note'.
Yes. I was thinking along similar lines. That's why I suggested you
could parallel up the clocks from one pin, to save pins.
You can also daisy-chain the shift registers outputs to inputs.
(double check the datasheet to make sure the serial-data-out becomes
stable on the opposite edge of the clock to serial-data-input - they
should work this way, I'm just a bit careful).

>
> You can get push buttons that have LED's under can't you?
Yes.
http://www.rapidonline.com/Electronic-Components/Switches/Control-Unit-Switches/8mm-Control-units/80340

> Was maybe
> thinking that pressing a switch might toggle its state and illuminate
> it, but can you read a push button like that quickly enough through
> shift registers?

Well, I haven't timed it for a while, so I may be mis-remembering, but
not by more than 2x.
My recollection is I could load a shift register to change the state
of 6 LEDs in much less than 10uSec (i.e. 100,000 times/second), and
listening to switches would be a similar rate.
I wasn't using digitalWrite, but going 'straight to the pin' ( I was
concerned to do this reasonably quickly)
My other experiences are digitalWrite/digitalRead is about 4x-10x
slower than manipulating pins 'raw' (variation depends on a couple of
factors).
Now I may be mis-remembering, and it is *much* less than 10uSecs.

This is so fast that you probably don't need to worry.
You may need to scan switches several times, several milli-seconds
apart, to see if there is switch 'bounce', but you'd have that problem
if switches were directly into an Arduino anyway.

> Can you then trigger the associated LED quick enough
> through a shift register?
If we are talking human-scale-time, definitely.
The eye is amazingly sensitive to light, so a brief (under a milli-
second) flash will register, but conversely, a many milliseconds early
or late doesn't seem to matter (to my Human-World interface, or
HuWi :-)

> By quick enough I mean so it looks like it
> lights up when you press it and turns off when you press it again?
I believe yes.
I notice 100mSec delays, and don't seem to notice sub 10 mSec delays
at all, so I would expect it could probably be done 100-1000x faster
than I can perceive.

HTH
GB-)

Michael Nicholls

unread,
Sep 9, 2009, 7:46:48 AM9/9/09
to Birmingham Hack Space
That all sounds good.

I just need to get hold of some bits and start playing now.

Don't think I will have chance to pick anything up before tonight
though, but sounds like you have some bits to work on the Laser Harp
and I have an Android/OpenGL/Game side project I am working on :-)

Hopefully will be able to pick the camera up to demonstrate the
finished first version of the IR remote if people are interested?

Mike

On Sep 4, 5:53 pm, G Bulmer <gbul...@gmail.com> wrote:
> On Sep 4, 11:38 am, Michael Nicholls <nicholls...@googlemail.com>
> wrote:> Thanks G.
>
> > Where would I connect a pot so that it acts as a volume control
>
> One end to ground, the other end to an Arduino pin, and the 'wiper' to
> the input of the LM386.
>
> > and what value pot would be best?
>
> I'm not sure.
> I think 1K would be a reasonable compromise (low-impedance into the
> amplifier, and high impedance on the Arduino pin).
>
> Thinking about it, it'd be sensible to AC couple the the amplifier to
> the speaker with a capacitor (in series). I think that might be in the
> datasheet anyway.
>
> Also, it'd make sense to use a capacitor on the amplifier input as a
> low-pass filter (so the very fast transitions from the PWM get
> reduced). A capacitor of around 100nF sounds about the right ball-
> park.
>
> > Also would I need a log pot for volume?
>
> That would be better, but for experiments, anything you can find. I'd
> use a cheap preset until I'd understood how well it works. Presets are
> pretty cheap:http://www.rapidonline.com/Electronic-Components/Resistors-Potentiome...
> and less tempting to twiddle once you've got it about right :-)
>
>
>
> > I think by input ones I meant shift registers that would allow me to
> > read data in, but from your explanation I can see I would use a
> > Parallel In - Serial Out to allow me to read a bank of switches ;-)
>
> Exactly.
> If you google for PISO or SIPO "shift register" "8-bit" you'll find
> relevant parts.
>
>
>
> > Ultimately I was thinking of maybe going for two banks of 16 LEDS. One
> > bank that reflects the state of the switch associated with it and one
> > bank that shows the position of the currently playing 'note'.
>
> Yes. I was thinking along similar lines. That's why I suggested you
> could parallel up the clocks from one pin, to save pins.
> You can also daisy-chain the shift registers outputs to inputs.
> (double check the datasheet to make sure the serial-data-out becomes
> stable on the opposite edge of the clock to serial-data-input - they
> should work this way, I'm just a bit careful).
>
>
>
> > You can get push buttons that have LED's under can't you?
>
> Yes.http://www.rapidonline.com/Electronic-Components/Switches/Control-Uni...

Antonio Roberts

unread,
Sep 9, 2009, 10:30:42 AM9/9/09
to birmingham...@googlegroups.com
> and I have an Android/OpenGL/Game side project I am working on :-)

I'll probably be picking your brain apart to find out what this whole
OpenGL thing is!

> Hopefully will be able to pick the camera up to demonstrate the
> finished first version of the IR remote if people are interested?

Yes please!

Ant

2009/9/9 Michael Nicholls <nicho...@googlemail.com>:

Michael Nicholls

unread,
Sep 9, 2009, 10:33:30 AM9/9/09
to Birmingham Hack Space
No problem.

I have approached OpenGL several times for a few things and only just
starting to get my head round it, but having Luigi walking around on
my phone is fun ;-)

Mike

On Sep 9, 3:30 pm, Antonio Roberts <bv3...@gmail.com> wrote:
> > and I have an Android/OpenGL/Game side project I am working on :-)
>
> I'll probably be picking your brain apart to find out what this whole
> OpenGL thing is!
>
> > Hopefully will be able to pick the camera up to demonstrate the
> > finished first version of the IR remote if people are interested?
>
> Yes please!
>
> Ant
>
> 2009/9/9 Michael Nicholls <nicholls...@googlemail.com>:
Reply all
Reply to author
Forward
0 new messages