Microcontroller Fabric Tone Generator in C-code by pstretz
Featured
At the end of October last year instructables user carmitsu sent me a message after seeing my lunchbox synth. From his message:

I teach music in elementary school. We play a lot of recorder music. i.e. the kids play little flutes...... I have several special needs kids who can are using these black poster boards with circles that have the name of the note on them. These students push on the circles with notes names at the same time the rest of the students are playing a song..... Most of the special needs kids can do this fairly well and in time with the music.
What I am looking to to is build a very simple sound generator so that these kids could play the same pitch as those being played by the students on their recorders. I would only be a few pitches. I thought I could attach some kind of small button to the bottom of their round circles so that when they push on them the sound would come out of a small speaker, loud enough so they could hear.

Having a mother who is a teacher and having liked school, how could I resist? Truth be told I couldn't. This is pretty much a chronicle of the project and instructions on how to build your own.
 
Remove these adsRemove these ads by Signing Up

Step 1: The beginning or why I couldn't stick to analog

FDPDcomb.jpg
The good stuff starts on the next page. If you want to know how I ended up using the parts I did, read on.

The veritable timer:
After giving the project some thought I immediately thought of the piezo tone generator from my op-amps Forest Mims III book. Seemed like a good way to go, it's just a piezo, an 741 IC and a couple passive components. No big deal right? Well it has 2 problems, 1) when you depress the switch, it's possible to change the pitch 2) it's damn near impossible to tune. The first could likely be overcome with with some debounce technology, though i didn't know how to do that without adding another counter. It could also be an issue with using a piezo. The second issue just got unwieldy when you started trying to hit a certain pitch. What about the 555? The datasheet shows a time dlay function based on resistors and capacitors. Which is great until you start typing in actual values of real world parts, that's when you'll find hitting a 440Hz pitch starts to get a little difficult. You can use trim pots to get it tuned in, but over time they tend to move. Constantly tuning the instrument, compiled on top of rapid increase on cost and quantity of parts, and my wife making the pitch change when she pushed the button killed the 555 for this project.

Op-amp:
No problem, people have been making synths with op-amps since before I was born. How hard could it be to make a really simple one, with few parts and specific notes? Harder than I thought. Most of the designs out there are very over complicated for this project. Synth designers are out for the perfect waveform/tone. This directly conflicts with a project that is supposed to be cheap enough for school or teachers budgets. Building a keyboard is easy enough, it's just a bunch of resistors and power or a bunch of diodes and power. It's the rest of the circuit design, and the cost of custom pcbs that starts to get out of hand for someone at a beginning electronics level.

Project redefinition:
So the project got redefined before i even really got going. I needed something that could toggle a speaker pin, in time, with the press of a button. I didn't want to have to design and buy a PCB. This had to use as few components an possible, and be assembled as a beginners kit. It was staring me in the face the whole time. Duh!! Microcontroller!

Microcontroller:
So after purchasing both an Modern Devices Bare Bones Arduino kit and an Evil Mad Scientist Simple Target Board and letting them sit on my desk for months not being used, I had the perfect introductory project. I started looking at the time it takes to put both together, the learning curve for the code, cost, the additional parts needed and make it do what I want and settled on the target board.
Cost was pretty even, $15 plus a $20 FTDI cable for the Arduino, $12 plus a $22 USBtinyISP programmer. I already knew C++ from the little college I could stand and figured C for microcontrollers wouldn't be that bad, while other than blinking a light to make sure I put my kit together properly, I had no Arduino experience. Both could be mounted. It was pretty much a toss up, so I decided on the fewer parts of the two, the target board.
ShortedOut says: Jan 16, 2010. 10:05 PM
Weren't sure you were aware of this (from your comment that you knew C but didn't know Arduino), but the Arduino is actually programmed using C, just plain ole C. So I guess I don't understand the comment that you think the Arduino adds a lot of bloat.

