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.

Here's another picture.

Friday, April 26, 2013

Breadboarding a Surface Mountable ATtiny85

I previously mentioned, I recently made a purchase from 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.
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 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.


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.


  • 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.


Monday, April 15, 2013

Resources for Learning Arduino

I thought I would do a quick post of some of the resources I found useful when I first started messing around with the Arduino.

  1. Arduino Learning Section- As I've watched some other people learn the Arduino system, the two biggest problems I've seen have been not reading the Getting Started section and not reading/knowing about the Learning section. is your friend. Bookmark it. 
  2. C Programming Quick Reference- I cannot find either the website or the paper copy of the one I used, but this is similar. It was somewhat useful until I found number 3.
  3. Arduino Companion App- Available where apps are sold. Its a free app available for IOS, Blackberry, and Android. I have no idea if there is/will be a version for Windows or Firefox OS. It has all the functions, libraries, datatypes, etc in a nice offline format. I still use it. Also has a built in resistor calculator. Very nice. (most of the stuff from the app can also be found HERE)
  4. Jeremy Blum's Youtube Channel- He also has a website. Most of the Arduino tutorials on YouTube are from him. They are pretty useful. My bumper debouncing circuit (which I don't think I ever got around to mentioning) was directly from his channel.
  5. The Arduino Forum- I haven't personally posted a lot of stuff out there, but there is still a lot of information to be found. If you do need to ask a question, be sure to check out the Sticky sections first. Chances are, you aren't the first person to ask that question, and you want to be sure that you follow posting etiquette. 
  6. Google- 3/4 of the battle is knowing what question to ask. I have a whole tab of bookmarks from all corners of the internet that is full of useful tutorials and forum posts. Also, datasheets are just a click away.
  7. Various Retailers- If you buy generic parts, often the real thing can be found on a retail website like Sparkfun, etc. That can be useful if you need to know what the real specs are.
  8. Various other Apps- I have an Ohm's law app and a few others that I use less often.

That's about all I can think of at the moment. If you have favorite source that I missed feel free to comment or fume privately. Of course, this blog is a source, I'm sure there are others as well.

 Hope you found this list useful

Wednesday, April 10, 2013

Continuous Rotation HXT900

I modified my first HXT900 for continuous rotation, and thought I would type up a quick list of notes.

I used a mixture of the techniques found on THIS webpage and THIS video. I will note that the video was pretty useless, but I did watch parts of it. Anyway, what I learned.

  • Its a pain. Getting the pot centered is about impossible.
  • Don't try to sand down the shaft. It will just get burred up. Instead, enlarge the hole.
  • Get drill bits. Don't try to enlarge the hole with a screwdriver like the video says.
  • You will have to remove any hotglue you put on the front of the shaft after you solder it. The gears won't fit back on if you don't.
  • Replacing the pot with two resistors of equal value does not work. 90 degrees is off-center for the pot. A clever person could figure out what size is required, but I didn't want to do that.
  • Getting the case back on at the end is a pain. Obviously, it is possible though.
That's about it I think. You can test your servo with THIS SKETCH. I used it to find the center of the servos I use on my differential steer robot, ie you may have to tell it to go to 91 to get it to stop instead of 90. It just requires your servo and a 10K pot.

That's all I have at the moment. More to come.

Monday, April 8, 2013

Upload sketch to Arduino Mega with External Programmer

Well I just "wasted" 30 minutes of my life and thought I should share it with the world.

As I have previously mentioned, I have an Arduino Mega with what I believe is a burnt out usb to serial chip. I haven't looked seriously into fixing it, but that might be a project for the future.

Anyway, as I now have a USBtinyISP, I thought I would try to program it with that.

Attempt One:  I found THIS webpage. Apparently you can change the setting in the preferences.txt to always upload via an external programmer. Well that's no good.  I only want to do it with one board. Oh wait,

"If you would rather use an external programmer for only an individual board, you can edit the boards.txt file in the hardware/ sub-directory of the Arduino application directory. Set the board.upload.using parameter to the identifier of one of the programmers in programmers.txt."

Well there's the solution. I'll create a new board that is just a copy of the Mega2560 except with the new settings.

Attempt Two: I found the Mega 2560 part in the boards.txt and go to deciphering. This goes rather slowly until I find THIS. Then I quickly sort it out into the correct lines and change what I believe needs to be changed. 

Upload. Error. Big surprise. 

I change some more settings and reopen the IDE. I go to open the blink example and notice something.

Attempt Three: "Upload Using Programmer". There it sits write below the upload command under the file tab. It works.

I abandoned my attempts to create the edited board file. It would just be redundant now. I don't know how long that option has been there. I checked, and it is there in the oldest IDE version I have (1.0.1). So it has been there at least since last October.

