Sunday, April 28, 2013

Using Reset pin as IO on ATtiny85/45 with avrdude and USBtinyISP

Today I'm going to discuss my successful attempt to use the reset pin of my ATtiny45 as an IO and then change it back again. I'm not going to go into a lot of detail because, a) I'm not an expert and b) other people already have. I'll just provide links to the useful pages.

The theory behind this is pretty simple. Basically, you change some fuse bits and the reset pin becomes pin 5. Unfortunately, this means you can't program it with a ICSP (like the USBtinyISP) anymore. You need a High Voltage Serial Programmer that supplies 12v to the reset pin before changing the fuse bits. There are several Arduino forum threads on this out there. Chances are you found those before you found this blog. Now lets get started.

1. You need to get some software. Follow the instructions from Ladyada to install WinAVR

2. You need load a test sketch into your ATtiny with your USBtinyISP or other programmer. I'm assuming you know how to do this. If not go HERE. I used blink with the pin changed to pin 5. If you load it and wire up the LED you shouldn't get any light.

3. Now you need to enable the reset pin as an IO (and thus lose programming capability). This is slightly involved. I recommend you see more instructions from Ladyada. They are very in depth and useful. If you want bare bones you can look below.
  1. Find a fuse calculator. I used THIS one. Select the options you want. I used default with reset disabled. Copy the AVRDUDE arguments.
  2. Open a command window by searching for cmd in the start menu.
  3. Type the commands to set the fuses: avrdude -c [insertyourprogrammerhere] -p [enteryourboardhere] -U [enter the arguments you previously copied here].  Example: If you are using an ATtiny45 and a USBtinyISP like I am (and are extremely lazy), copy and paste this line into the command window:     avrdude -c usbtiny -p attiny45 -U lfuse:w:0x62:m -U hfuse:w:0x5f:m -U efuse:w:0xff:m
  4. Watch and wait. You should get a nice thank you message. You're done.
You're reset pin should be acting like an IO now. If you plug in your LED now, it should blink nicely.

That's great! You know have 6 IO pins at your disposal, but you want to load a new program onto the chip. You need a HVSP. Go forth and Google search. To save you some time here are the cheap options out there.
My Arduino resetter circuit. 
I ended up using the last one, and it does work. All you need is a breadboard, jumpers, 6- 1k resistors, a 2N3904 NPN transistor (I found one on an old cordless phone), and an Arduino. You'll also need some source of 12V. Anyway, you pretty much just follow the instructions on the webpage above. After I discovered the bad jumper I was using, it went smoothly. 


When you finish, the LED on the reset pin should no longer work, but you will be able to program the chip again. This is good. You have successfully reset the fuses.

That's about all I have for this post. I hope you found it useful. Be sure to check out those other websites. They have a lot of good information.

-Matthew
Here's another picture.

Friday, April 26, 2013

Breadboarding a Surface Mountable ATtiny85

I previously mentioned, I recently made a purchase from Mouser.com. Today I wanted to make a quick post about one of my purchases.

I had planned on ordering a few ATtiny85's when ordered the stuff for my ATmega328 breakout. Unfortunately, the dip package was out of stock, so I did the next best thing. I ordered a few ATtiny45's and some surface mountable ATtiny85.

ATtiny85-20 SU vs SH
They had two that caught my eye. ATtiny85-20SU and the ATtiny85-20SH were $0.83 and $1.18 respectively. Honestly. I had no clue what the difference was, so I ordered a couple of each.

I received them and finally set about playing with them a few days ago. To the right you see a picture of the two different kinds. Don't let the picture deceive you. They look the same. I'm not an expert on such things. If someone knows what those letters mean let me know and I'll update this post.

UPDATE: Jason the PC MD says that the pins are made of different materials. This would make sense. Tin is cheaper.
SH:NiPdAu
SU: Tin

Regardless, I wanted to put them on a breadboard to play with. There are several ways to do this. Ideally, I would make a little PCB and solder it together. Maybe someday I will get into etching, but that day is not today. I have also heard of surface mounting protoboard which has smaller spacings to accomodate surface mounted parts. I'm sure there are other methods as well (I saw something about drawing with a conductive pen.. Not going there). Anyway, I had none of these methods available, so I broke out the soldering iron and went to town.