Also, just to clear up confusion for anyone about Bekathwia's comment... Early reviews of this thread stated that it tended to fray quite a bit, which could cause shorts. For this reason it wasn't recommended for top thread in a sewing machine. Because the bobbin thread in a sewing machine lies straight (it's the top thread that forms the loops around the bobbin thread), there is less fray.
pstretz (author) says: Jan 17, 2010. 8:41 AM
There is no such thing as pinmode() in C or analogwrite(), digitalread() or any other Arduino function.  That is a construct of the Arduino platform in a header file hidden from the user.  A sketch needs to be compiled to hex code with the Arduino definitions in order to run on a microcontroller.  Those definitions that are needed to make Arduino actually work are the reason for my bloat comment.  Sketch programmers for Arduino are taught to use functions that are hidden from them.  That, to me, does not qualify as C programming.  It is closer to programming in Basic or Java, not "plain ole C."  If Arduino was more open about the header file their software adds on compile and the users actually understood that that's what is happening, then I'd agree that they were programming in C.

Also, technically, the bobbin thread should not lay flat. It should be pulled into the fabric as evenly as that of the needle. See this article, www.threadsmagazine.com/item/4302/understanding-thread-tension.  If you use regular thread on the top and conductive thread on the bottom, there will be no electrical connection if your tension is set correctly since the copper pads are on the top.

Go troll somewhere else.
ShortedOut says: Jan 21, 2010. 8:04 AM
Well! I guess I should respond that you should go trash Arduino users somewhere else! There are a lot of us Arduino users, especially when it comes to fabric. We use LilyPad Arduino. Just realize that when you go getting all uppity about your work, and slam other platforms, people do have the right to respond and defend their platforms. The "go troll somewhere else" comment is totally inappropriate to this community of users!

I will admit that I was incorrect about the bobbin thread lying flat. The recommendation not to use this thread as a top thread stemmed from the fact that the top thread has to go through many more twists and turns through the machine and then through the eye of the needle. In tests by the experts in fabric electronics, this tended to cause more fraying.
pstretz (author) says: Jan 21, 2010. 8:23 AM
 I'm not trashing Arduino, that's just your interpretation.  I use it on all my MIDI and complex projects where importing an Arduino library is faster than writing one of my own.  One of my Arduino projects is even on Instructables.  For a project as easy as this, I didn't deem it necessary to do it in Arduino.  I also believe it's important to fully understand what is going on behind the scenes in order to do the best job I can.  The majority of people just want to get it done quickly.  Arduino allows for very quick/easy development.  I just can't believe it's the end all of DIY firmware code design. Sorry.

While perhaps my troll comment was slightly out of line, your comment seemed like an attack on me for not just doing it in Arduino like everyone else and my ignorance of what Arduino is/how it's programmed.  Your comment neither suggested improvement nor offered praise for spending the time to put this Instructable out there.  If I read more into it than you intended, I apologize.
ShortedOut says: Jan 21, 2010. 9:05 AM
Apology accepted. :) I'm sorry that I gave the impression that I was trashing you.

I went and looked at the Arduino site for information about the pinMode statement (which is a function). Arduino is said to be totally open-sourced (I thought), so I figured that anybody who is interested in how the wheel they're using was built should be able to go there and find the source code. Except that I couldn't find it...

You are right that many (and in my estimation, a fairly sizable number) of people who use the Arduino platform don't understand the code they're using. However, that's not all bad, in that it has opened up microcontrollers to many more people (artists, for example).
pstretz (author) says: Jan 21, 2010. 10:50 AM
No big deal.  You'd think I'd have mastered that whole count to ten before getting upset thing by now.  ;)  

If you look under the FAQ on the Arduino site, there's a build process link.  It takes you to arduino.cc/en/Hacking/BuildProcess which explains the whole thing is gory detail. Look at the Wprogram.h stuff.  Wprogram.h includes wiring.h and that's how they get serial.print() and digitalWrite() to actually mean something.  you can see the source at code.google.com/p/arduino/source/browse/trunk/hardware/arduino/cores/arduino.  I still can't figure out why they keep talking about a bootloader if they are compiling and loading the chip through USB, but I figure telling people there's a bootloader is faster than sitting then down and explaining the detail of that page.  :D  
ShortedOut says: Jan 27, 2010. 10:40 PM
Thanks for the tip on Arduino. Sorry about the slow response to this. I am not at all well, and have to take my good days when I can get them. :)
McLightning says: Jun 8, 2009. 12:12 AM
there is no demonstration video yet?
pstretz (author) says: Jun 8, 2009. 4:24 AM
See steps 4 and 6. Both those versions have their own videos. I can make a video of the first one if you'd like, though it'll sound the same. Should I put one on the first page?
bekathwia says: Jun 4, 2009. 7:32 AM
If you put the conductive thread in the bobbin side of your sewing machine and use a regular thread on top, it won't break quite as much. I also find the kind from Lame Livesaver is a lot stronger:

http://members.shaw.ca/ubik/thread/order.html
pstretz (author) says: Jun 4, 2009. 8:06 AM
It was only the top that ever broke. Since I ran a line from pad to pad and then back it would have probably worked out OK only using it on the bobbin. Did you have to increase the tension on the needle to bring the conductive thread up or did you sew it upside down to get the conductive thread to make contact? btw, love the bike patch. :)
jessyratfink says: Jun 3, 2009. 4:55 PM
What a great project! I love that the buttons are color coded. Very functional and really cute too! :D
pstretz (author) says: Jun 4, 2009. 5:56 AM
thanks. Rev 3 is actually based on the colored construction paper pad they were using before. Here's a pic.
Photo 9.jpg
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!