Commanding servos with audio wave form.

Hi there,

First of all, I do apologies for my bad English, I'm not an English native speaker.

Here's what I d'like to create:

i'd like to create specific servo movements synchronised with specific audio songs. Indeed, by using audio etiting tools like sony vegas pro or audition adobe, I d'like to create .wav forms that would result in a specific servo movement.

For example, during a specific song moment between 1min 34 and 1min 42, I would "draw" an audio wave form that goes from let's say X hz to Z hz. This movement would then make the servo go from X degrees to Y degrees at Z speed . This would allow me, after encoding a whole song, to be able to make different servos moves according to the form I would have created on the audio editing tool.

Another example would be to create a high frequency audio form that would result in servo vibrating and so forth. In other words, rather than writing commands on the arduino software, would it be possible to create a library of frequencies in wav form that would results in movements/fonctions for servos?

I guess that would require a DAC but does anyone know how to generally do something like that? What would be the hardware/software needed or general steps? Is this even remotely possible?

Thanks in advance for your response it is appreciated.

Have you determined how fast your servo can move, and how far? Seems like that would be the first thing to do. By the way, your written English is fine.

Thanks for your answer (and my english thanks you as well, using technical words is harder than conventional talking)

Well they can go from 0 to 180 degrees in about 200ms.

Ok, now you know that it will take about 400ms or.4 seconds to go 180 degrees and back to zero. If this represents an audio wave that is what frequency? Do you have music that goes that low in frequency? Or are you thinking of dividing the audio frequency down to match the response of the servo? Or, perhaps there is no actual relationship between the servo action and the audio frequency and you only want the servo to move when some particular frequency is detected.

Paul

noxxsound:
I would "draw" an audio wave form that goes from let's say X hz to Z hz. This movement would then make the servo go from X degrees to Y degrees at Z speed .

So you're talking about monotonic audio here ? pure sine waves ? (if not, then how are you going to decide what the frequency of interest is?)
You mention X and Z Hz - then mention X and Ydeg and Zspeed

How is Y derived?

How does X>Z Hz become Xdeg>Zspeed - what function maps that over time ?

Maybe you simply overloaded the variable names? if so, try not to as it causes confusion... Question still remains, what are the functional relationships (the math/logic) between input (audio) and output (servo state)?

noxxsound:
Another example would be to create a high frequency audio form that would result in servo vibrating and so forth.

In line with Pauls train of thought:

0-180deg in 200ms - results in a 2.5Hz cycle - it's not exactly 'audio' any more, it's what some would call plain ol' position control voltage.

Signals are signals - if you happen to put them through an audio transducer (a speaker) and they happen to be such that the speaker can handle them and then also your own audio transducer (your ear) can handle them then they are 'audio'.

I guess that would require a DAC but does anyone know how to generally do something like that? What would be the hardware/software needed or general steps? Is this even remotely possible?

You don't need a DAC because the servo takes a digitally signal (digitally timed) can converts it to analog movement.

However, you can use the Arduino's ADC as input, process that input through software, and move the servo.

Indeed, by using audio etiting tools like sony vegas pro or audition adobe, I d'like to create .wav forms that would result in a specific servo movement.

If you are planning on using a soundcard as output, make sure it goes down to DC (zero Hz). Obviously, the servos can't operate at normal audio frequencies (hundreds or thousands of cycles per second.

It might be easier to program the movements completely in the Arduino's software, but you'd have to figure-out how to synchronize the movements with your audio. O.... Is there actual sound to go-along with this?

For example, if you wanted to make a sinusoidal movement you can use the sin() function (or a table). Then, you'd just have to control the speed and magnitude.

You can tackle this two ways:-

  1. Use the signal in the audio channel to directly control the servo. You will need a separate audio channel for each servo, and the audio will simply be the PPM signal that gives the servo it's position. This is done in this project, where an audio signal controls two servos to make a drawing.
    http://makezine.com/projects/trs-drawbot/
    There is software to convert the drawing into audio which you can then embed in your song.

  2. Measure a frequency in the audio and use an Arduino to control the servo. You could do this for say 7 servos by using the msgeq7 chip. This splits the audio into seven bands and gives an output proportional to the amplitude of each frequency band. You could then have seven different sin waves and the amplitude would control the servo movement.

