Motor Controller with ATMega168

Hello;

I'm a retired art teacher making a laptop electric spinning wheel for one of my high school art teachers, now in a wheel chair. I've never done anything with electronics before starting this project, but have always wanted to. When the opportunity presented itself, I was eager to dig in. I've been following the directions for the Electric Eel Wheel http://www.dreamingrobots.com/ElectricEelWheel/BuildersGuideElectronics_v1200/ by Maurice Ribble.

The URL above lists all the recommended parts to build the PCB, including an ATMega168 which I seem to have ordered just before it was retired. My custom PCB just arrived today, and I'm anxious to dig in. So, in reading here on the Arduino site and elsewhere around the web, as well as in watching tutorial videos on YouTube, I get the idea that a USB connection is used to connect to my PC. There is some confusion in my mind about that, however, in that Maurice includes no USB connection, and Sparkfun Electronics ATmega168 with Arduino Bootloader - DEV-08846 - SparkFun Electronics? says:

To get this chip working with Arduino IDE, you will need an external 16MHz crystal or resonator, a 5V supply, and a serial connection.

I presume the serial connection is typically be made by USB? My question then is, given what I've purchased so far, can I install his Arduino program on the ATMega168 http://www.dreamingrobots.com/ElectricEelWheel/files/electricEelWheel.pde? If so, can someone point me to a tutorial, or give this lay person directions? If not, well, what might you do in my shoes?

when you buy a chip like the 168 (which is not retired, its just not most popular) unless it specifically says it has a bootloader, and cost nearly twice as much, its a blank chip. Think of it like a desktop computer with a blank disk in it, its just going to sit there and do nothing untill something tells it otherwise.

To get the bootloader on there, you need a programmer, and if you have a programmer you dont really HAVE to have a bootloader. The bootloader is just a little code that gets loaded when the chip first gets power, listens for a magic code over the serial port, and if it gets it programs the chip with your program, if it doesnt it just starts up whatever in there. (and yes it requires conversion to connect to a com port or a usb port on a pc, its not standard RS232)

Programmers range in cost and features from "make your own" if you already have an arduino, to a couple bucks on ebay, to over 100$ for development boards.

If I were you I would get something like an USBASP which runs 2-20 bucks, once you have that burn the bootloader (a simple menu option) which gives you serial programability and sets the chips fuses (options) for you. Again you dont have to use the bootloader, but you do have to set the fuses or else stuff is not going to work right ... and a couple clicks vs a big line of text in a command window you might as well install it.

edit: ack, just noticed you got the one with the bootloader if you bought it from sparkfun. In that case you can use the programmer above or you can get an FTDI cable / breakout board to program over USB (also available though sparkfun)

I believe (others may want to confirm this) you can use an ATMEGA328 on your project board.
You could then purchase an Arduino UNO (which has a 328) use it as your design platform.
You upload your compiled code from the Arduino IDE software using an USB cable.
Next you would remove the 328 from the UNO and plug it into the 28 pin socket on your project PCB.
I would recommend buying a few extra 328s (with boot loader) just in case you damage one.

I compiled your electricEelWheel.pde sketch, it was 2,748 bytes. The 168 has 16 Kbytes and the 328 has 32 Kbytes.

There are many other places on the NET also:

Good for you for wanting to get into this stuff.
You may find this interesting Arduino Tutorials | tronixstuff.com

yea 328p's and 168p's are interchangeable, you just get more ram and rom with the 328

My garsh; thank you both very much. I've been bouncing back and forth between eBay, Mouser, and SparkFun in order to better understand the direction you gave me, and slowly, illumination ramps. The only bit that I'm having a time with, Larry, is when you said, "I compiled your electricEelWheel.pde sketch, it was 2,748 bytes. The 168 has 16 Kbytes and the 328 has 32 Kbytes". I guess I'm not sure how to interpret that unless it was to suggest another good reason to upgrade the microchip? Well, I think I will, and I also think I'll get an extra one or two just in case.

You both also have my gratitude for not having sent me to buy a pre-made Arduino board. This is a lot more interesting, and I feel much more a part of the project by building the board, and learning about it, even if I'm merely following a recipe.

Osgeld, my apoloies for not having mentioned the bootloader. I don't fully understand what that means (I do a little), but I had read, and seen enough to know that it was important, and I intended to include it in my topic subject line.

