Microcontrollers: For (absolute) beginners.

Show off your projects, ask about others, talk about mine, whatever. Ask for help, or just say, Wooo, thats cool.

Microcontrollers: For (absolute) beginners.

Postby corrado33 » Mon Jun 06, 2011 2:21 am

Hey guys,
I learned how to program microcontrollers (MCU for short) a couple of years ago. I actually wanted to build a robot. I could program it just fine, I just never actually built the robot. :oops:

MCUs can be used for so many different things. Many of the projects we've been talking about can be completed with them VERY easily. The solar panel sun tracking... I could program a MCU to do that in 20 seconds. It'd literally be just a few lines of code. It's a GREAT tool for anyone who does these types of projects, and I think that everyone should learn how to do it. It's not as hard as you would think either.

The great thing about MCUs is that they are CHEAP!!! The one I'm demonstrating with is (if I remember correctly) $1. Only ONE dollar. It's crazy they'd sell this tiny thing with so much potential and technology going into it for 1 dollar! I'll get into the costs tomorrow, but you could program your own microcontroller for probably under 40 or 50 bucks. That's buying the programmer (25 bucks) and breadboard (probably 20 bucks) and MCU (1 dollar). Now, you don't NEED the breadboard, but you'll want one. It's invaluable.

Anyway, I wanted to teach you guys, step by step, how to get started with MCUs. I'm going to be doing this in installments. My first video or two will be getting the hardware, getting the software, hooking it all up etc. I'm literally taking you through EVERYTHING you'd have to do.

First, the prerequisites.
    -You have to have a computer.

Second, the "should haves"
    -You should know how to solder. If you're doing anything with MCUs, you're going to have to solder, so learn. It's extremely easy. Tons of tutorials on youtube. BUT... you can get away with not knowing for now...
    -You should know how to program. If you don't, that's fine, I'll teach you the basics. But it'd make it a lot easier. I'm going to be using C, but I believe you can use other languages as well.

Now, I want to get this straight as well. I am not an expert at this. I'm pretty much a Novice. I know how to do it, and I've done one or two small projects with it, but I am no where near an expert. I'm SURE there are other people on here who are more experienced than me, and I hope they'll chime in to help me out sometimes. The programming is the easy part. Getting the MCU to do EXACTLY what you want... that's a bit trickier. Not hard, but trickier.

Ok, with that done, I'm heading to bed. But I should have the first video up tomorrow, after work, and later if it's sunny.

********UPDATE #1... Hardware and Software*********

To begin any project, you need to know where to get the materials. I'm going to list where I bought my materials, but there are many other places you could find the same things. I'll also quickly show where I got them in the first video. I am using an Amtel AtMega8 for my programming. It's small, cheap, and it works in a breadboard. (More about that later)

To begin programming MCUs, you need
  1. An AtMega8
  2. A programmer
  3. A computer
  4. A breadboard
  5. Software

For the AtMega8. I bought mine from digikey.com. I bought it while I was ordering a bunch of other electronics for another project. It's not really a "buy one thing" kind of store (although you probably could). But you can find the AtMega8 (not the L version) a bunch of different places online. You want the PDIP version. Don't ask, that's the version you want. It has through hole connections (meaning it has a bunch of spikes sticking out of it which can be put through holes in project board you can find at radioshack). I believe the other two versions are a surface mount version, and a socket mount connection. I'm not sure though. Just buy the PDIP one. The PDIP one is rectangular, while the other two are square. You want the rectangle.

For the programmer, I used USBTinyISP. Here is the website for it. http://www.ladyada.net/make/usbtinyisp/index.html I like it because you build it yourself. They ship you a box of parts, and you solder the entire thing together. It's a great learning experience. They also sell fully assembled ones(I think), but it's fun (and cheaper) to put it together yourself. Here is the link to buy it. http://www.adafruit.com/products/46 This is by no means the only option, you can buy an official programmer from Amtel, but it's more expensive, and this gets the job done. You can also just buy the PCB and microchip and source the rest of the parts yourself if you really wanted to. (But hey, it's $22, you really can't beat it...) Oh, I don't rememeber if it comes with a usb cord or not... so if you don't have a normal usb cord, usually used for printers, then you'll have to find one somewhere. One that has these ends.


