Wednesday, February 27, 2008

Arduino Fever

It used to be that the Basic Stamp was your best bet if you wanted get started in microcontroller projects without a lot of prior electronics experience and soldering skill. While Basic Stamps are still great tools, a less expensive, open source alternative has been gaining in popularity: The Arduino. The Arduino is an awesome little microcontroller development system for around 30 bucks that comes with a software package that is free to download. Adafruit Industries makes a great version of the Arduino that you can plug right in to a solderless breadboard. They call it the BoArduino and this thing rocks! It's just so handy to be able to plug it into a solderless breadboard and be ready to go. Don't forget to order a USB TTL-232 cable with it.

Limor Fried, the force behind Adafruit Industries, has created a really great online tutorial for learning the Arduino with lots of photos and helpful hints for beginners, including suggested tools (Adafruit also has lots of other great kits that are easy to solder for beginners). These resources make it much easier to get into the Maker movement and create your own do-it-yourself intelligent objects. There are tons of Arduino projects on the web and more seem to appear every day.

Wednesday, May 04, 2005

A Microchip PICMicro based Guitar Tuner

Disclaimer: This project is for educational purposes only. Soldering irons are hot and solder is often made of lead which can be dangerous. Electricity can be dangerous. I am not an electrical engineer and cannot be held responsible for your use of this project. It probably won't work may be dangerous and you should find a qualified adult to help you with any electronics project. And while I'm at it: Don't expect too much from the writing on this site. Like my projects, if I try to make it perfect it will just never happen. I tend to ramble and I'm not going to go back and rewrite it, so just quit now if you can't handle that. I really don't expect to get a visitor here, ever, so I'm not going to make it my life's work, okay?