First of all, thanks for all of your answers,

I’ll try to respond to everyone:

You can tackle this two ways:-

  1. Use the signal in the audio channel to directly control the servo …

  2. Measure a frequency in the audio and use an Arduino to control the servo.

That’s very interesting, however for 1) as it is stereo, we can only drive 2 servos right? I have 8 …

  1. I’m not sure I’ve understood this method correctly. Could I drive all 8 servos independantly?

You don’t need a DAC because the servo takes a digitally signal (digitally timed) can converts it to analog movement.

Very true, thanks for your point.

It might be easier to program the movements completely in the Arduino’s software, but you’d have to figure-out how to synchronize the movements with your audio

That is why I want to “draw” the “movements” waves using an audio editing tool so that it is already synched with the music when I create it. I’ll know that from 1min12 to 1min14 there will be a movement occuring at that precise time. If I was to program it through the arduino it wouldn’t be that easy, I would have to calculate seconds, testing each movements while listening to the music and see if it starts/stop at the right time. By using an audio editing tool I can visualise precisely where to start/stop using the sound waves.

To all, I think I’ve not been very clear with my explanations, sorry about this.

I don’t want the music to CREATE the movements. I know that my servos won’t be able to go as fast as the music goes and won’t be able to get all frequencies either.
Basically, on an audio editing tool, under the music waves. i’ll create my OWN waves at the right frequency (whatever frequencies) for the servos to be able to reproduce it. Those waves will just be created in synchronisation with the music using the software. Then I’ll export those waves movements and synchronised with the music. I’ve found a video describing from 0min20 to 1min05 the whole process, although this is for movies, it is very similar to what I want to do:

Hope it will be clearer for everyone?

How is Y derived?

How does X>Z Hz become Xdeg>Zspeed - what function maps that over time ?

You’re right, I forgot a step.

Let me rephrase it:

For example, during a specific song moment between 1min 34 and 1min 42, I would “draw” an audio wave form that goes from let’s say X hz to Y hz during Z seconds.

e.g a wave that goes from 50hz to 100hz back and forth during 10 seconds would result in 1 or multiple servos vibrating during 10 secondes.
e.g a wave that goes from 50hz to 60hz back and forth during 5 secondes would result in 1 or multiple servos vibrating harder during 5 seconds
e.g a wave that goes from 50hz to 150hz in 12 secondes would result in 1 or multiple servos going from 90degrees to 120degrees in 12 secondes, therefore at Z speed.
(Those values are random)

That’s basically something like this that I’m trying to achieve. I know that I could code it directly on the arduino, but drawing waves is much more easy to visualize when you have 1 or multiple songs to create movements for. By creating those waves on an audio editing tool. I’ll be able to have a library of already created movements for the future and just copy/paste them at the right moment.

Again, thanks a lot to everyone for your help, it is much appreciated.

however for 1) as it is stereo, we can only drive 2 servos right? I have 8 .

Nice of you to tell us up front.
As you are creating another sound channel:-

Those waves will just be created in synchronisation with the music using the software.

and not using the music itself, what is to stop you creating as many channels as you want to direct your servos.

  1. I'm not sure I've understood this method correctly. Could I drive all 8 servos independantly?

Well seven per channel per chip. Again as this is not the music channel you can create as many as you want. So use two chips and a stereo channel and you can have up to 14 servos moving interdependently.

However given your response I am not sure you will be up to designing this project so why not just have MIDI controlled servos where you put the MIDI notes into your editing suite? Or even use DMX to control the servos.

noxxsound:
For example, during a specific song moment between 1min 34 and 1min 42, I would “draw” an audio wave form that goes from let’s say X hz to Y hz during Z seconds.