For the computer... I'm using a PC with Windows XP on it, but don't let that discourage you. You can program microchips from Mac OS X, and Linux/Unix. I don't know any other way of doing it besides through the console in os X and Linux though. It can work, but I'm not going to go through it in this walkthrough. (Ok maybe I'll try OS X, eventually). I'll get into the software later. Oh, you also need an open powered USB port. Which is basically any, unless it's on a keyboard or something.

For the solderless breadboard... This thing isn't NEEDED, but you'll want one. There is a picture of one below. Basically this allows you to make circuits without soldering. It's invaluable because I doubt you'd get the circuit right the first time without testing it anyway. If you don't know how they work, google it, or just check out the wiki. http://en.wikipedia.org/wiki/Breadboard You can buy them from digikey, but I didn't. I bought mine from a site called electronic goldmine. http://www.goldmine-elec.com/ I also bought a little pog (yes pog, who doesn't remember pogs?) container filled with LEDs. I think it's a semi surplus website, cause the LEDs were only.. I think 5 bucks... for maybe a hundred of them or so. It's easy to find the stuff on the site. You can find solderless breadboards at radioshack though. Although they're (much) cheaper online.

Image. Image borrowed from wikipedia.

For the software... Since I'm using XP, I'm using a program called AVRStudio. If you like the console, you can use AVRDude. Both of these are on the website for the programmer. And it also has instructions on how to get it to work with both programs. I like AVRStudio, although it needs some fanangling to get it to work with the non-official programmer. (It's not hard, and I'll have instructions in my vid.) I also like AVRStudio cause it has this cool feature that let's me physically see which bits and registers I'm turning on and off. I LOVE this tool for debugging. Cause you can see EXACTLY when something will happen and why it's not working. I often step through my program just to make sure everything gets turned on at the right time. I know you probably don't know what that means now, but you will, once I start programming.

Now, without further adieu... here's the hardware and software video

Ugh, terrible video quality. The output from the screen recording program did not like to be made into other forms. But you get the point. I'll get better at it, I was in a hurry for this one.


********UPDATE #2... Wiring AtMega8 for programming*********


********UPDATE #3... Installing the software for programming*********
Please know the software I use is just what I like. There are lots of different programs you could use. I am by no means promoting these products, I just like them for my small projects.


********UPDATE #4... Your first program sent to the microcontroller!!!*********



********UPDATE #5... Bit Manipulation!!!!*********

Yes, this stuff is useful...


********UPDATE #6... Using a 7 Segment LED Display*********
Video six is how to hook up a seven segment display, and video seven is how to program it.




********UPDATE #7... Functions and Header files*********



********UPDATE #8... Timers*********
Timers "theory" if you will Part 1.

Part 2

Sample program
Last edited by corrado33 on Sun Jul 03, 2011 10:57 pm, edited 12 times in total.
corrado33
 
Posts: 232
Joined: Mon May 30, 2011 5:53 pm

Re: Microcontrollers: For (absolute) beginners.

Postby sjvsworldtour » Mon Jun 06, 2011 3:20 am

This is a very good subject for this forum and micro-controllers can be very useful/flexible. The important thing is to recognize when they are applicable.

The sun tracking stuff is very simple logic and would better be done with a few photo transistors and basically some relay logic. You would end up using more parts external to the micro-controller than you would if you just did the relay logic stuff.

There are a wide range of micro-controllers out there and some are much less than $1. The smallest I have worked on had 32 bytes of RAM. Yea, bytes, not kilobytes. I believe the chip had 6 pins, if memory serves correctly. Assembly language programming is preferred with these.

There are several things to consider when using a micro-controller. If it is a high noise environment, you will need to shield the processor from the noise. Sticking them in a metal box to basically create a Faraday cage is probably best, along with filtering on any lines coming in and out of the box. Any low current lines need to be in the box. This is particularly true if you are doing a wire wrapped board. I actually blew up a water treatment system once because the prototype used a wire wrapped board and the shielding turned out to be inadequate.

Then there is the complexity of what you want to control and what actuators you would need. As an example, consider the spider tank Jaimie is building. Could I design something that did what the spider tank does with a processor? Certainly. I could even put more features in it.

The brilliance of Jaimie's design is the low cost, the size, and the weight. I seriously doubt I could come close on any of those counts. I wouldn't even be in the same ballpark. The number of sensors and effectors would absolutely kill me. The processor would also have to have a bit of beaf to do all the calculations. Jaimie's spider tank would basically kick the crap out of me on all those counts. What parent is going to buy their kid a 20 pound spider tank that is 5 times the size of Jaimie's design and pay $500 more for the privilege. It just wouldn't make any sense.

You can see videos of very impressive walking electronic spiders on youTube, but you will see nothing that comes close to Jaimie's design in terms of cost/size/weight. Yea, there is that one evil toy maker that copied his design, but that is about it.

I hope I don't dampen your enthusiasm for micro-controllers because they are wonderful and it is amazing what you can do with them. In college I worked on a micro-controller based car that competed in IEEE. It was very cool. The car that actually won the competition that season turned out to be much simpler and smaller. It was an analog design, but on the coolness factor, our micro-controller based car blew it out of the water.
sjvsworldtour
 
Posts: 264
Joined: Sun May 29, 2011 6:06 pm
Location: Columbia, SC

Re: Microcontrollers: For (absolute) beginners.

Postby corrado33 » Mon Jun 06, 2011 10:05 am

Oh I agree with you 100%!

I just don't know how to design simple circuits with that kind of relay logic and stuff. So I use what I can. Are the microcontrollers over kill? Yes, but still, once I learned how to use them a whole new world was opened up to me. It got me interested in circuits. And if being interested in microcontrollers teaches me how to build good circuits without the use of microcontrollers, then so be it. But the whole point is to learn right?

This is what I can do, and I'm doing what I can to teach it to people who may be interested. If it inspires a project idea in just one person, then I've done a good job. :)

