Well I began work on my ATtiny85, and so far it has been quite the adventure. My initial thought was that it would be cool to use one on my differential steer robot, so I plunged into making this happen.
There are several problems with this that I have seen so far.
- I will quickly run out of pins. I will probably want an ATtiny84. Maybe my 2313 will work. That’s another day.
- The servo library will not work on the ATtiny85, reason being that the servo library relies on a 16 bit timer whereas the ATtiny only has an 8 bit timer.
- The NewPing library does not work on the ATtiny. I believe this is the case anyway. The code will not compile. I haven’t looked into why this is. I’m assuming it has to do with the timers again. (Edit: check out my post on that HERE)
Problem One: Like I said earlier, I will probably need to change hardware for this one. However, the ping sensors can be run on one wire for trigger and echo which I am not doing at the moment because my Arduino Mega had pins to spare. That would diminish the pin count by 2. I could also get my two bumpers on the front off of one analog pin by putting a different sized resistor on each one.
Problem Two: Now it gets fun. As it turns out, way back in the days of IDE 20ish there was a library called SoftwareServo library (more info HERE). All these young whippersnappers (Me) don’t know what that is because they got that newfangled timer based Servo library. Interesting. Well this can be used to our advantage. Long story short, download the library HERE. Stay tuned if you want to hear how I changed it.
#include <WProgram.h> to
#include "Arduino.h"
This is to accommodate IDE 1.0+. For those that might not know, you can use a variety of programs to do this. I used CodeBlocks because it was what was set was the default on my computer. You could probably manage with notepad on a change like this, but I’d go ahead and download a free compiler somewhere. Just Google C/C++ compilers. I’m really not experienced enough to recommend one.
Next I went to getting it running on the ATtiny. Well it was not as convenient to do so as some other libraries because it only came with one example, SerialServo. Well this is a problem because the serial library does not run on the ATtiny85 in its current form either, but that is a problem for another day.
I went typing away and eventually got it to work, so I added a few examples for lazy people like me. I already gave a link to it, but here it is again: SoftwareServo.
The rest is pretty simple. You do need to flash the ATtiny
to run at 8MHz. That takes all of 15 seconds. Just connect it up, select the
ATtiny85 (internal 8 MHz) option and hit burn bootloader. Details from High-LowTech.
It works really well. It’s perhaps a bit more jumpy than running on my
Mega. That will happen though. I read an explanation on why that is, but it involves math and I really don't remember the details. I just know that the cut from a 16 bit timer to an 8 bit one cuts the resolution quite a bit.
Just for reference, there is also a Servo8bit library that I tried before I found the SoftwareServo library.I don’t believe it requires the Arduino IDE. I never got it to work, but maybe others can. Find details HERE. If you get it to work, let me know. I’d like to check it out.
That brings us to Problem Three. Well that is work for the future. I mainly just wanted to get a servo up and running. I succeeded with that. Yippee. Also, I got some new components and such. I will probably do a quick post on those soon too.
Happy Easter,
Matthew
This is to accommodate IDE 1.0+. For those that might not know, you can use a variety of programs to do this. I used CodeBlocks because it was what was set was the default on my computer. You could probably manage with notepad on a change like this, but I’d go ahead and download a free compiler somewhere. Just Google C/C++ compilers. I’m really not experienced enough to recommend one.
Next I went to getting it running on the ATtiny. Well it was not as convenient to do so as some other libraries because it only came with one example, SerialServo. Well this is a problem because the serial library does not run on the ATtiny85 in its current form either, but that is a problem for another day.
I went typing away and eventually got it to work, so I added a few examples for lazy people like me. I already gave a link to it, but here it is again: SoftwareServo.
Just for reference, there is also a Servo8bit library that I tried before I found the SoftwareServo library.I don’t believe it requires the Arduino IDE. I never got it to work, but maybe others can. Find details HERE. If you get it to work, let me know. I’d like to check it out.
That brings us to Problem Three. Well that is work for the future. I mainly just wanted to get a servo up and running. I succeeded with that. Yippee. Also, I got some new components and such. I will probably do a quick post on those soon too.
Happy Easter,
Matthew