Finally, Osgeld suggests the USBASP, while Larry recommends a Arduino UNO (could you point me to something that looks like you mean, there are a number of things that come up when I search for that). Do these two approaches accomplish the same thing? Does one have an advantage over the other?

ETA: Drat. Sorry, Larry; the first time I looked at those two links, I didn't catch what I was seeing.

Found these with good prices:

Arduino Uno R3 http://www.ebay.com/itm/Arduino-Uno-R3-/300823638330?pt=LH_DefaultDomain_0&hash=item460a7c713a

(Arduino-Compatible) UNO R3 MEGA 328 for Arduino IDE Software USB Cable 01052 http://www.ebay.com/itm/Arduino-Compatible-UNO-R3-MEGA-328-for-Arduino-IDE-Software-USB-Cable-01052-/281052236490?pt=LH_DefaultDomain_0&hash=item417004caca

USBasp AVR programmer Atmel arduino microcontroller http://www.ebay.com/itm/USBasp-AVR-programmer-Atmel-arduino-microcontroller-USB-ASP-ISP-USA-/181065759451?pt=LH_DefaultDomain_0&hash=item2a285c3adb

The only bit that I'm having a time with, Larry, is when you said, "I compiled your electricEelWheel.pde sketch, it was 2,748 bytes. The 168 has 16 Kbytes and the 328 has 32 Kbytes".

The 2,748 program will easily fit on both the 168 & 328 i.e. 2,748 < 16,384 and << 32,768.

Finally, Osgeld suggests the USBASP, while Larry recommends a Arduino UNO (could you point me to something that looks like you mean, there are a number of things that come up when I search for that). Do these two approaches accomplish the same thing? Does one have an advantage over the other?

Both methods will program the controller chip. I was suggesting the UNO because its an all in one solution and I think easier to use for a beginner.
When you finish this project, i.e. program the controller and move it from the UNO to your Electric Eel Wheel hardware PCB, you will still have the UNO (and extra controllers chips you buy) to further your learning on the Arduino.
The UNO: is user freindly, cost efficent, has a removable 328 (you may want to make a standalone product later), you do your developement on the UNO and it has a built in USB to serial converter for uploading sketches. (you will need a USB printer cable).
Here is an introductory glimps that may be of some interest: http://www.gammon.com.au/forum/?id=11637

I just sent the links as examples to where you can purchase these items.

usbasp is more of a soulution if you bought a blank chip from mouser or digikey with no other arduino ready hardware

since you got a bootloaded chip you can program it over serial (considering external conversion hardware like an FTDI chip)

the major advantage of using a programmer vs hooking up additional hardware to support serial programming is

it cost less, and your programmer will work with any other project you see down the road
VS if you discover a bug, your end user can just plug it into a USB port and update easily without a programmer with a file sent via email

in then end they all do the same thing, burn your program to rom so the chip runs

Larry does have a valid point though, you could buy a premade arduino, plop your 168 in place of the stock 328p ,use that to program your 168p and move it over to your final target

then you just plop the 328p that came with the arduino back in and move on to other projects/interests

if your even somewhat interested in arduino as a platform, I would buy an uno, once you have one you can program a pretty decent varity of chips, from 8 pin tinys to chips that have enough resources to emulate full blown computers from the early 80's

Thank you again for all your helpful information. I have a lot of reading / watching to do, a decision to make, and another part to order.

This past summer, I wanted to do a small html / css project, and while I had messed around with both for years, it was usually with the crutch of an editor. I wanted to write the code for myself using a text editor. With the vast amount of information, examples, and tutorials on the web, it was not all that difficult to do, but it was time consuming. In the process, I learned...about divs, about connecting css to html, and about code. I'm hooked. This is starting the same way that did, so you were speaking right to me when you suggested I might want to move on to another project when this one is completed. So, one of the things I want to do is to see what can be done.

I spent a couple of hours yesterday soldering my PCB. No one should be allowed to have so much fun when they're by themselves. At this point, without the software for this motor controller, the motor comes on, and spins at full speed in a clockwise direction, even when the potentiometer is straight up. It'll be a little while before I can spend more money on this, but I've decided to get the genuine Arduino UNO R3 Dev. board.

edited to correct a misspelling, and to remove no-longer-relevant links.