There is a moral to this story. Don't assume that because Google doesn't yield an easy solution, it doesn't exist. You may have just been skimming over it in the IDE.

May you always see the obvious.

Saturday, April 6, 2013

NewPing library on ATtiny

Well now we have come to the point where I need to address Problem 3. If you don't remember that one, it was mentioned back a few post ago.

We need to run the NewPing library (for my HC-SR04) on the ATtiny85. First things first, we will need some code to test it with so we know it is working. It doesn't have a convenient serial interface like the Mega. Enter NewPingLED.

Its purpose is to turn on an led when an object gets within 20cm of the sensor. This is something that the ATtiny85 can manage.

Next, I got it running on my Mega. Not too difficult. I did note that this sensor was a lot less accurate (and precise) than the other ones I got. Sometimes you get what you pay for. It was like $2.50 on Ebay.

I posted a video in case you don't believe me. Obviously, the Mega can also run any of the example programs that come with NewPing 1.5 as well.

Now on to the ATtiny. Well the code doesn't compile right out of the box. The problem is with some of the timers that the ATtiny doesn't have. This is discussed HERE. It sounds like a fix will be coming up shortly in version 1.6, but in the meantime you just have to comment out the stuff about the timers. If you want the library with that stuff pre-edited out, its HERE. Note that you won't be able to use those parts of the code on any other board until you change it back. Hopefully 1.6 isn't far away.

Now that we have that out of the way, we just need to change the pins to something usable, get rid of the serial stuff, and wire it up. I'm going to assume you can handle that (remember the resistor on the LED!). If you are having trouble with basic wiring and such, check out Jeremy Blum's stuff HERE.

The new code is HERE. As you can see, it works well. It's no miracle of science, but it's a step toward doing what I want to do. Just for fun I also did a Fade program. Next, I think it would be cool to do some basic communication with my Mega. Sending Ping values back and such. I also have some other projects on my mind though.

In case you didn't know, next week is National Robotics Week. That's sure to be a blast. Also, in the world of FIRST robotics, nationals are coming up. Be sure to check out the webcast HERE. There are sure to be some awesome Frisbee shooters there.

That's all I have for now. Check in again,

Thursday, April 4, 2013

ATtiny85 programming adapter

I've been playing with the my ATtiny85 and have been enjoying it. However, programming it can be a pain, because I have to break out the jumper wires and the datasheet to figure out which wires go where. This got annoying quick, so I got to problem solving.

This was the result. It simply plugs into my breadboard on top of the ATtiny and then rearranges the pins into a convenient 6-pin connector for my USBtinyISP. It works pretty well. I wanted to make a full Arduino style breakout board for it but had two things inhibiting that.

This stuff is junk.
One, my female headers haven't come in yet. They are in the mail, so maybe I will do that someday. Two, the cheap perfboard that I bought is cheap. It only has contacts on one side. I struggled working with it for a while. When I pulled a pad off of one contact, I gave up and got the good stuff. I switched to the stuff from HobbyKing. Now on to making your own

What you'll need

  • Male headers- specifically you'll need 14 pins
  • Protoboard- I used THIS stuff and it worked great. Perfect size too.
  • Wire- I used some stuff I had around. I believe it is called Kynar.
Step One: Cut the board to length. I needed a grid that was 6 x 7. However, when I switched to the HK protoboard, it was close to the size, so I used that.

Step Two: Solder on the male headers that plug into the ATtiny. It is simplest to plug it into a breadboard while you do this so that you know it will be straight and fit in the sockets.

Step Three: Solder on the male headers that plug into the USBtinyISP. I did the same thing as above and just flipped it over and soldered it in the breadboard.

Step Four: Connect the dots. This takes a little ingenuity on your part. I put the side with the RESET and GND pins on the left so that most of the pins were fairly straghtfoward. Be sure to mark it so you know which way to plug in the cable. The important thing is that   they a) go to the right places b) don't go to the wrong places and c) don't go where the ATtiny will physically be when this thing sits on top of it.

Step Five: Ring it out. Now you go through EVERY pin on the thing and make sure it goes where its supposed to (see the above charts). Next you go through EVERY pin and make sure it doesn't short out anywhere or do anything else harmful. I will not be responsible for any fried chips but my own.

Not pressed down
Now go test it out. I found it quite a bit more convenient than breaking out the charts and jumper wires every time. It's also less prone to errors. I will mention that you may need to unplug other things when loading code. Example, I had a servo plugged into pin 1 and tried to load code. The servo jumped around and the code didn't load right. Also, it probably would not be good to hook it up when the chip is under power. I don't know that for a fact but call it intuition.