I started with a small piece of protoboard that I cut to size with an x-acto knife and sanded smooth.


Next I snapped off some male headers and placed them in a solder-less breadboard to insure they stayed straight. I randomly decided that I would use an ATtiny85-20SU and then began to very carefully solder each pin to the corresponding header. I used the same small Kynar wire that I used for my ATtiny programming adapter (which if you haven't seen, you should check out. It makes my life much easier when I program the ATtiny DIP sockets).


When I got done I squirted a good bit of hot glue under the ATtiny itself just to make sure it didn't move around and short out. I also super glued the headers to the protoboard because the pins aren't plated all the way through on this cheap protoboard, and I didn't want them to pull off with repeated use.


I have no doubt that this could be done more compactly. This is not pretty and won't work with my previously mentioned adapter, but it gets the job done. I have tested it; it works fine. As for SH vs SU mounting types, I still don't know. We will see what time reveals.

Also, this weekend is the FIRST Robotics Championship in St. Louis. If you don't know what that is, check out the website usfirst.org. The competition will be streaming live as well. That can be found HERE. I know from first hand experience that it is a lot of fun. If you ever get the chance to go to one of the events, you won't regret it. They are all free and open to the public.

-Matthew

Thursday, April 25, 2013

DIY Arduino: ATmega328P breakout, Hackduino++

Today I wanted to share with the world something I have been working on. Say hello to the Matthewduino 1.0. Very original name if I might say so.


Features:

  • Female headers on all pins
  • Male headers in "servo" orientation with signal, power, and ground on all IO pins (except 13)
  • Reset button
  • LED on pin 13
  • ICSP Header for easy programming
  • 2.5 mm power jack (center-positive)
  • 5V voltage regulator
  • Jumpers switch sensor ports between onboard power and power from an external source.
  • All the other stuff that comes with an ATmega328P 


It came into being because the usb to serial chip on the Arduino Mega on my robot burnt out some time ago. Now that I have my USBtinyISP, I can program it as detailed in previous posts. Great! The only problem is the ICSP Header gets covered up by the sensor shield. I could just rewire everything with wires and a breadboard, but that's no fun.

I had previously seen THIS website and decided that would be the way to go. I basically made a Hackuino with a built in sensor shield. It even has the Mouser project file linked. I noticed one of the components was invalid. Well I found a replacement fairly easily. HERE is the needed capacitor. Be sure to get at least two.

I ordered enough components for two ATega328P breakouts and some spares. I also threw in some ATtiny85's, an ATtiny2313, and an ATtiny84. Total came to under $30 with shipping. That isn't bad.

I may do a build post later; I have lots of pictures. For now, this is some of the other parts I needed.

  • Protoboard: Ebay- 5 for $4.50: 5x Double-Side Prototype PCB, 50x70mm, Universal Board
  • Male Headers: Ebay- 10 for $1.00: 10pcs 40 Pin 2.0mm Single Row Pin Male Header
  • Female Headers: Ebay- 10 for $3.00: 10pcs 2.54 1X40pin breakaway Straight female header
  • LED and 1k resistor- My LED came from Pololu. 
  • Wire- Mine came off an old garage door opener.
  • Jumpers- I used two off an old computer so that I can switch the male headers between external power and the onboard voltage regulator.
  • 2.5mm Power jack- Mine came off an old cordless phone.
I have no doubt that Mouser also sells many of these things.

What did I learn? Well it took much longer than I thought it would to solder together. All told, I probably spent five or six hours soldering/figuring out how it went together. Likewise, I have a new found respect for printed circuit boards. They are good things. Also, make sure you have a decent soldering iron. I'm not a very experienced solderer, but my life got much easier once I got the temp set right. 

I never did any sort of layout before I started. I looked at some software for laying out protoboard circuits, but I wasn't familiar with it. I just dove in. It turned out well enough.

When I finally did get done, I rang it out with the multimeter and had to fix some broken joints. I had a bad MISO joint that kept it from uploading. I also wired the reset backwards. I fixed that, and now it works great. I may run into problems with it later, but I have another ATmega328P in the bag to play with if that happens.

Anyway, I don't have a schematic  but here are some pictures. I hope this inspires you to go work on your own projects.

-Matthew