e.g a wave that goes from 50hz to 100hz back and forth during 10 seconds would result in 1 or multiple servos vibrating during 10 secondes.
e.g a wave that goes from 50hz to 60hz back and forth during 5 secondes would result in 1 or multiple servos vibrating harder during 5 seconds
e.g a wave that goes from 50hz to 150hz in 12 secondes would result in 1 or multiple servos going from 90degrees to 120degrees in 12 secondes, therefore at Z speed.
(Those values are random)

You would hope those numbers are random !

We already figured out the max frequency (with any meaningful movement) your servos can achieve is 2.5Hz, but the numbers you’re giving above are well above that, they are in fact higher than the PWM update frequency for basic servos. More expensive versions can do 333Hz+ - but keep in mind that doesn’t mean they can mechanically move 333Hz, it just means their position command is updated that fast - a bit off topic perhaps…

So your audio editing software can draw sine waves ? and it can draw changing frequencies between two points ? … and that’s really useful to you, because it’s quite hard for a human to do the same… (?)

…and that’s the motion you’re after - nice sine(isn) waves of changing frequency ?

if so, and those facts combined with the ease of synchronising with playback audio - then I’m starting to dig your approach.

So 8 servos huh !

Assuming your software allows you to mix audio, then draw waveform0 through waveform7 …

then …

oooooh boy - just resized this is going to get really messy trying to explain

I’ll first ask:

  • are you aware of how a graphic equaliser operates ? (at least the overview and not the details of a solid-state or digital implementation)?

  • or for that mater a vocoder, it’s effective ‘opposite’ ?

  • are you aware of the distinction between frequency(Hz) and amplitude ? (not sure of the units in this context, but the ‘up and downy’ of the audio waveform) << this is critical

  • and then following from that AM and FM ? (the basic concepts)

Mikes suggestion of the ‘msgeq7’ is interesting - I’ve never seen/used it - but if it works it’ll afford you a method of multiplexing your ‘audio’ control signals into pretty much a let’s say interesting noise of 8 (or two streams of 4) signals …and then at the other end a method of demuxing this noise into 8 relatively pure control signals for your servos.

Critical things of note:

  • going by your descriptions you’re ‘drawing’ in AM (but with frequency being the desired metric ::slight_smile: )

can your software ‘draw’ the frequencies you’re after? they are after all inaudible (!)
if so:

  • as has been asked earlier, can your sound card/output device output inaudible frequencies?

(why would it be designed to do so??)
if so:

  • can this ‘msgeq7’ chip deal with inaudible frequencies ?

a better solution might be push everything up in frequency and start to think in terms of frequency modulated signals - unless that’s what you meant ?

sorry, not enough data to look at your youtube video atm

and not using the music itself, what is to stop you creating as many channels as you want to direct your servos.

Well I thought that, as per the example, they were using a Phone jack to get the stereo signal out. For 8 servos I would be using the arduino instead?

Well seven per channel per chip. Again as this is not the music channel you can create as many as you want. So use two chips and a stereo channel and you can have up to 14 servos moving interdependently.

However given your response I am not sure you will be up to designing this project so why not just have MIDI controlled servos where you put the MIDI notes into your editing suite? Or even use DMX to control the servos.

I've just looked into MIDI and you're right, It seems a pretty straightforward solution. And yeah, as you can see, I'm having trouble designing a project of this size, thus my presence on this forum.
So by using an arduino, a MIDI to ISB software (haireless MIDI to serial bridge) and a MIDI editor, I should be able to move those 8 servos. Some people are talking about the teensy board or the Servocenter USB board but I guess the arduino should do it fine.

I'd rather use MIDI over DMX which is more light oriented, MIDI is for audio and, therefore, more in theme with what I want to achieve.

So your audio editing software can draw sine waves ? and it can draw changing frequencies between two points ?

Yes and yes. But as Grumpy Mike said, MIDI seems to be a solution much easier to implement.

a better solution might be push everything up in frequency and start to think in terms of frequency modulated signals - unless that's what you meant ?

Yes, that's what I meant. Again sorry that my english give me some trouble finding the right words to describe correctly my project. I know you guys are spending time trying to understand what i'm writing based on a few bad explained and incomplete sentences . Sorry about that.

