December 12, 2009

Nascent Makerspace Emerging

This week I put aside my normal tinkering to help some friends organize a makerspace in Urbana. This is an organization dedicated to enabling the mashup of arts, humanities, hard and applied sciences and technology. Learning and collaboration are key goals here, so you know I'm all over that like white on rice. I figure every minute invested on making this idea into reality is well spent, since I realized the value of bringing together a community of artists, technologists, students, scientists, mathematicians, kids, tradesmen, tinkerers, dreamers. It is well spent because the collaborative nature of the effort should yeild more "eureka!" moments than if we all journeyed separately (as I've been doing in this blog). It also allows us to give back to and support each other in many more tangible ways than just sharing knowledge on a page. Additionally, I realized I may be able to reinforce my knowledge by actually putting together some ideas and presenting them to an audience, not to mention applying what I know to other interesting problems presented. All around, it's a very attractive idea, both from selfish and benevolent standpoints.

We have no name yet. We have a mission statement draft, some starting organizational designs, and several enthusiastic individuals who are willing to sacrifice time, talent, and treasure to make the idea a reality. We are on the verge of having a 500 sq ft. space nailed down. We have piggybacked our association such that we will start out of the chute with 501(c)3 nonprofit organization status. As I write, we are inventorying all of the tools we have already and all the stuff we need. So much yet to accomplish. I'll keep you all posted, so stay tuned.

Until then, keep your irons hot. A makerspace* may be coming to your town.

* NOTE: "Makerspace" is synonymous with "hackerspace" or "hackspace", but since the news media and government has taken the term "hacker" and projected it to the masses as lawlessness and destruction, to prevent confusion we will refer to our effort as a makerspace. We will however display the glider logo, as we truly do identify with the hacker culture as defined by ESR.

"Respect the Past, Examine the Present, Build the Future" (hackerspaces)
"Hack the Spaces"
"Building the MIlwaukee Makerspace" JSOnline, The Milwaukee Journal Sentinel
Noisebridge Vision Statement

If you are around the Urbana-Champaign area and are interested in making stuff with us, message me, either through the comments or via DM on twitter.

Additionally, if you wish to help by donating or lending equipment such as a CNC mill, oscilloscope, drill press, lathe, MIG welder, or other maker gear, contact me either through the comments or via DM on twitter. 

December 6, 2009

Grokking Arduino

Now that I've constructed from scratch a testbed with a stable 5 VDC power supply, used it to power the ATMega168, added a rs232 interface, external timing, blinky blinky LED's an so forth, I decided perhaps I could now partially comprehend just what's going on with the all-inclusive Arduino platform. So I ordered an Arduino Duemilanove from Sparkfun to get a closer look. I set out to find out what all the hubbub was all about. After all, it's just a prebuilt AVR sled, right?

I first took a look at the hardware. If you look closely, you will see a lot of familiar stuff. Let's see, I see an AVR. I see a FTDI rs232 interface, with nifty SMD RX and TX LEDs. I see a power interface, voltage regulators with a couple electrolytics and a diode. I see a 16 Mhz crystal. I see a reset switch. I see some pin headers. So far, this thing has everything we built on our breadboard. Well, OK it has a few extra nifty hardware fetatures. Number one in my book is the USB interface. Notice two voltage regulators? Makes sense, we can power from our wall wart or alternately from the same USB interface we use to program. That is pretty nice. No more hacking 18ga wire spaghetti to the MOSI and MISO pins. Of course a biggy is the ATMega328 - It's a drop in replacement for the ATMega168, but with twice the program space. I also see some nice analog and digital I/O pinouts. I see an IC marked "358 G35A" - is that an op amp? It's over near the analog inputs, so I suspect that's the case. Let me know if I missed anything.