On I side note, I did engineer a motor controller (with no knowledge they existed) out of 2 or 3 relays when I was 15. I had to control the seat belt in one of the family's cars, and it obviously only had two wires coming out of it. SOMEHOW I managed to draw up a circuit with a couple relays(I think they were double pole, one connection was made when power was applied, and one was made when it wasn't applied). It amazes me to this day I was able to do that, now that I know about how actual motor controllers are made!
corrado33
 
Posts: 232
Joined: Mon May 30, 2011 5:53 pm

Re: Microcontrollers: For (absolute) beginners.

Postby sjvsworldtour » Mon Jun 06, 2011 1:36 pm

Yea, I wouldn't discourage anyone from using micro-controllers, particularly for their own projects. They give you much more flexibility than a hard wired circuit. I love them and got paid for doing so for quite a while. We used them for controlling boilers and HVAC systems, and refrigerators mostly.

They are in a lot more places than you would ever guess. I even developed a small temperature display that goes on the side of a freezer. The display had it's own micro-controller to minimize wiring to the freezer controller.
sjvsworldtour
 
Posts: 264
Joined: Sun May 29, 2011 6:06 pm
Location: Columbia, SC

Re: Microcontrollers: For (absolute) beginners.

Postby folypers » Mon Jun 06, 2011 6:07 pm

Great idea, nice thread corrado33, can't wait to see your videos!
- don't tell me the sky is the limit, when there's footprints on the moon
folypers
 
Posts: 89
Joined: Sun Jun 05, 2011 2:48 pm

Re: Microcontrollers: For (absolute) beginners.

Postby Scodiddly » Mon Jun 06, 2011 11:50 pm

I've been fooling around with a Ti Launchpad microcontroller - the dev kit is under $5!!!

Sadly I lost critical mass on that project, so I haven't touched in a while. Need an application get me interested again, probably.
Scodiddly
 
Posts: 94
Joined: Sun May 29, 2011 5:27 pm

Re: Microcontrollers: For (absolute) beginners.

Postby corrado33 » Tue Jun 07, 2011 1:46 am

Part 1 UPDATED! Check the first post. Sorry for the bad quality video! Yeah my computer screen, and by default, the resolution of the video created by recording it, is not 16:9 or 4:3, so when I put it into a 4:3 video, the program tries to scale it to fit completely, making it look like crap.

I'm trying to add "padding" now to get it into a 4:3 aspect ratio so it'll still look nice and sharp and stuff. Ugh...
Last edited by corrado33 on Tue Jun 07, 2011 2:49 am, edited 1 time in total.
corrado33
 
Posts: 232
Joined: Mon May 30, 2011 5:53 pm

Re: Microcontrollers: For (absolute) beginners.

Postby sjvsworldtour » Tue Jun 07, 2011 2:17 am

DIP = Dual Inline Package

It is what you are wanting for the breadboard.

Another thing to consider is getting an erasable chip, either an eprom or an eeprom. If you are going to be doing a lot of development with micro-controllers, it pays to be able to reuse them. Use the erasable one for debugging and then burn the one time programmable (OTP) versions.
sjvsworldtour
 
Posts: 264
Joined: Sun May 29, 2011 6:06 pm
Location: Columbia, SC

Re: Microcontrollers: For (absolute) beginners.

Postby corrado33 » Tue Jun 07, 2011 2:47 am

sjvsworldtour wrote:DIP = Dual Inline Package

It is what you are wanting for the breadboard.

Another thing to consider is getting an erasable chip, either an eprom or an eeprom. If you are going to be doing a lot of development with micro-controllers, it pays to be able to reuse them. Use the erasable one for debugging and then burn the one time programmable (OTP) versions.


The AtMega8 is erasable. :D :D

At least I've programmed to mine a couple hundred times debugging programs. lol And I believe it has eeprom. EDIT: Yes it does, 512 whole Bytes of it.
corrado33
 
Posts: 232
Joined: Mon May 30, 2011 5:53 pm

Re: Microcontrollers: For (absolute) beginners.

Postby sjvsworldtour » Tue Jun 07, 2011 3:38 am

Oh, that is awesome. There is likely a version that is much cheaper the is OTP. The one that can be reprogrammed is all you need for tinkering around. If you design something you want to keep, go after the OTP. It should be significantly cheaper.
sjvsworldtour
 
Posts: 264
Joined: Sun May 29, 2011 6:06 pm
Location: Columbia, SC

Next

Return to Talk about projects.

Who is online

Users browsing this forum: Alexa [Bot] and 0 guests