To resume, I think I'll go with the MIDI solution,

I've found two good examples that could be applied to what I'm trying to achieve. They're not very very detailed but here they are:

http://nysoundworks.org/teaching/automata2013/midi-over-serial-with-hairless/

On the first link, the guy is using an teensy board. Do you think an arduino can do it?

Again thanks for you help guys.

You want a MIDI receiver, this project fires solenoids from MIDI notes but it is just as simple to control a servo:-
http://www.thebox.myzen.co.uk/Hardware/Glockenspiel.html

I did make an 8 channel MIDI to servo controller as a commission a few years ago. I have just uploaded a video of it so you can see. Not the best production quality but you get the idea.

Yes, your problem now is basically interpreting MIDI protocol to servo protocol.

MIDI in (roll your own or buy off the shelf)
Extract 8xchannels mod wheel info
Offset/scale
Servo out

You might have to think about what you're going to do about the different time scales involved. Hrrrm, but MIDI has no clock huh? And although servo PWM runs at 50Hz, sending a pos command at 'whatever' Hz doesn't seem to hurt it though... Maybe you don't ? ::slight_smile:

@1:1

Most of what you wrote in that last reply is totally wrong. Have you used MIDI at all?

your problem now is basically interpreting MIDI protocol to servo protocol.

It is not at all a problem, there are several ways to do this but perhaps the simplest is the note on message, using the note value to define the servo and the velocity value to define the servo's position.

Extract 8xchannels mod wheel info

No you don't use the mod wheel at all.

You might have to think about what you're going to do about the different time scales involved.

No that is not even a factor, you put the messages in where you want them in the score.

but MIDI has no clock huh

But MIDI does have a clock, it is just that you don't need it here.

And although servo PWM runs at 50Hz

Absolute rubbish. First it is not 50Hz and second it is not PWM it is PPM for driving a servo correctly.

sending a pos command at 'whatever' Hz doesn't seem to hurt it though..

Again rubbish, yes you can "hurt" the servo with the wrong frequency of the PPM

Maybe you don't ?

Don't what. Up to the quality of the other statements in this post.

You want a MIDI receiver, this project fires solenoids from MIDI notes but it is just as simple to control a servo:

Yes! That seems to be it!

I did make an 8 channel MIDI to servo controller as a commission a few years ago. I have just uploaded a video of it so you can see. Not the best production quality but you get the idea.

Looks terrific! So from what I can see, you have an 8 channel MIDI but only one servo is wired up right? So you could plugged in 7 more servos and control them independantly exact?.

My last bunch of questions is electronic related.

  • As I would be driving servos through a midi software, do I still need a MIDI socket or can I use the hairless USB serial or just a USB or a Midi to USB adaptator?
  • Your electronic box looks full of boards/electronic and I couldn’t see an arduino in it. I’ve you used one? Looking at the MIDI Glockenspiel webpage, all the detailed schematic seems to be there. They’ve used an opto Isolator 6N139, a 74121 and some LM18293. I was wondering if the LM18293 were to be used for servos as well as it is signal that goes in. I mean, for your own project, have you used the exact same schematics? A coil works a bit differently than a servo as a coil only have ground and positive when the servo has ground, positive and signal so I was wondering if this schematic would do it. Moreover as the document said “The output pins of an Arduino are only 5 volts so to convert the logic signals up to the 12 volt levels needed to drive the solenoids I used an LM18293 driver chip” therefore I’m wondering if for a servo, which is 5 volt, I could just plug it in directly in the right arduino PIN without going through an LM18293.

Anyway, I was just wondering if for your project, the schematic of the Glockenspiel was the same. If yes, I’ll start building it. If it seems to complicated, I could still use the teensy board which is an already made circuit exact?

Again thanks for your answer that has been a great help to me

So from what I can see, you have an 8 channel MIDI but only one servo is wired up right? So you could plugged in 7 more servos and control them independantly exact?.

Yes that is correct.

can I use the hairless USB serial

Yes.

or a Midi to USB adaptator

Then you still need the MIDI interface to give you the socket. MIDI / USB adapters have a MIDI plug on them.