I spent some time readying my laptop to use all the Arduino environment goodness, and in doing so stumbled upon the why this thing is so cool. Sure the hardware is nice, but the Open Source Arduino development environment is the real jewel here. I had been spending my cycles manually driving avrdude and avr-gcc with my ATMega168/breadboard setup, which is fine for some with technical leanings, but what the Arduino folks did with their "sketch" programming environment was to abstract most programming tasks into something akin to snapping Legos together. And they open sourced the entire thing (I was on the verge of making my usual kneejerk dig on the Java programming language that Sketch was designed in, but it's so cool, I am going to let it be)! Now I haven't dug incredibly deep on this, but I get the idea. Of course this means they may have just successfully opened up a technology wide open for use by those who could care less about the inner workings, and more about creating cool shit. I may want to dig into C code, but now it seems that's a choice, not a requirement. Way cool. Way cool.

I was going to go into detail, explaining to you Internet readers all the crap I had to do to to get the environment working on my Ubuntu 8.10 (Intrepid) system, but it's late and probably largely irrelevant. Just a few notes before I part: Remember that you need avr-gcc 4.3.3 or better because 4.3.1 and older jacks up calculations with long ints on the 328. I solved my problems just by uninstalling all my AVR tools, logging into AVRFreaks and replacing them with the AVR tools DEB package supplied by them to address the issue. Or you could run Jaunty, or a Mac, or hell even Windows. However you do it, you have to check this out. Playing with Arduino is going to be excellent fun. In fact, I am going to show it to some of my artist pals to see what they do with it. I know what I'm going to do with it. Something big.

Arduino Development Environment ( (Sketch + tons of extra libs n stuff)

November 29, 2009

Happy Thanksgiving

I really thought I'd do something this week, but at present. I am drinking wine with my chix0r, and playing with a robotic cockroach on the dining room table with my daughter. Screw it, it's a holiday weekend.

All I have for you this week is some information from my readings. When rummaging around at my house, I uncovered my old copy of TTL Cookbook by Don Lancaster - a classic! For fun, I looked up our 74HC164 shift register from last week. I learned that the function of this device is a lot like seating 8 people for Thanksgiving dinner, then ordering them all to attack the buffet at once :) There will be more on this when we get this in and put it to use. There wa also much other goodness I will be referring to in the future (555, 556 timers, etc). I have also been digging around in Applied Robotics by Edwin Wise. We will be making motor controllers using N-channel MOSFETs in the near future using plans from there.

OK enough for now. Time to go eat some lox, drink some wine, and count my blessings.

November 23, 2009

Shift Registers are Important

I started out this week's lap looking at my options. I had a RS232 shifter board kit. Interesting, but that's mostly a bunch of boring soldering. I just received a cool new Arduino Duemilanove! Sweeter than sweet, but I don't have the required version of AVR-GCC installed (you need 4.3.3 for the ATmega328 due to a bug in older versions - I currently run AVR-GCC version 4.3.0). Compiling software is not how I planned on spending my Saturday, so nixed. The 16x2 LCD display I bought to monkey around with sounded pretty good.  Figured it should be fun figuring out how to display something childish and dirty to the little guy!

Knowing practically nothing about the display, I started with a close examination of the hardware. Nothing dramatic, besides the display screen, the only other outstanding feature on the display was 16 solder pads on the edge. To figure out which pad was for what, I consulted the data sheet - and almost fell asleep! OK, from an EE perspective, all that stuff is interesting, but I thought this was not quite the right doc to start with. Too low, like in the freakin weeds low-level. Being the impatient pragmatist, I want to see working examples and overviews first, and then later on maybe we can put a microscope on in to scope out the bit plumbing. I found better (better, I mean because I could at least identify what was useful) info on the manufacturer's sheet. Found out I have 8 data lines, power (Vcc, Vss), some adjustment inputs, register select and read/write controls, not to mention some ambiguously labeled control input called "enable" (insert Spock sound byte: 'fascinating!'). I think I may understand what most of these might do. Now was the time to dig deeper though, since I didn't have enough to go on yet.

When ferreting out more info on the unit, I discovered that the HD44780 character display seems to be a defacto standard. This means many different manufacturers make character displays, using the same basic interface. This is a good thing. Why? Well because this means I will likely never need to read the datasheet ever again, since many engineers have already done this and documented the living dogshit out of it prior to my arrival. Have I mentioned that at this point I felt all mushy and awkward toward Peter Ouwehand for having an entire site dedicated to HD44780 character displays? I'm gonna send him a fruit bastket just for saving us from that nasty datasheet. He has examples! Examples!

I jumped quickly to a linked AVR example. For whatever reason, the first thing to leap out at me was the 10K trimmer required for the contrast adjustment. Luckily, after digging through my stuff I found that my arduino kit included a 10K trim pot. Why the 74HC164 interface IC on there didn't register in my consciousness first is an utter mystery. It did eventually though. And when I finally figured out what "serial in, parallel out shift register" means I knew my day was destined for shortness. Yep, the 74HC164 takes serial input and then outputs to a parallel device. This whole time I guess I had assumed the LCD display somehow used serial I/O. I imagine the datasheet may have had this info somewhere between all the clock timing specs and register state bitmaps, but really just seeing 8 data I/O pins should have tipped me off! Hey well I do learn eventually.

Without a shift register, I was pretty much done. Ordering one right now so we can do this up later. I spent the rest of my project time soldering up the RS232 shifter board. Looking great! Except I couldn't find my dikes to snip the legs. So tune in next week! Does Chuck find his dikes? Will he also notice that the example uses a dissimilar AT90S2313 micro? Will he reread the evil datasheet and slip into a coma? Why is there a pizza in the first picture of this blog? The suspense! Have a great week, and happy hacking everyone.

November 15, 2009

Mucking About with Code and UART I/O

While attending my daughter's dance recital Saturday, my mind stuck on the word "recital". The kids weren't reciting anything, they were dancing. Neither do kids at a piano recital actually recite anything, and so on*. "Recital" I suspect is one of those words originating out of a specific common event, which eventually broadened in definition to mean any event where a pupil demonstrates his progress and/or achievement in a very formal and public way. Once I sorted it out in my head, I realized I am performing sort of an electronics recital here, am I not? Only difference is, when I'm done I intend to launch killer flying killer robots instead of playing "Mary had a Little Lamb". Heck, I might even make flying killer robots that play "Mary had a Little Lamb"! Onward with the recital then...

I did Sparkfun's Beginning Embedded Electronics tutorial #5. It was labeled "AVR GCC Compiling", but I like my title better, since we really do just muck with some code and our serial interface some more. And that's cool with me, I have a little 16x2 serial display on the way; I need to get a handle on this stuff. I realized late last week that the subtext to last week's lab said we'd printf some foo to our monitor via a running program on the AVR, and somehow that never happened. Until now, of course.

I started by compiling and writing the "basic-out-atmega168" program to my micro. Of course I noticed right away that something wasn't quite right - The code was supposed run on the micro and output something like "Test it! x = 1Test it! x = 2Test it! x = 3Test it! x = 4Test it! x = 5" to my minicom (terminal emulator) screen. What I got was a bunch of garbled crap. Looked like the inventor of ASCII threw up in my term session. Good time to recap what we learned last week. I did a successful loopback test on the UART. Looking at the schematic for the max3232 indicated I tie RX and TX on the micro somehow to "R1OUT and T1IN".  A break in the drawing doesn't show which goes to which though. I guessed RX went to the transmit pin and TX to the receive pin. A basic crossover connection, right? Looking at the resultant garbled crap made me think about what the RS232 controller really does - it does some voltage foowankery, but basically it's a traffic cop, a pass through. That means the TX on the micro goes to T1IN and RX goes to R1OUT, and all would be fine. It was. Program now works. Just a note, Homework for this week is to see if I can manage 2 serial streams with this guy, cause I noticed a set of unused pins labeled R2xxx, T2xxx.

Can you spot my rookie screw up here? This setup can't work.

The tutorial goes over some basic methods used in C to twiddle bits, toggle GPIO pins, and set other options. After a while, it'd probably be good to spend some time rooting around header file avr/io.h to see what interesting AVR defines and directives exist. Even though the tutorial skirts around the subject, now is probably a real good time for me and anybody else who hasn't used a bitwise C operator since college to get a good refresher. They are of course used to enable things that could make life sweet, like the TX and RX pins (RXEN0 & TXEN0). More homework for lucky me. The author states that he never starts any code from scratch - he always modifies existing code. If I actually trusted other programmers, I might use this method. But since I trust neither the coders out there, nor coding contexts as germane to my efforts, I think I may spend more time getting familiar with the coding end of this whole thing. I can't recommend my way over Sparkfun Nate's, as it will be considerably more work, I imagine it just depends on whether you trust people or not. Damn, trusting people is a lot less work than my way. *sigh*

I won't discuss compiling and loading the second program, since it was uneventful, so that's it for now. Time to think about using the interface for more useful stuff. Like I said earlier, I have a 16x2 serial display en route. I'll see if I can get the micro to display to it next week.

The next 2 Sparkfun tutorials deal with soldering. I am probably going to skip these. This does not diminish the importance of good soldering technique, I am just already pretty good at this. Not sure about the CAD ones either. I have downloaded the free Eagle CAD software (good stuff! they have great Linux support!) and will use it to design my stuff, but I want to keep focusing on getting the micro to bend to my will, not peripheral stuff. So I guess that means I am pretty much done with the Basic Embedded tutorials at Sparkfun! Woooo! Be sure to check out their last one, which is basically things to do to prevent frustration and embarrassment. I should formally thank them for sharing all the learning material. I had fun and now know a little something about something.

*If one was performing an original oratory for the very first time, would that just be a "cital"? Or does one "cite" when first putting pen to paper? No, I would think it drafting or composing. And then everyone repeating it would then re-cite it? No, that would be speech, or speaking. But there is no "respeeching" or "respeaking", only recital. Strange word. Calling all linguists! Attack!

November 7, 2009

Installing and Testing a Serial Interface

As I wandered through the farmer's market in Urbana this morning, instead of thinking about tasty dishes I could cook, I was wondering if I could use the the old potato-battery trick to power a micro. So that pretty much tells you where my head is these days. According to this guy, we'd get 0.5V with 0.2mA, so that means we'd need what? A bakers dozen to safely power our ATMega168? Good to know if I ever get stranded without power in Idaho! Maybe for fun I'll do this later on.

Now, down to the business at hand: Today I hacked a serial interface onto the ATMega168, using a MAX232 IC, and tested it using Linux and minicom. I was loosely following Sparkfun's "UART and Serial Communications" tutorial, but with the normal diversions to use tools commonly used with Linux. In this case, the tutorial would have us test out the rs232 interface by firing up Hyperterminal (infernal Windows term thing). Yeah, you know me. I was all "we're totally not doing that."

Here's where I started: I have a max232 IC which is my serial interface. I really don't have to know much about it, other than the fact that it converts +/-12V signals to usable 0-5V signals for our micro and other UART magic (the charge pump link in the tutorial is pretty interesting though). I noticed again no mention of static guarding IC's; Am I just too anal about this? I still don't have a grounding strap for my wrist, but I grounded myself to the leg of the table before I carefully bent the pins and installed it on my breadboard.

It was nice to know about the decoupling caps - I suppose I should plan on keeping a bucket of 22 and 10 uF ceramics around. I noticed also we weren't using electrolytics anymore for decoupling. We used them for the 5V power supply, but not for the oscillator nor for this max232. Can anyone tell me when one is preferable over the other? The datasheets of course specify ceramics, and that's fine. I was just wondering.

When installing the caps, one thing jumped out at me. Caps decoupled pins 1&3, 2&6, 4&5. Pins 7&8 are unused. Sound familiar? It did to me. That is the wiring order for a CAT5 UTP crossover cable! And it made sense: Back in the day, the first ethernet cards I remember had serial-looking interfaces on the back and often required tranceivers to accept CAT5 with an RJ45 end. I should've made the connection back then, but probably had my mind on other crap! Just an interesting note.

I put a loop on the TX and RX pins of the IC, so whatever input I give it will be puked right back out. In this state, we are able test the proper functioning if the max232 by hooking up a terminal emulator or heck, even a real vt100 terminal if we want!.

The tutorial tells us to use Windows' Hyperterminal, or maybe TeraTerm. Nonsense I say! Linux! I used minicom. Minicom on my Linux laptop had no pre-set config, and defaulted to some bad defaults which I needed to change.

Welcome to minicom 2.3

Compiled on Oct 24 2008, 06:37:44.
Port /dev/tty8

              Press CTRL-A Z for help on special keys

You'll notice it defaults to tty8. We need to change that and switch the port speed to 9600bps. The quickest way to do this is to hit "ctrl-A O" once minicom starts.

| Filenames and paths      |
| File transfer protocols  |
| Serial port setup        |
| Modem and dialing        |
| Screen and keyboard      |
| Save setup as dfl        |
| Save setup as..          |
| Exit                     |

I selected "Serial port setup" and made the following changes:

| A -    Serial Device      : /dev/ttyS0                                |
| B - Lockfile Location     : /var/lock                                 |
| C -   Callin Program      :                                           |
| D -  Callout Program      :                                           |
| E -    Bps/Par/Bits       : 9600 8N1                                  |
| F - Hardware Flow Control : Yes                                       |
| G - Software Flow Control : No                                        |
|                                                                       |
|    Change which setting?                                              |

I ran into problems here. It's worth noting that I spent a while troubleshooting a seemingly non-working serial connection. I would type and type; nothing ever got puked back to the console. I noticed that the wires running to the DB9 interface were a little too loose for my comfort, so I got out the soldering iron and a new slice of bread and fixed that mess. Still no worky. After beating my head on it for a while I figured out that somehow changing minicom on the fly does not always work. When I saved the settings to a minicom config file and restarted, all of the sudden the thing worked fine. Yesssssss! I took the loopback plug out and connected the RX and TX pins if the max232 to the RX and TX pins of the ATMega. Now we're ready for some cool I/O fun!

So next time I will be doing the AVR-GCC lab. Not sure if it will be me just going off on my own, but in any event I will be using my new serial interface to debug stuff, which is cool! Later for now, all - I'm gonna go look at cool 19x2 serial displays and russet potatoes!

November 1, 2009

Tick, Tock, Rockin the Clock with Crystal Oscillators

Yesterday I dove into Sparkfun's 3rd tutorial in the Beginning Embedded Electronics series, "What is an Oscillator?" I learned about using the AVR internal oscillator, ceramic resonators, and crystals as a clock source for my projects. Of course all did not go smoothly, which was fortunate (!) since the bumps highlighted some important things.

I started by reading a good article on clocksources on AVR Freaks. Knowing all the different sources and properties is cool, but I really didn't get a good feel for proper applications. I mean, I know the tolerances on ceramic resonators and the internal AVR osclllator aren't tight enough for your highly synchronized stuff like serial or network communication, but they are good for something, right? Besides blinking an LED, what is some other uses for ceramics and/or the internal? I'll try and look into this some more - If you have some experience with this, let me know in the comments.

I monkeyed around with the AVR internal clock by downloading the ATMega168 datasheet from the Atmel site, finding and toggling the CKDIV8 bit. As was expected; unprogramming this bit took our AVR clock output from 1MHz to 8MHz. With the "blink" code from last week still loaded, the LED on the output line started to blink faster. One confusing
thing I noted right here: the bit order listed in a fuse byte is read from bit7 to bit0, not the other way around. Seems backward, but I'll just have to remember this (it will of course, if I know myself, bite me in the ass in the future, stay tuned, heh)

I am still using avrdude on Ubuntu Linux (Intrepid) and a ponyser serial programmer. I practiced dumping the fuse bits set by executing the following on the CLI:
$ sudo avrdude -p m168 -P /dev/ttyS0 -c ponyser -U lfuse:r:-:h -U hfuse:r:-:h 
  avrdude: AVR device initialized and ready to accept instructions
    Reading | ################################################## | 100% 0.00s
    avrdude: Device signature = 0x1e9406
    avrdude: reading lfuse memory:
    Reading | ################################################## | 100% 0.00s
    avrdude: writing output file ""
    avrdude: reading hfuse memory:
    Reading | ################################################## | 100% 0.00s
    avrdude: writing output file ""
    avrdude: safemode: Fuses OK
    avrdude done.  Thank you.
(I love how Avrdude thanks me. "No, thank YOU!") Setting the fuse bits is just a matter of figuring which bits you want to program, then using similar syntax to write them back out to the micro. When setting the CKDIV8 bit, I looked at the starting config of the low fuse byte (0x62) and figured out the new value when unprogramming (setting to "1") bit7. The value ends up being 0xe2. Using a calculator that does hex to binary conversions is very helpful. [NOTE: the fuse calculator in the tutorial is also tres useful:]
Next, I installed the 16MHz crystal on my breadboard, following the schematic in the tutorial. Note that at this point I feel very smug and proper, having installed caps properly, unlike the "bad engineer! bad!" image in the tutorial. This will be important later, trust me.
OK, having set up the hardware, I dug back into the ATMega168 datasheet in search of programming notes regarding selecting the external clock source which I just connected to pins 9 & 10 (PB6 & PB7). Section 1.1.3 of the Pin Descriptions section gave a nice description of the function and linked out directly to what I needed: section 8, System Clock & Clock Options. So I struggled a bit here to understand the different devices you could program up with the 4 CKSEL bits. For a minute there, I was pretty sure I had an "external clock" (0000), but after reading further, and double checking with the tutorial, I found the correct setting was "full swing XTAL oscillator" (0110). NOTE: My homework this week is to find out what qualifies as an "external clock". So, to set my 16MHz external xtal and caps setup as the oscillator, I set the low fuse bit to 11100110 (0xe6)! AND...and? Oh crap. Nothing. Nothing? As soon as I set the fuse bits on the micro, the output LED just quit. I immediatedly attempted to program the fuse low bits back to use internal RC and was met with the following bad news:
$ sudo avrdude -p m168 -P /dev/ttyS0 -c ponyser -U lfuse:w:0xE2:m

    avrdude: AVR device not responding
    avrdude: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.

    avrdude done.  Thank you.
This time the "thank you" kinda stung. Not responding, thanks? Did I brick my micro with a bad config? After staring for a while, I decided to dig a little. Checked my 5V rail: all good. Checked programmer connections: all ok. Checked fuse low bit config sent (0xe6): confirmed good config. Checked crystal connection: ok. That left the caps - I rolled my eyes and went through the motions of checking the caps, then noticed something odd - "104" marked on the sides. 104? As in, 10uF. Huh, these things were supposed to be 22uF! Pulled the 2nd one, it was also the wrong value. But whatever, right? I mean the demo photo on the tutorial showed no caps at all! However, the subtext was correct. Running with no caps or out-of-spec caps is a crap shoot. The datasheet section 8.4 listed acceptable values for caps C1 and C2 at 12-22uF. I pulled the incorrect caps, installed some 22uF ceramics, and woohoo! Wicked fast blinkage on the output LED. A couple test reads/writes on the micro verified I hadn't damaged anything. Sweet!

So, reading the datasheet and double checking your work are as important as always. Got it.I thinks my flickering LED would look good in a jack-o-lantern! Maybe by next year, I can get something in for Sparkfun's Hack-o-Lantern contest!

 Next week I will be using my cool xtal clock to power some comms! Doing the "UART and Serial Communication" Lab

October 24, 2009

Hexing up the ATMega168 Using Linux and Avrdude

NOTE: Since I am a serial tweeter anyway, I decided to tweetcast my progress live! Follow herdngelectrons to see my lab schedule, comment, or lurk from here on out. 

This week I built upon the 5 volt testbed I made last week, using the VCC rail to power the ATMega168. I also learned the basics involved in compiling the code with gcc-avr and using avrdude to move the code onto the micro. I followed Sparkfun's tutorial: Beginning Embedded Electronics - 2 Getting AVR HEX code loaded onto the ATmega168, well, not exacly followed; the thing was written for Windows users with parallel ports, neither of which I can lay claim to. So off the beaten path I went, and had a pretty fun time doing so.

So I started off the week inspecting the parts kit shipped by Sparkfun. All looked good at first until I stared at the parallel port programming dongle sent, realizing my laptop had no parallel port. My backup laptop had no parallel port. My wife's computer had no parallel port. My daughter's computer had no parallel port. I tried to think of the last computer I had with a parallel port - Holy cow, unless you have a desktop, you're pretty much out of luck. Oh well. Maybe to be a hardcore micro hobbyist, you need to hack a parallel port on whatever you use! I do have a USB port replicator, but read that these really don't work well for this sort of thing. USB programming dongles are out there, but whoa doggy are they pricey. I think $85 was the cheapest I saw. My lappy has a serial port though. Sparkfun did have a serial programming dongle. The spec page doesn't mention any support for ATMega168, but the tutorial refers to the thing (AVR-PG1) specifically at one point. What the heck, the thing was $12 so I ordered it.

To start off, I installed the AVR on the breadboard. I carefully and gradually bent the pins on the package to fit. It was at this point I realized the tutorial didn't really say anything about static guarding your micro. At first I was slightly annoyed that a beginner's tutorial wouldn't mention this, but then realized one important fact. This micro costs $4. I am used to handling VLSI chips worth $100 or more. I suppose at that cost I can leave the grounding wrist strap packed up and just touch the metal leg of the table and go on with life.

I ordered Sparkfun's cheapo-DVM-with-tone-function and decided it was very nice! Much better than my el cheapo and I enjoyed the alligator-clipped leads it included. I used the tone function to measure resistance on the legs of the 4-leg momentary switch, ensuring I didn't install the damn things sideways! @gevmage helped out by explaining the pitfalls of floating the RST pin, and why we need to pull the voltage high: "Two things in circuit bad: untied inputs, and outputs connected together (in slow logic; fast is different)." So there you have it! I also wired up VCC to pin 7, and GND to pins 8 and 22. I checked my voltage again, because I'm a paranoid wreck.

So I had successfully wired and powered my AVR. Next I needed to load some code on the thing. Time was nigh to see if I could get the serial programming dongle to work. I ran into an unexpected issue right off the bat: The dongle serial connector design assumed a serial port that pokes out of your comp. Of course, mine was recessed. The dongle connector case had protrusions that prevented me from seating it. I decided it was time to void the warranty and start cutting. Protrusions? Cut those bastards off. They were there to secure the package to the metal part of the interface, but as long as I'm careful to not rip the wires out when unplugging it, I'll be OK. The modified serial dongle plugged in nicely.

Following the datasheet for the ATMega168 I wired up the serial cable to the corresponding I/O pins. Looked like so much spaghetti. After wondering why I needed to wire up 4 GND connections (but doing so anyway), I reminded myself to order a 10-pin header for the next try. I still don't know what MOSI or MISO pins are for exactly, although I suspect the I and O may be (I)nput and (O)utput? Maybe that's my homework this week.

So at this point, the tutorial started going on about WinAVR and all the windows tools, what's a C compiler, what good code editors do, etc, etc. I kind of glazed over and took off on my own direction since I use Ubuntu (Intrepid Ibix) Linux, I use vim for coding, I know what make and gcc do, and well, why start using Windows now?. So I got my penguin on, downloaded the zip file containing the Makefile and the sourcecode and took off into the sunset. I figured out that all I needed to install in Linux was gcc-avr, avr-binutils, avrdude and avr-libc, all available in the Intrepid download channel (yesss) using apt-get or Synaptic package manger. I was happy to see the serial dongle was configurable in the Makefile, although it listed "COM1" as the serial port. A quick check in /var/log/dmesg confirmed my serial port was accessable through /dev/ttyS0, so the correct config for me was "AVRDUDE_PORT =/dev/ttyS0". I also needed to change the programmer var to: "AVRDUDE_PROGRAMMER = ponyser". To compile and transfer, "make all" and "make program" worked a-ok*, the code loaded onto the micro, avrdude posted happy messages, and the LED began to blink.

ZOMG it worked! I celebrated success with a cold Guiness. Maybe now we should start thinking about all the cool stuff we'd like our micro to do. Mmmm California dreamin :)

* I actually ran "sudo make program" because I as a regular user did not have enough permission to use the serial port. Details, details.

NEXT WEEK: Lecture 3, What is an Oscillator

October 17, 2009

5 Volts on a Saturday Afternoon

I have a streak I'm sure some of you out there can identify with. The streak goes like this: I start something, get bored with the basics, jump to the super-advanced part, build some monstrously awesomely advanced thing which then causes an unintended, yet epic conflagration or disaster. Seems crazy, but I have convinced myself the fun doesn't start until I'm knee-deep in something. After the fire department leaves, I always feel like maybe I should have maybe finished studying all that boring basic stuff. So this time no skipping through. I decided to go back and start my re-learning process with something we can all roll our eyes at: making a simple 5 volt DC power source. Yeah yeah, it doesn't get simpler, but hey later on we'll sure enjoy knowing that the problem were troubleshooting on our micro isn't rooted in the power supply. I can even tell the fire chief that my power supply was built with current-limiting awesomeness if he happens on by to see what the hell I'm doing this month.

I chose Sparkfun's "Beginning Embedded Electronics - 1" tutorial as it is nicely written and very easy to follow. It also contains some really nice supporting info, descriptions, and suggestions. I ordered all the parts from the convenient link included in the writeup. The kit arrived in my mailbox a couple days later, containing a breadboard, some 18ga. wire, a 9V wall wart, a switch, a barrel connector, 2 elecroltic capacitors, a 5V regulator, 2 LEDs, a diode, 2 resistors and an, ahm, a thingy? (We'll get to that thing later) So time to roll up the sleeves and put this together.