Here are some more pictures in case its fuzzy just how this thing is connecting to the ATtiny. It sits on top of it.
It place and ready to go.

Well that's all I have.  I hope you find this useful. Have fun in all your endeavors


Wednesday, April 3, 2013

Recent Purchases: Mini-reviews

Well I thought I should mention some of my recent purchases that made the below project possible. I'll try to make this brief. If you haven't seen that project, go back two posts.

ATtiny85: I got this off of eBay for a few dollars. In the future, I will probably buy them somewhere else, but I just wanted one, so that was the cheapest thing to do. I am pleased with it.

Solderless Breadboard: 830 point solderless breadboard. MB-102. Also from Ebay. $4 shipped. I like it. It is twice as big as my other ones and the roominess is nice.

MB-102 Power Supply Module: Thats the thing on the left. It works really well. I am quite pleased. It takes a center positive power supply or a male usb A. It is switched and can provide 3.3V or 5V. It plugs right into the power rails of the board. $2.15 shipped from Ebay.

Jumper Wires: Yes I sold out and bought some ready made jumpers. I'm glad I did. They are stranded and thus much easier to work with. I was getting all my plain white wires confused. The colors make it easier. Note that I did not get an even distribution of colors. I got 65 total and maybe 3 were black. $2.39 from Ebay. I've only found one so far that doesn't work.

10K pot: I got these from Ebay a long time ago. I don't remember how much they were, but it was a few dollars for 10. They work ok. They were 10 +1-2 K. But for my purposes they were ok. A slight annoyance, the pins aren't long enough to go into a breadboard. Had to solder on some...

Male Headers: I got ten 40 pin rows of them for $.99 (Ebay-China)

HXT-900 Servo: These are my favorite servos, hands down. Cheap. Simple. Reliable. They are sold under various names much as sg-900 and towerpro. They are the 9g servo from HexTronik Ltd, the company that manufactures everything for Hobbyking. Get these servos HERE. And if you manage to strip the gears, get the replacement HERE. Its also worth noting that they sell a 5g version HERE. I did a write-up about HobbyKing in one of my first posts. I also got my first Arduino there.

Other: I also got 10 paper prototype boards from Ebay for $1.38. They had a bit of a chemical odor and were not the best, but they will do for messing around. Hobbyking also sells some higher quality stuff that I have bought. The green stuff. Its HERE. That stuff is pretty nice.

I have got some female headers as well for various projects that I have in my mind. They seem pretty decent. I got 10pcs 1x40 breakaway female headers for $3 from Ebay.

USBtinyISP: I put this last because I really have already mentioned this quite a bit, but I love this thing. It is extremely easy to use. You might look into the tinyProgrammer instead if you just want to do ATtinys, but this was $15 on Ebay from a US seller. It is high quality and I love it. Check out some of my past posts tagged USBtinyISP.

That's all I have for now. Go forth and spend you're hard-earned money.

Monday, April 1, 2013

SoftwareServo library - ATtiny85/45/25

This post will cover the the examples of ATtiny that come with the modified SoftwareServo library found HERE Please note that the commands themselves have not been changed. I merely changed it for IDE 1.0+ compatibility and added a few examples. For information, check it out HERE.

What you will need:

  • ATtiny85/45/25
  • USBtinyISP or other method of programming
  • Hobby servo
  • Jumper wires
  • Breadboard
  • 10K potentiometer 
First, I am assuming that you know how to load programs onto the ATtiny. If not, please refer to my last few posts and THIS link.

Second, I'm going to assume you have either tried the Servo library that comes with the IDE and know it does not work or have read my previous post.

Third, don't expect the SerialServo example to work on the ATtiny.

Configure the ATtiny: We need it to run at 8MHz. Luckily it has an internal 8MHz clock. We merely need to plug it in, select ATtiny85 (internal 8 MHz) under boards and hit burn bootloader. It should load pretty quickly.

In case you don't want to read the datasheet. (credits)
Sweep: This is the first example I added. It is very similar to the sweep example from the Servo library. Notice that you have to refresh the servo manually. This could be useful or annoying depending on your situation. Regardless, it is the nature of the beast.

Here is a diagram of how you should wire everything up. It is pretty simple. As you can see from the pinout chart above, you could change the pins somewhat. 

Knob: This too is similar to the example found in the Servo library. This requires that you hook up a 10k pot to pin 3. As you can see, you can choose one of the other analog inputs instead if you wish. 

Again, here is a diagram of how you can wire everything up.

Now in case you are one of those people that just like to see the real thing, you can check out a video of sweep HERE and knob HERE.

If you have any questions or comments, either comment here or send me an email.