Setting up Arduino IDE 1.0 and 1.6 for ATtiny and Manchester library
BackgroundI am currently working on a project where I want to deploy small battery powered ATtiny based modules to track a few things and to communicate back to an Arduino or Raspberry PI.
While I was first trying to use the Virtual Wire library, I found out it couldn't handle the ATtiny85 that I was operating at 1 MHz. The reason for this is that it has a different timing from chips that run at regular speeds, like the Arduino itself.
Luckily there is an alternative in form of the Manchester Encoding library for Arduino. It works not just with the typical Arduino chips but also with various ATtiny variants. The only problem was that my Arduino IDE setup I had in place did not work with this library. In the following I will outline what the issue was and how I got around fixing it.
My original ATtiny85 setupWhen I started out coding for the ATtiny85 I used sparkfun's excellent tutorial on how to set-up the Arduino environment to compile and upload ATtiny programs. At one point you need to install the hardware specs and code for the ATtiny family. Sparkfun and other places recommended David A. Mellis' repository, which I downloaded and which worked fine for the blink tutorial and a few simple projects. Even Virtual Wire was no problem with this setup.
Switching to arduino-tinyAs I mentioned in the beginning, I had to switch over to the Manchester encoding library. And when I did I got a bunch of error messages about symbols not being found:
error: 'TCCR2A' was not declared in this scope
error: 'WGM21' was not declared in this scope
error: 'TCCR2B' was not declared in this scope
error: 'CS21' was not declared in this scope
error: 'OCR2A' was not declared in this scope
error: 'TIMSK2' was not declared in this scope
error: 'OCIE2A' was not declared in this scope
error: 'TCNT2' was not declared in this scope
Through a post on Stack Exchange I found an alternative library for supporting the ATtiny hardware specs that seems more complete than the one I used before. It's called arduino-tiny and can be found on Google Code at the moment (though it might move since Google Code is in the process of shutting down).
Installing arduino-tiny in the Arduino IDE 1.0 was easy, but I had a few issues with Arduino 1.6 - though I eventually got it to work as well. I've done this on Windows but there shouldn't be a difference for doing this on other platforms.
Installing arduino-tiny for Arduino IDE 1.0Installing arduino-tiny for Arduino 1.0 is pretty easy. The Google Code site has two archives at the moment, one is for Arduino 1.0 and the other one for Arduino 1.5. Download the package for 1.0 and then:
- Extract the folder called 'tiny' from the archive you downloaded and put it into the .../Arduino/hardware directory. So in the end you'll have .../Arduino/hardware/tiny/...
- Navigate into the .../tiny/avr/ directory and create a new file called "boards.txt".
- Either copy the whole "Prospective Boards.txt" contents to this new file or search for the chip you have and only copy out this section. This will make your "Boards" sub-menu in the IDE less cluttered.
- This should be it. Restart the Arduino IDE and you should see the ATtiny in the "Boards" menu. Try to compile e.g. a blink program, it should all work.
Installing arduino-tiny for Arduino IDE 1.6
With Arduino 1.5/1.6 they seem to have changed a bit about where the compilers live and how the hardware specs have to be defined. Luckily the arduino-tiny site has an archive for Arduino 1.5 which already has the specs changed to be compatible. However, I couldn't get it to work with the IDE after following the steps I outline for Arduino IDE 1.0 above. When I did this I got an error when I tried to compile saying that the IDE couldn't find the compiler:
Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer.
Cannot run program "E:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++": CreateProcess error=2, The system cannot find the file specified
After looking at the Arduino 1.6 file structure I was surprised to not find the compilers and linkers in the tools directory. In fact I couldn't find them anywhere at first. After some digging around I finally found them in a zip archive under .../Arduino/dist/default_package.zip.
When I tried to Google about it I couldn't find much information, and maybe there is a better way to achieve what I want, but in the end I got it to work by unzipping parts of the archive to make the compiler accessible. Here is the full list of steps I needed to perform in order to compile for the ATtiny with the new Arduino 1.6 and the arduino-tiny hardware specs:
- Following the same steps I outlined for Arduino 1.0, with the only difference that you need to take the arduino-tiny archive for version 1.5. At the time I write this there was no 1.6 package, but the format seems to be the same.
- Next, take a look at .../Arduino/dist/default_package.zip. It contains a folder /packages/arduino/tools/avr-gcc/4.8.1-arduino2 (The exact name/version might be different if you got a newer/older version of the IDE, I am currently using 1.6.2.
- Create a new folder .../Arduino/hardware/tools/avr and extract the contents of default_package.zip/packages/arduino/tools/avr-gcc/4.8.1-arduino2 into there.
- The last thing you need to do is to edit .../Arduino/hardware/tiny/avr/platform.txt. Find the commented compiler.path line and replace it with:
- This should be all. Restart the IDE and try to compile a sketch for the ATtiny, including one that uses the Manchester encoding library.
I hope this post helps some folks to get set-up with their ATtiny and some more advanced libraries like the Manchester encoding library. I have the feeling that there might be an easier way to get the arduino-tiny hardware spec to work with Arduino IDE 1.6. If you know how to get around extracting the AVR compiler, please reach out and I will update this tutorial.
But in any way, I am glad I was able to unblock my wireless project which is using an ATtiny85 to transmit data using a 433MHz transmitter to an Arduino which has a receiver. I will create another article about this little project, but didn't want to spam it with these library and set-up issues.