We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Armstrong - Music with the Arduino

00:00

Formale Metadaten

Titel
Armstrong - Music with the Arduino
Untertitel
No shields required!
Serientitel
Anzahl der Teile
199
Autor
Lizenz
CC-Namensnennung 2.0 Belgien:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen.
Identifikatoren
Herausgeber
Erscheinungsjahr
Sprache

Inhaltliche Metadaten

Fachgebiet
Genre
Abstract
Generating music from an Arduino usually needs a shield. And shields cost money. This talk introduces a project that makes it free and easy to play sound without a shield, nor a knowledge of musical theory. We shall introduce a number of projects that make the Arduino make noises, other than the squeaks of the example code. This includes the new library, Armstrong, which supports various methods of playing music, along with MIDI functionality, all from a vanilla Arduino
65
Vorschaubild
1:05:10
77
Vorschaubild
22:24
78
Vorschaubild
26:32
90
115
Vorschaubild
41:20
139
Vorschaubild
25:17
147
150
Vorschaubild
26:18
154
158
161
Vorschaubild
51:47
164
Vorschaubild
17:38
168
Vorschaubild
24:34
176
194
Vorschaubild
32:39
195
Vorschaubild
34:28
Spezifisches VolumenFunktionalZahlenbereichProgrammierungErhaltungssatzMusterspracheAbstraktionsebeneVersionsverwaltungKonfiguration <Informatik>Ein-AusgabeGamecontrollerLoopBildgebendes VerfahrenRechenschiebert-TestATMGruppe <Mathematik>Digitales DrucksystemTermSchlussregelProzess <Informatik>Web-SeiteEchtzeitsystemWiederherstellung <Informatik>SpieltheorieMultiplikationsoperatorAutomatische HandlungsplanungRahmenproblemMereologieSpeicherabzugGeräuschMAPStellenringAggregatzustandDynamisches SystemStandardabweichungObjekt <Kategorie>CodeOktave <Mathematik>Message-PassingGeradeFunktion <Mathematik>Endliche ModelltheorieDigitalisierungProgrammbibliothekHardwareSoftwareAusdruck <Logik>MIDI <Musikelektronik>LastProjektive EbenePersönliche IdentifikationsnummerAnalogieschlussGanze FunktionInterrupt <Informatik>Umsetzung <Informatik>MultitaskingQuellcodeDreiecksfreier GraphDifferenteSystemaufrufComputervirusKonfigurationsraumComputeranimation
MereologieProgrammbibliothekCodeQuick-SortWellenformGarbentheorieZeichenketteVerschlingungDatensatzMultiplikationsoperatorSoftware Development KitDifferenteSweep-AlgorithmusEin-AusgabeTypentheorieRandomisierungBildschirmmaskeBitSpannweite <Stochastik>Lokales MinimumZentrische StreckungComputerspielDickeGüte der AnpassungRechenschieberEinsEnergiedichteCASE <Informatik>MeterSpezielle unitäre GruppeDigitaltechnikGebäude <Mathematik>FunktionalSystemprogrammAbstraktionsebeneFront-End <Software>GeradeAbschattungPersönliche IdentifikationsnummerAnalogieschlussGruppe <Mathematik>FrequenzWellenlehreWeißes RauschenHarmonische AnalyseSprachsyntheseGeräuschInterrupt <Informatik>LoopSchallenergieStichprobenumfangSchätzfunktionServerAbstimmung <Frequenz>VerkehrsinformationDatenfeldPlenoptische FunktionPolstelleFormale SpracheQuaderATMBeweistheorieGamecontrollerMomentenproblemMathematische LogikBitrateOrdnung <Mathematik>SchnittmengeWeb SiteDatenbankQuellcodeMathematikRadikal <Mathematik>AuswahlaxiomErschütterungBeobachtungsstudieSummierbarkeitTeilbarkeitBildschirmsymbolEndliche ModelltheorieComputeranimation
Persönliche IdentifikationsnummerMultiplikationSpannweite <Stochastik>WellenformOrdnungsreduktionATMDifferenteComputeranimation
Transkript: Englisch(automatisch erzeugt)
The people at the left, can I ask you not to use the stairs, please, by security? You have a lot of places at the center of the rooms. Mm-hmm.
Mm-hmm. Mm-hmm. Mm-hmm. Mm-hmm. Mm-hmm. Mm-hmm.
Mm-hmm. Mm-hmm. Mm-hmm. Mm-hmm. Mm-hmm. This is the fourth time up on the lightning call on four different cycle and source projects. And every time it's... Oh! Oh!
Oh! Oh! Oh! Oh! Oh! Oh!
Mm-hmm.
It's just Tim configure for all of them.
Mm-hmm. It's like Hobou. Yeah, yeah.
For our next talk, Stephen Goodwill is a little jack of all threads, because in the end he is a maker, an author, a dev, sometimes a magician also, an educator, and today it
will be the musician we'll have as he will explain us how to build an Arduino without a shield to make music. Let's applause Stephen Goodwill. Thank you. Hello. So, as that part of the slide says, my name is Steve, and as that
part of the slide says, we're doing music with the Arduino. And I have the little pre-text on the slide that says, no shields required. I couldn't come up with a better Star Trek joke, unfortunately, so you'll have to like it. It just means that all the music that we'll be making, and I use music in the loosest sense of the word, we'll be using this device and nothing else.
So, how did we used to do music on the Arduino? A few magic numbers and the function tone. This works fine, it's not a problem, however, tone uses interrupts, and if you want to use interrupts for something else, like something useful, you can't because this tone is stealing it. So, instead, we have this. This is a much, this is an improvement.
Is there a two lines of code? We now have lots. However, it is better, honest, honest, because this is what it sounded like back in the day. And this is what it sounds like now. See, so much better, isn't it? I can see I've got an entire
audience of converts already. However, this does have some improvements, honest gov. So, what are they? Well, the first thing is we're doing some abstraction here. Instead of saying write to pin 8, we're actually saying channel 0, for example. Why is this an improvement? Well, if you want to switch from using digital pins to analogue pins and use the pulse width modulated functionality of the board,
you'd have to reprogram half your library. Well, don't. Just change the channel to be a digital pin rather than analogue one, which it knows automatically. It says if you're going on pin 7 or pin 8, it knows what's analogue, what's digital, and it sets everything up accordingly. That is actually an improvement to me because I never bother checking my pins. Also, you've got serial debugging.
Without even trying, if you use the tone function, it makes a note. Whereas if you use the Armstrong libraries to make the note, you could also say would you mind tracing out what notes you're playing and when so you can actually debug it without saying is the software at fault or is the hardware at fault? That's one thing you can do. And you can just change it to be a MIDI output
rather than an audio output with a speaker with one line of code. Again, we've got here the playing string, which is saying I'm going to play the note of C. However, you can play many notes just by changing this.
Yes, the theme from The Exorcist or Tubular Bells Part 1 depending on how old you are. I'm assuming that's a laugh from the elder people in the audience. So, yes, you can string a whole load of notes together, but also you've got other control messages. You can change the tempo, the duration of the various notes, and you can move around the octaves. So instantly you've got some much quicker
way, a more effective way of changing the music, of writing music and having it run. Tone as a function and the standard note playing in Armstrong is a blocking function. Nothing happens until it's finished playing the music. However, this is moderately useless because most of the time you want to do something else.
If you're doing a game at the end of the level it makes a little jingly noise to say wow, you've won or you've lost. That's fine. If you're doing music during the game, for example, and you're doing a little flashy light game, you can't do it. It must be non-blocking. So what we use is this idea of an update function which allows you to do co-operative multitasking. So we don't have any interrupts
whatsoever. Just every frame it says just change the speaker. Do you need to change the speaker? Have another go. Just every single frame. And because this goes quick enough, you can actually generate notes like this. See, because I'm changing the pitch, because I'm not stuck with a blocking function, as you
go through, you can change the pitch of that note or the volume of that note in real time. So if you want to add some vibrato to your note, you can actually vary the pitch in each update loop. So you've got a fair amount of control of what you can do with that sound. Also provided are a number of input abstraction layers. I like abstraction layers. This is
the analog one. He says having to look at his notes. Your input is going to be between 0 and 5 volts. Fair enough. However, when you get to actually read the port it's going to say it's between 0 and 4095. However, I want it to be a note. So what this does is it automatically says
I will read the input and I will automatically scale it to a note between, for example, C2 and C6. Also, you can scale the input range itself. If you have an LDR and you're building a light terra mean, for example, so as you cast shadows over your light sensor, it varies the pitch of the note, which is one line of code here. Your LDR
might not be able to register the full range of 0 to 4095. 0 will be complete darkness and 4095 would mean you stuck it into the middle of the sun. You don't have that range, so you just say, well, whatever range the LDR does have, which is 1 to 500 in the case of the ones I've been playing with, that just automatically scales so you get the maximum range possible.
Again, this is not complex code. This is not magical code. None of this is going to change your life. But if a thousand people are making little music, little MIDI trigger apps or music apps, that might be a hundred or a thousand people who are writing the same really dull hundred lines of code.
There's also digital abstractions as well. So here we've got two forms of toggle button. You press a button, it changes from on to off, or you press it, and while you're pressing it, it goes on. This gives you a couple of different ways of abstracting the input to make a different sort of musical instrument. And you can put debounce into here as well for free
because debouncing push buttons is the most dull piece of code you'll ever write. So the library itself, it's broken up into parts because my brain can only handle a very small thing at a time. So we have the music playback, which is what we did the Exorcist theme with. You give it a string of notes, it plays the notes, one after the other, blah blah blah blah blah. This calls
the note playback, which says now play C, now play E, now play A, now play B. That's one extra section of the library. That in turn calls the note control. This is what allows you to switch a note on, switch the note off, and actually work in the update loop so it doesn't need interrupts but still plays asynchronously to the rest of your code. And the Waveform library,
which is so brand new I don't even have any documentation on it, but it actually makes some different noises. I'm not even sure if I've got them on here. Let's see. Let's try that, see if that makes a noise. Yes, it makes a very quiet noise. The Waveform library lets you create an abstract wave of any
type and then pump it through the analogue pins on your Arduino. So you can actually use this for playing back speech if you want to take a sample, put the whole lot into an array, and then play that. You can do that. Or you can use harmonics. And then actually say, right, this is a primary harmonic, there's a second, a third, and a fourth of different rates, and it will generate the wave and it will then play it through the speaker.
And the analogue inputs and abstractions that we've seen, plus some utility functions for those that want to know, well, what is the frequency of A above middle C? The answer being 440 hertz for those that are interested. This was the very first example that I made, partly because I play Lego and partly because I can't build anything unless it is Lego.
This is a Tanoine, and you may have noticed that all the slides have a music quote in them. There was a Duran Duran quote there. Who got the Duran Duran title? Who's prepared to admit they got the Duran Duran title? Only me then. Jolly good! So Good Vibrations, the Beach Boys song, people think that was a Tanoine. It was actually a Tanoine,
which is basically a length of a micron wire. A micron wire has a fairly high resistance for what is basically a piece of cable. So what you do is you put a crocodile clip halfway across that wire and it creates a potential divider circuit. You then take that and abstract it into your input so wherever you put the crocodile clip along this meter of wire makes a different note.
A nice sort of sweeping note. And of course it's made with Lego. This is another thing you can do. The piezoelectric buzzers which you can get, as well as making a noise, are also capable of taking in input. All it does is it's just a transducer. It converts sound waves, sound energy, into electrical energy. So as well as
outputting buzzer noises, if you hit them, it generates a spike like that. And then you can use the input library to say, well, as soon as the spike goes above this indicates a trigger of a sound. And that trigger of a sound can play notes and buzzes or white noise from a sort of a snare or a hi-hat kind of a sound. And if you've put one of these under a mouse mat, or as the chap here has done,
under a proper drum pad, you can actually build yourself a very small electronic drum kit with five or six of these 20p devices and an Arduino. And a speaker if you actually want to hear anything. But I think I've managed to go on time, which is unusual for me since I normally talk about ten times as long.
Which means I actually have time for questions, although I'm hoping there's not going to be any, because I'm not very good at that bit. Because I can't rehearse the questions. When I rehearse the talk, I get all my teddy bears in a row. You all do this, right? And I give the talk to the teddy bears. Because if I can explain it to a teddy bear, I can explain it to a bunch of geeks.
So, I've rehearsed up to here. Questions I'm kind of going out on a limb if there are any. The links which I hopefully can see are all at the Marquis site, which is also where I do FOSDEM Diaries, JavaScript, Lego, GTA, and other bits of random stuff. If you can't be bothered to type the whole URL, just go there and you'll find it.
There might even be some other notes on here if I do the... Really, really, I wonder if we're having a... never mind.
But just as proof, that was all running just with no shields. A piece of wire, a resistor, and the speaker. I was not... I know you can't see down there. I just wanted to prove there are no shields in this. So, yes, if I have actually finished, then I will take any questions that I can in the time remaining. But I can't see how long.
So, where's the question? Do you have an idea what the frequency range is? No, haven't properly tested it. OK, thanks. I'd like to give you a really proper answer. The sweep that I was doing earlier was I think between 200 and about 6,000 hertz.
That's all audible. It has gone up to about 10,000 hertz. I have no musical use for anything up that high. Obviously, lower frequency is going to be easier because you need to change the waveform less often, so you've got scope for that, and then it's down to whatever amplifier and speaker you end up shoving at the back end.
This is running so fast, you've got a fair amount of scope. So I don't think the range is going to be an issue. Plus, of course, you've got multiple channels on this, so what you can always do is say, well, because it's non-blocking, you can say I'll put three speakers on three different pins and they can all play different notes. So if you want polyphony, you can do it that way rather than having to build a waveform with
all of the different notes concatenated in. Another question? Okay, thank you, Steven, for your talk. You're welcome.