I couldn't see an arduino in it.

There is a stand alone Arduino, I built it from scratch, I did not use an actual Arduino board, I seldom do for complete projects. Like that MIDI beater, there is no Arduino board just the processor and other bits I need.

I was wondering if the LM18293 were to be used for servos as well as it is signal that goes in.

There is no need you just connect the servo directly to a processor pin.

I mean, for your own project, have you used the exact same schematics?

No, in a way it is a lot simpler, there is no need to buffer the output. You do have to watch the power supply to the servos, these take a lot of current and can generate interference so you need a different power supply and / or heavy decoupling. See the last circuit on this page:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Again, thanks!

Yes.

If I can use the hairless usb serial then I don't have to build the MIDI socket + opto isolator then. Good news, however, I'm not sure how the signal goes in the Arduino. On the Glockenspiel, the MIDI socket is here to get the signal from the computer and this signal is going through the opto isolator that goes into pin 0.
If I remove all this by using Hairless usb serial, is the signal gonna get in directly through the arduino USB socket in real time? if yes that's a whole lot easier.

Then you still need the MIDI interface to give you the socket. MIDI / USB adapters have a MIDI plug on them.

Yes of course but I would still try first with the Hairless serial USB and if it doesn't work I'll do the circuit with the opto isolator.

There is a stand alone Arduino, I built it from scratch, I did not use an actual Arduino board, I seldom do for complete projects. Like that MIDI beater, there is no Arduino board just the processor and other bits I need.

Impressive, may I ask what MIDI software have you used on the video?

There is no need you just connect the servo directly to a processor pin.

That's what I thought, good news. Therefore I don't need the 74121 neither right?

You do have to watch the power supply to the servos, these take a lot of current and can generate interference so you need a different power supply and / or heavy decoupling. See the last circuit on this page:

Yes for my current circuit where I'm controlling those 8 servos with a PS2 controller I have an external power supply of 5V 10A which is way enough.

So basically to resume,

To get those 8 servos functionning with a MIDI software I need:

  • An arduino (I'll use the MEGA)
  • The Hairless serial USB OR a MIDI interface
  • The servos
  • An external power supply

So by removing the LM18293, the MIDI interface and the 74121 on the Glockenspiel schematic. There's nothing much left to build as a circuit. I mean, my current circuit of 8 servos being controlled by the PS2 controller going into pin 13,12,11 and 10 of the arduino is already made so I'll remove the PS2 controller to keep the 8 servos on the circuit connected to the voltage and the arduino and I shouldn't be far from making it work then.

Have I forgotten any electronic circuit related parts?

I'm not sure how the signal goes in the Arduino.

It comes in to the serial port just like it would if you had a MIDI shield and traditional MIDI plugs.

what MIDI software have you used on the video

Just Garage Band - came free with the Mac.

Therefore I don't need the 74121 neither right?

Right, the 74121 is a monostabe to provide a pulse to the solenoids.

Have I forgotten any electronic circuit related parts?

Sounds fine. Remember you can also use the analogue pins as digital outputs for PWM so there is no need to disconnect anything if you don't want. Analog input 0 is digital pin 14, Analog input 1 is digital pin 15 and so on.

Great! I'll give it a try. I've prepared my breadboard with all the servos.
I've successfully connected Garageband to the Hairless Serial to my arduino. I can see the LED 13 blanking when doing stuff on the garageband.
I've used the Glockenspiel code to give it a try but it is not appropriate at all as it is made for coils.

What I'm gonna try to do is to keep my functions I've created (about 30 of them that make a group of servo do specific movements) and to call those functions with the MIDI note I'm gonna play.

A thousands thanks to all and to Grumpy Mike for the time you've spent helping me.

I'll keep you updated of my progress, hopefully I won't need some help but If I do you'll see me back here :slight_smile:

I’ve used the Glockenspiel code to give it a try but it is not appropriate at all as it is made for coils.

Just attach and LED and resistor to the pins that used to drive the coils and you will get an idea of what is going on.

Good luck with your project.