Motivation
"I really don't have time for this project." I've told myself this time and again. After all, I have real work to do and most of the things I'm supposed to do I haven't even started on. How can I possibly justify building a guitar tuner when there are so many other things to do? I mean, for pity's sake, I can go buy on for $10 bucks on eBay (plus--surprise--another $8.95 shipping. always read the fine print). It's a strange phenomenon, really. The American Idol results show is on tonight and I wouldn't have the slightest tinge of guilt for sitting on my behind staring, catatonic, at the tube. (And I'm not going to be happy when the season ends and my favorite, Carrie Underwood, doesn't win because she doesn't have a following of faithful army of 12-year-old attack dialers.) I think that somehow I can't give myself permission to do something productive because then I start comparing it to everthing more productive that I should be doing and that's just a downhill battle. As I write this, I have my room is a mess, the front lawn, as they say here in Idaho, "needs mowed," and I have 8 surface mount prototype boards that I promised my business partner that I would solder. Of course, Neil Fiore's book, The Now Habit, A strategic Program for Overcoming Procrastination and Enjoying Guilt-Free Play goes a long way towards explaining this phenomenon, but I haven't done well with the "Guilt-Free" part yet. I may still feel guilty for having fun with these cool little chips, but I've decided that I'm going to try to do one microcontroller project a week (no matter how trivial) this year--even if it just involves creatively blinking an LED on and off.

Okay, why talk about procrastination in a blog entry about Microchip PICMicro guitar tuners? Well, I spent my childhood dreaming about becoming an electronics wiz, but I always assumed it was too hard for an ordinary guy like me to learn to build cool things on my own. I always figured I would do cool things later, after I finished my Electrical Engineering degree. After I bought an oscilloscope. After High School, College, the latest Death March to product release at work. The perfectionist in me wouldn't allow myself to actually do anything until I could do it perfectly. As you will see, I don't do any of this perfectly. I may not even finish this project, but I've decided to have fun trying.

So I am going to devote the pages of this blog to doing things, with the hope that if anyone stumbles upon these pages that they might be inspired to do something as well. I'll try to make the project listings as complete as possible so that you can leverage my experience and maybe even come out of the project with something you can actually use or just have fun with. All you smart guys out will find it easy to shoot holes in my work, but I don't mind. I know I'm not doing it the right way, I'm just having fun and I'm sharing my experiences hoping that you can enjoy my work things and have fun too. I find that most projects on the web don't give a clue as to why a project was done a certain way, so I'll attempt to include some of that as well.

Designing the Project
Actually, it would be easier if electronic guitar tuners weren't dirt cheap. If they cost a hundred dollars I could justify spending twenty or thirty bucks in parts. But I don't feel like spending any money on a guitar tuner and I'm going to spend ten or twenty hours on a project that probably will only save me ten or twenty bucks.

But it is still harder because they are cheap. It think it's pride, actually. Somehow, I imagine that if I ever show off my project, somebody is going to ask me that irrelevant question that I fear: "How much did it cost?" And I'll have to admit how much it cost. And then I'll feel stupid when they say, "Hah! I just saw one of those for $9.96 at WallyWorld." So to avoid humiliation, I want to build this completely out of my junk box.

I didn't live through he depression, but you'd never guess it by the way I scrounge electronic parts. Every time I go to Seattle to visit family I spend inordinate amounts of time going to Frye's Electronics in Renton, WA (with a child or two in tow to placate my wife--BTW, you GOTTA check out Frye's. They've got like 10 aisles of components, copper clad, proto boards, oscilloscopes, computer parts... the place is unreal) and scrounging around at VetCo electronics. To my wife's dismay I'll do things like buy 30 caller ID boxes at the dollar store because someday I want to use the LCD display, case, buttons and battery compartment for a project by just replacing the main circuit board with a board of my own design. I buy assortments of resisters and proto boards at Radio Shack, "just in case." And I lust over, but never quite get around to ordering from The Electronic Goldmine, Digi-Key (they have the best selection, best website, and they'll send you cool, massive catalogs for free), Jameco (they have cool component assortments and grab bags) and Mouser Electronics (my friend Todd's favorite store). If you can't find stuff you like at one of these places then you should give up on electronics now and take up cross-stitch.

Here's my components library. Mostly desoldered from broken electronics. I'm showing it in its current residence behind a door in my room. You don't have to have the Ultimate Workbench to do some fun projects. I often use the dining room table.


Okay, first things first. What processor am I going to use? Well, the guy who got me interested in microcontrollers is Don Lancaster who says that Microchip's PICmicro microcontrollers are the chip of the decade. I think he's right. They're a bit wierd to program in assembly language, but I've got a C Compiler(1) so I don't have to worry about the wierdness much. AVRs are 4X faster per clock speed (although for what I do I almost never find clock speed to be an issue) and have a cleaner architecture, consequently you can get the GCC C compiler for them for free. The downside with AVR's is that they just don't have the massive app notes library and customer service ethic that Microchip has. I've sent an email to the author of a Microchip App Note and actually gotten an email back! It was cool. My favorite low-cost development board is the AVR Butterfly (point Atmel) because it has about $100 worth of cool stuff on a $20 board that measures about an inch by two inches. But it doesn't strike me as a very good beginner's platform to use. Much easier to use is the USB-based PICkit 1 (point Microchip) that is $36 as of May 2005 and even comes with a handy snap-off daughter board to use for your first project. And if you ever fry a Microchip dev board they will send you a new one for free (it happened to me). So if I were starting from scratch, I would probably have used a 12F675 and the PICkit 1. But since they didn't make the PICkit when I started, I am using a 16LF819 because it's what I've got laying around, but a 12F675 would have been just as good and lots cheaper.


When I first googled this, I wanted to do it on a PICmicro because I've got a cool debugger that works well with my C compiler. Well, the coolest page I could find was Jesper's Guitar Tuner page for AVRs. Ironically, there is a very popular page about a PIC-based Guitar Tuner on a page by David B. Thomas but it has apparently been expunged from his PIC page. Enter the Wayback Machine and you can see the original, which disappointingly is just an assembly language listing for an older PIC.

News flash! I don't know how I missed it, but there's a pretty cool Circuit Cellar article that may be exactly what I'm looking for! I even have an 16F84 kicking around for just such occasions! I wonder why I didn't find this the first time? This is great news! I hope I can find all the parts in my junk drawer.

This power supply I scored at a garage sale is cool...





...but half of the time I just use my "junk drawer power supply"...


because it's so handy. I use a setup similar to that described on P.H. Anderson's wonderful embedded programming website. His 16F877 development package is a really great way to get started programming these cool little chips.

TO BE CONTINUED...

Footnotes:
(1) The CCS C compiler is a pretty good value in Microchip C compiler. The "PCM" compiler is $125 as of May 2005 and works on all the mid-range chips from 8-pin chips like the 12f675 up to the powerful 16F877. Don't expect an ANSI C compiler. The compiler isn't even case sensitive (Heresy!) but it works well enough and it seems reasonably efficient. Hi-Tech's free PICC Lite. It is pretty cool but is limited to "only" 2048 words of code. But on these little chips you can control the world with 2048 words of code. I have to admit, of course, that Atmel is the cool chip to use if you're doing embedded programming in C. Atmel or Microchip, I honestly think that life is too short to mess around with assembly language. What's the point? C is fun and assembly is painful. End of story.