Note that I am selling my house and have already moved away. I am living in a small 2 bedroom apartment. At the house I had access to my workshop. Here I am working out of a "bare essentials" toolbox. So those of you out there doing this on your kitchen table - I'm right there with you. The tools used today are: needle nose pliers, an el cheapo DVM, wire strippers, and alligator clips. I don't have my nice soldering station (it's in a box floating around somewhere) so I made a trip to the local Radio Shack and picked up a 25W iron good for meatball joinery. Also grabbed flux and solder. Since we're not going to be soldering anything super sensitive, I'm not worried about my hot-ass iron. If you plan on soldering near or on sensitive stuff in the future however (ICs, micros, etc), you may want to splurge on a good digital temperature-controlled soldering station. I love mine (wherever it is).

Upon unpacking, I noticed the breadboard came "assembly required" which is no biggie, but I wish the adhesive for the rubber feet hadn't all dryed up and blown away in the packaging. I guess I'll take care of that with some spray adhesive later. There were no instructions, but I figured out how everything on the breadboard goes together just fine. If you don't, post or e-mail me and I'll help where I can.

Plugged in the wall wart and measured my voltage at around 9 volts. I don't have an o-scope to see how clean this is, but as the tutorial says, it's reasonable to assume a fair amount of ripple on the output of the wall wart. Who cares? We're going to fix it up with some caps later anyway like good boys and girls.

I like the idea of putting a jack on the board for nice power connect/disconnect. Soldering the barrel jack looked like it would be straightforward, but I encountered a few issues. Number one was keeping it still while soldering. If you have a set of clips or "helping hands", use 'em. I opted for something soft and pliable that I could smush the barrel into securely while soldering, yeah, that's a piece of bread. It's the end, which noone in this place will touch anyway. I imagine modeling clay, play-doh, plastic explosive, or other pliable and non-flammable material will work as well. I just won't eat the bread when I'm done - Not only are bread ends crusty and undesirable to most, on top of that solder for electronics is made with a host of nasty and/or poisonous stuff such as arsenic and lead. I have enough mutant powers alreadt, So I just tossed the bread.
Ran into a samll gotcha when assembling the barrel: the side lead on the barrel is not a ground lead like I thought it was. The end lead is 9V, the middle lead out the bottom is GND, and the side one is neither. Don't connect this one to GND like I did. I connected this to the breadboard afterwards and re-measured to ensure I saw 9V on the board.

After putting the 5V regulator on the breadboard, installing the switch and caps, and jumping the gaps in the GND and VCC rails, I took an extra step and verified 5 volts on the top rail. A small step, I realize but I crazy Ivan a lot when working to ensure all the details are in order. I could've just wired up the LED and resistor to verify (like the tutorial did), but then I couldn't be all paranoid. Just to mention, my paranoia is completely irrational; Sparkfun sent me an extra LED and resistor, probably on purpose.

Hey! it works!

The cathode of the LED is indicated on the schematic with a flat line and in real life manufacturers print a band or a cast a flat side to mark it. A casting flaw in my LED obscured the flat side, but I noted the cathode leg is usually shorter than the anode leg. This is minor stuff, as putting one in backwards usually doesn't damage much, as the tutorial reaffirms. It's still nice to get it in right on the first try (that's what SHE said!?)!

The regular diode was never really shown anywhere but on the schematic, I included a picture of it installed and working just because.

I encountered an interesting extra device I suspected was the PTC discussed in the tutorial. The labeling was a little cryptic but a little googling of the markings affirmed my suspicions, and a data sheet! Now I know it's what I think it is, I installed it in circuit.

Well that's it. 5 volts, VCC, whatever you want to call it. Next week I will hook it up to an ATMega168 and attempt to make something blink. Hopefully between now and then I can figure out who is telling the dev manufacturers that parallel cables are the way to go for uploading programs. Yeesh.


October 12, 2009

Pfft, pfft - Is This Thing On?

Every 8 months or so I decide to add a tool to my arsenal. See, I'm a big fan of knowing about shit (James Madison FTW!). I dig into something new on a regular basis. Usually it's a solitary pursuit involving me, some books, some gear, pen, paper, the intertubes, some conversation in my head, perhaps even an end in mind. The problem? Well my mind is filled with so much stuff, I fear over time I just lose things in there. I lose things I don't care to lose, like those great conversations I had with myself, when I figured out some shit on my own. What's left? An odd sensation that I once knew something really cool but have now forgotten. Frustrating. Not crying over spilt milk here, I'm just saying it won't happen this time or with any luck, ever again. I'm going to do it differently. I'm going to let everyone in the conversation this time. I may forget, but the cloud will remember. Maybe this way I can keep it straight? God I hope so.

So this blog is dedicated to documenting stuff I learn, including examples, fuckups, trials, conundrums, screaming frustration, and glorious triumphs. I will start with embedded electronics. I enjoyed reading through's tutorials enough to document my progress through each one, hence "herding electrons". I hope to gain enough confidence to build some stuff I've been thinking about for a while - we'll get to that later.

Some background: I know a little, enough to be dangerous. I studied electronics while in the U.S. Navy's Basic Electronics & Electricity school. BE&E was 14 weeks of theory, practice, and sheer terror wherefrom I remember Ohm's law, the slutty ways of the infamous Violet*, hole flow, what an inductive-capacitive circuit does, semiconductor theory (AKA "as far as you're concerned it's all PFM kid"), basic troubleshooting, why I'd never care about MOSFETs in the field, and, according to my broadcast engineer father, not a %#$^@ thing about the most important and fabulous electronic things on earth: tubes. I ditched my test probes after graduating though, deciding to instead do something Dad knew nothing about. Years later when I started restoring old arcade machines I picked up a soldering iron again, mostly to shotgun malfunctioning stuff with new electrolytics and the occasional bridge rectifier. Mostly I know how to solder. Amazingly enough it's the thing I'm most proud of right now simply because it's the most practical thing I know out of all that crap. So there's where I start.

The goal is to use the knowledge to actually do shit. So here's the deal. I am going to ramble on about shit I learn, or break, or get stuck on. It will mostly be a conversation with myself about crap everybody else already knows. Feel free to post if you feel I've strayed so far afield the comedy of the situation moves you to point out my error merely as a point of mercy. But do remember I am not much interested in the theory unless I can apply it, get my hands dirty, and use it right now. Hey, maybe my crazy one-sided conversation turns to dialogue!

This thing is on, just don't tell my Dad.

* The old non-PC mnemonic for remembering resistor value color codes 0-9 was: Bad Boys Rape Our Young Girls But Violet Gives Willingly - nice, huh?