You did a great job soldering the PCB!
The push button, top RHS side pad, is lacking some solder flow through.
Note: you can use a Q Tip and Isopropyl alcohol to clean up any flux.
I suggest you put a red/white mark on top of the micro controller near pin 1 & on the PCB near pin 1 to remind you to plug the chip properly.
In the future, you may also want to keep the components as flush as possible to the board.
Good work.

Thanks, Larry! You have a very supportive way about you that's uncommon in tech forums.

I can easily add a tiny bit more solder to the corner push button pad as you suggested. I see that in the image now that you point it out, and I can see it on the board with a magnifying glass now, too.

I used a toothbrush with isopropyl as was suggested by the designer of this board. I gather by your having mentioned it that I didn't get it all. I'll study the enlargement to find and clean up the rest.

The marks at pin 1 of the micro controller are a good idea. I had been using the little notch, but the mark will be even easier to see.

Shoot. I intentionally kept some of the components away from the board just to try to keep them from getting too hot. With at least some of them, I think it won't be hard to drop them to where they should be. The resistors, and diodes are 3mm to 5mm above the PCB surface; should they be closer do you think? The crystal, and most of the capacitors should be easy to bring down.

Thanks very much again...those are some very helpful suggestions.

Since several of the components of my project get hot, and since both it, and the motor it will control will be housed inside a wooden box, I'd like to put a 12V. PC box fan in that box as well.

Can my project board support the fan as it is, and if so can I make solder connections with it's leads somewhere?

I found that I could connect the leads to two of the pads at the AC connector, but of course, it's not switched there. Allowing the fan to run all the time the unit is connected to the power supply is an alternative that works just fine, but I would like to connect it in a way that is controlled by the power switch.

do the diodes get hot?

the motor IC (the big metal tab chip) can have a chunky heatsink attached, which may be enough to not need a fan

The diodes get warm, but not hot. The L298N, the larger of the two chips with a metal tab gets warm, but not at all hot. The ATMega168 also gets warm, but the 5V Regulator LM7805, the smaller chip with a metal tab gets hotter than is comfortable to touch in just a few seconds, and it stays hot while the PCB is connected to the power supply, even if it is switched off. Is that normal?

The wooden box is not entirely closed, either. There is an opening about 2" x 4" to accommodate the belt; the PCB is fairly close to that. Maybe I don't need a fan.

it really should be switched with the rest of the power, but thats a design thing, if you have a radio shack this thing is sorta beefy

or you can often find good sized ones out of older appliances

having some breathing room does help, though without it you pretty much have to heat the entire volume of air up to some degree before heatskink efficiency diminishes

or you can often find good sized ones out of older appliances

That sent me on a scavenger hunt into corners of my house looking for anything that might contain a PCB to see what components I might find to salvage. Just a bit ago, I found a multi channel amplifier, a NAD 906, and it's just loaded with stuff in triplicate. It doesn't power on. I swear I never saw it before, either, and I haven't an idea where it came from. Several in working order have sold on eBay for around $100 in the last month. I may see if I can figure out what's wrong with some on-line tutorial help, but if not, I'll have loads of fodder to practice un-soldering components.

In the process of snugging the components down close to surface of my project board, I broke the wires of a 10uF Capacitor at the level of the solder. Now, I had a mess; how to remove the solder, and how to get the broken wire out of the hole. As it happens, I have 8" stainless steel double pointed knitting needles in all sorts of sizes from .7mm to 5mm. These holes are tiny, so I pulled one of the .7mm needles, heated it along with the solder until I could push the needle through the hole. After a couple of seconds, I pulled the needle back out of the hole, and on the back side, a small straw of solder remained. That easily knocked off, and revealed an open hole. Because there was an identical capacitor right next to that one, I knew how to align this one to keep polarity. It didn't explode when I connected it to the power source, and turned on the switch, and the motor turned as always.

Back to the amp; there are 3 aluminum angle irons about 1.5" x 1.25" x 12", and each of these is screwed to heat sinks about 1.75" x 3" x 9". To each of those angle irons are screwed many of what looks like 5V. Regulators. Everything inside is extremely dusty, and covered with lint, pet hair, and I don't know what else. When it's light tomorrow, it's going to get a good hard gust of wind from the air compressor.

What might I find in there that's worth keeping?