Home > Arduino, Guides, TKJ Electronics > ATtinyRemote

ATtinyRemote

I have previous thought about buying a universal remote like this one, as I was tired of grabbing my JVC remote for my stereo everytime I had to turn it on, off or turn the volume up or down. But then I discovered Ken Shirriff’s IR Library for the Arduino. Normally the library didn’t support neither the Panasonic or JVC protocol, but I discovered that somebody else had already added them. See the forked github library. At first I simple downloaded the library and tested whenever it could decode the Panasonic protocol and send commands to my JVC stereo. It had to tweak the library a bit, but then it worked just fine.
I thought it would be a bit overkill to use an Arduino and I didn’t want to rewrite the whole library, so I decided to use another AVR’s but in a much smaller package, the ATtiny85. Which is 8-pin AVR.

Development
I the beginning I thought about writing everything in C and then compile and upload everything using the terminal, but then I discovered that one can easily use the Arduino IDE to compile and upload the code.

To use an ATtiny85 with the Arduino IDE, you simple download the ATtiny core for Arduino. Then move the content to a folder called “hardware” inside the Arduino sketchbook folder (you can find it’s location in the preferences dialog in the Arduino software). If the hardware folder doesn’t already exist, just create a new folder called “hardware” in the sketchbook folder. After that simply restart the Arduino IDE. Now you can select “ATtiny85 @ 16 MHz (external crystal; 4.3 V BOD)” in Tools>Board menu.

But you can’t simply upload the program to the ATtiny85 as you normally would, you have to use a programmer. The good thing about AVR’s is that you don’t have to spend another cent if you already own an Arduino, as you can use the Arduino itself as a programmer. To use the Arduino as an ISP see my previous post for more information or see this video by MAKE Magazine which describes the basics in detail: http://youtu.be/30rPt802n1k.

I had some problems with the Arduino ISP sketch in the Arduino IDE version 1.0, but the one in version 0.22 works just fine. So go and download the old IDE, if you can’t get it working.

Then connect the Arduino to the ATtiny85, with some jumper wires, as follows:

ATtiny85       -   Arduino
PIN 8 (VCC)    -   5V
PIN 4 (GND)    -   GND
PIN 1 (RESET)  -   PIN 10 (Slave Reset)
PIN 5 (MOSI)   -   PIN 11 (MOSI)
PIN 6 (MISO)   -   PIN 12 (MISO)
PIN 7 (SCK)    -   Pin 13 (SCK)

For some reason I couldn’t burn the fuses using the Arduino IDE, but it’s pretty simple to use the terminal too. To set the fuses you should download AVRDude or you could simple download WinAVR if you are running windows or CrossPack if your are running MAC OS X, as it contains a GNU compiler suite, a C library for the AVR, the AVRDude uploader, and other AVR development tools.

After you have downloaded the program, go ahead an open a terminal. In windows open run and type cmd, or in MAC OS X simply open the terminal application.

After that you simply type

avrdude -p t85 -P /dev/tty.usb* -c avrisp -b 19200

To check if the communication is working. If you are running Windows, you should replace “/dev/tty.usb*” with the COM-port of your Arduino ISP.

The terminal will then print out something like this:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.25s

avrdude: Device signature = 0x1e930b

avrdude: safemode: Fuses OK

avrdude done. Thank you.

You can just ignore the first line.
If it didn’t work, double check all the connection, remember you should also connect 5V and GND to the ATtiny85.

If that’s works, you simple set the fuses like so:

avrdude -p t85 -P /dev/tty.usb* -c avrisp -b 19200 -U lfuse:w:0xff:m -U hfuse:w:0xd4:m -U efuse:w:0xff:m

This will print out something like this:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e930b
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.05s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xd4"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.05s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd4:
avrdude: load data hfuse data from input file 0xd4:
avrdude: input file 0xd4 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.05s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xff"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xff:
avrdude: load data efuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.05s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

This will set the ATtiny85 to use an external crystal at 8MHz or above, the start-up time is set to 16K CK/14 CK + 65ms, brown-out detection is set to 4.3, the EEPROM is preserved though chip erase cycle, and the SPI is enabled.
NB: You should be very careful when written the fuses, as you can BRICK your chip, if you for instance disable the SPI interface or disable the reset pin.
For more information see ladyada’s excellent tutorial. Also see the datasheet at page 25 for more information.
If your are going to set some different fuses, I recommend the Engbedded Atmel AVRร‚ยฎ Fuse Calculator.

If you don’t like using the command line, you can download the following program: AVRFuses, for both Windows and MAC OS X. If you are running Windows, you can also just download AVR Studio which will include all you will ever need for AVR’s.

The reason why I decided to use an external crystal was because the timing has to be very precise when sending the IR commands. I know that you could properly just use the internal clock inside the ATtiny85. It could be achieved by tuning the internal clock using the following sketch: TinyTuner. But as I don’t care that much about production cost, it would be easier just to use an external 16MHz crystal, as I had some of them laying around.

You should connect the crystal as follows:

Where C1 and C2 are 22pF capacitors.

The next thing you will need is a IR LED to send the commands, I used one I had in my drawer, but any IR LED just like this one could be used. You might also want some with a wider angle, so you can combine these two types, if you are going to mount it permanently. The wider angle ones are usually blue/violet.

The next thing you will need is a IR receiver. I used a TSOP4838, but you could use any one you like. I recommend getting a 38kHz one, as this is the most common, but check the frequency of your the IR protocol you want to decode before buying one. See the LIRC page for more information.

The code
The next thing I had to do, was to write the code itself.
The receiving code is based around Adafruit’s IR-Commander sketch while the decoding of the Panasonic protocol and sending of the JVC commands are based upon a forked version of Ken Shirriff’s library.

The finished code can be found at github: ATtinyRemote.

Update
I have now created a highly optimized new version of the code. Instead of using a timeroverflow to measure the pulses and then save them in a buffer, which you have to do if you want to compare the data to a lot of different protocols, you could just use a interrupt and then a timer to measure the time of the pulse, if you only need to compare it against one protocol. The outcome is that the code is much faster – the ATtiny now react instantly, there is no noticeable delay at all.
The new updated version can be found at github as well: https://github.com/TKJElectronics/ATtinyRemote/tree/master/ATtinyRemoteVer2.

The functionality is pretty simply, if I press the red button it turns my stereo on/off, the green button mutes and unmutes the stereo, and finally the yellow and blue bottom respectively turns the volume down and up. The stereo will also turn on/off whenever I turn my TV on/off. Finally the power button in the bottom left disables/enables the ATtinyRemote. This allows the user to use the color buttons as you use them very rarely to change settings.

I have used the port registers as much as possible, so it would be easy to port it to other AVR’s. The only thing I used from the Arduino IDE, is the delay functionality, as I discovered that the delay microseconds function in the popular AVR Libc library isn’t precise enough for the sending functionality.
If you want to port the code to another AVR, that’s not supported in the Arduino IDE, you could just copy the delayMicroseconds() from the Arduino IDE as I couldn’t get it working properly with the delay function from AVR Libc.

The PCB
I decided to use an IR emitter, also known as an IR blaster, and an IR receiver cable from ebay. They can simply be connected to the PCB with a normal 3.5mm Jack plug.

I decided this to be my final design, as I didn’t like the ATtinyRemote to be visible to the user. By having the cables, I could mount the PCB on the back of my tv, while getting power from the USB port at the same time. By doing that, only the cables would be visible. Also I would save power, as it’s only turned on, while my TV is also turned on.

The schematic for the PCB can be seen below:

And the finished PCB from Dorkbotpdx can be seen below:
[nggallery id=3]

The PCB is available at Github as well.

You might have noticed that the protecting resistor is only 22Ω for the IR emitter, but the thing is that a IR LED can actually handle up to approximately 1A depending of the type – but only for a few milliseconds! This is not a problem when using it for IR communication, as it toggles at a frequency of 38kHz (this change depending on the specific protocol), but if you turn it on constantly you might damage the IR LED, so while prototyping I recommend a larger value protecting resistor. See this page for more information.

Since I didn’t know the exact specs for the IR emitter, I just decided the following values for my circuit: a forward voltage of 1.1V and a 22Ω protecting resistor. By using Ohm’s lov one can calculate that the current through the LED is 177.3mA ((5V-1.1V)/22Ω).

Get one
If you would like a kit, please send me an email at kristianl@tkjelectronics.dk.

For information on how to implement your own IR protocol, I recommend the following pages

If you don’t own a ATtiny85 and want to control you JVC or Panasonic device, check out my forked repository at github: https://github.com/TKJElectronics/Arduino-IRremote as I added the protocols to Ken Shirriff’s original library.

In the case you missed it here is a link to the final source code: ATtinyRemote.

For more information about PWM see the following pages:

If you got problems uploading to the ATtiny, then see the following sites:

For more information about how IR works:

Categories: Arduino, Guides, TKJ Electronics Tags:
  1. robbok
    March 25th, 2012 at 21:34 | #1

    Hello, this code looks excellent and it is very relevnt to what I’m trying to do, although I’m not working with TV remotes. I have an ATTiny84 and just want to get a basic IR library up and running. Do you have any advice for how to “genericize” this code so it doesn’t have the “Panasonic to JVC” logic? All I need to be able to do is control individual pins on my ATTiny84 with a standard remote (this one: http://www.robotshop.com/productinfo.aspx?pc=RB-Dfr-92&lang=en-US).

    Lastly, do you anticipate any issues using your library if I’m also using delay() and PWM for LEDs on the same chip? Not sure if these will be upset by your use of interrupt code.

    Any advice would be much appreciated, thank you!

    –Rob

  2. Lauszus
    March 25th, 2012 at 21:51 | #2

    @robbok
    Hi,
    The first thing I would do is to download the library for Arduino and run the IRrecvDump example by doing so, you can decode which protocol your remote is using.
    After that you should modify the receiving part of the code. First modify the commandLength (it’s the number of bits + 2). You should then modify the decoding part. If it is send the same way as the panasonic protocol, the only thing you have to change is the values (PANASONIC_HDR_MARK, PANASONIC_HDR_SPACE etc.), like so: https://github.com/TKJElectronics/ATtinyRemote/blob/master/IRremote.h#L32

    And lastly just change the switch case, so instead of sending a IR code, turn on a specific pin etc.

    I don’t use interrupt at all. So you could use any pin that supports PWM.

    Best Regards
    Kristian Lauszus

  3. Robb Kunz
    April 2nd, 2012 at 20:32 | #3

    Lauszus,
    thanks for posting all this. I have the need to make 20 ATTINY85-based circuits work at exactly the same time. I began to program them with the Arduino (using 22) and realized that the internal oscillators are all over the place. Furthermore, these will be outdoors in temperature gradients.
    So external crystals will be essential.

    Two things. after downloading the ATTiny Core into the hardware folder and restarting, I still do not see the Board option you listed for ATTiny85 at 16MHz. Hmmm. Clues?

    Secondly, is it possible to use a 14.745MHz crystal?They are WAY cheaper.

  4. Lauszus
    April 6th, 2012 at 19:57 | #4

    @Robb Kunz
    Are you sure you have put the folder in the right location? You have to create a folder called “hardware” and put it in your Arduino folder – the same place as the “library” folder.

    Yes It is, but your should add this to the boards.txt file:

    attiny85at16e.name=ATtiny85 @ 14.745 MHz (external crystal; 4.3 V BOD)

    # The following do NOT work…
    # attiny85at16e.upload.using=avrispv2
    # attiny85at16e.upload.using=Pololu USB AVR Programmer

    # The following DO work (pick one)…
    attiny85at16e.upload.using=arduino:arduinoisp
    # attiny85at16e.upload.protocol=avrispv2
    # attiny85at16e.upload.using=pololu

    attiny85at16e.upload.maximum_size=8192

    # Ext. Crystal Osc.; Frequency 8.0- MHz; Start-up time PWRDWN/RESET: 16K CK/14 CK + 65 ms; [CKSEL=1111 SUT=11]
    # Brown-out detection level at VCC=4.3 V; [BODLEVEL=100]
    # Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
    # Serial program downloading (SPI) enabled; [SPIEN=0]

    attiny85at16e.bootloader.low_fuses=0xFF
    attiny85at16e.bootloader.high_fuses=0xD4
    attiny85at16e.bootloader.extended_fuses=0xFF
    attiny85at16e.bootloader.path=empty
    attiny85at16e.bootloader.file=empty85at16.hex

    attiny85at16e.build.mcu=attiny85
    attiny85at16e.build.f_cpu=14745000L
    attiny85at16e.build.core=tiny

    Best Regards
    Lauszus

  5. Robb Kunz
    April 11th, 2012 at 01:05 | #5

    Thanks Lauszus.
    I found a better deal on 16MHz crystals and went along with those.
    After sorting out the boards.txt and getting it in the folder AND having the crystal
    set in place when I uploaded the bootloader and program, it was supposedly burned
    into the ATTINY85 with Arduino1.0. No errors. BUT using a simple blink example
    or anything, doesn’t work when powered up. Nothing happens. What can I say?
    I’m lost. What if there was already something burned in it before? Could that be
    screwing things up? There’s so many places things can go wrong eh?

    Supposing I DO figure out. Would there also be a way to change the BOD voltage
    to 3.3V or something like that?

    Anyhow Big Thanks for the help.

  6. Lauszus
    April 11th, 2012 at 01:42 | #6

    @Robb Kunz
    Try to download WinAVR or CrossPack if you are running Mac OS X and run avrdude from the command line and see what it outputs.
    I also had some problems using the build in “Burn Bootloader” functionality and then you will also learn some of the stuff that’s under the hood of the Arduino IDE ๐Ÿ™‚

    You should use the following command to set the BOD voltage to 2.7V:
    avrdude -p t85 -P /dev/tty.usb* -c avrisp -b 19200 -U lfuse:w:0xff:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m

    See the Engbedded Atmel AVRยฎ Fuse Calculator for more information.

    Best Regards
    Lauszus

  7. Robb Kunz
    April 11th, 2012 at 02:29 | #7

    Fuses are fine. I reburned the bootloader for the factory internal 8Mhz and no BOD… uploaded
    a program. Works fine. Just wanted to get things back to normal.

    Then I tried burning a new bootloader for internal 16MHz PLL (using Arduino). No errors but
    then Blink wouldn’t even work.

    I hear you about using CrossPack. I use it to check fuses and I’m okay about changing them too using the Fuse Calculator to determine values… but I don’t think I’d know how to use it to upload a program I wrote in Arduino. You dig?
    Anyway, thanks for being so forthcoming.

  8. Lauszus
    April 11th, 2012 at 14:16 | #8

    @Robb Kunz
    Are you trying to set the internal clock to 16MHz or are you using an external crystal?

    Actually you don’t have too, but I just had some problems burning the fuses using the Arduino IDE. When uploading remember to use: “Upload Using Programmer”.

    Best Regards
    Lauszus

  9. Robb Kunz
    April 11th, 2012 at 22:24 | #9

    In Arduino 1.0, there is an option to Burn Bootloader. So I burn the bootloader at external 16MHz, 4.3V BOD. Then I upload a blink sketch… with (or without programmer). But the circuit doesn’t function. Weird. I can reburn a bootloader set for the internal crystal at 8MHz and it will work no problem. So, I’m not sure what the hell is wrong. How could I use the terminal command line to upload sketches written in Arduino? Is it possible? It might be nice to take Arduino out of the loop. Thanks again.

  10. Lauszus
    April 11th, 2012 at 22:50 | #10

    @Robb Kunz
    Okay, I got to ask. Have you connected the crystal correctly? See the picture from the post on how to connect it to your ATtiny85.

    There are several guides out there, just try to google avrdude, gcc compiler etc.
    What most people do is that they use a Makefile – try googling: “Makefile AVR” and then you could just type make all or something like that in a terminal and it will build your program.

    Here is a link for a makefile I have used myself:
    http://www.tkjelectronics.dk/uploads/Makefile_AVR

    Configure the file accordingly to your setup and type “make writeflash” in a terminal inside your folder to upload the program.

    You could also try to download Atmels official IDE: AVR Studio.

    Regards
    Lauszus

  11. Robb Kunz
    April 11th, 2012 at 23:00 | #11

    Right? Yeah, I’m sure I have the crystal situated correctly between physical pins 2 and 3 with
    22pf caps from each pin to ground. I’m using ceramic caps. Also tried without caps as I read that ATTINY85 has internal caps when set for external crystal. No effect.

    I can’t use AVR Studio as I am on Mac and am not going to install Windows. I’ll try to look up Makefile and do a bit of research on that. Thanks.

  12. Lauszus
    April 11th, 2012 at 23:05 | #12

    @Robb Kunz
    Okay, that is very weird. If you remove the crystal and try to burn the fuses – is that possible for you? As you shouldn’t be able too if the fuses are burned correctly.

    Okay. I recommend trying the makefile I uploaded, but then you have to install CrossPack.

    Regards
    Lauszus

  13. Robb Kunz
    April 11th, 2012 at 23:17 | #13

    Yeah, I know. The fuses appear to be getting burned correctly because the crystal MUST be in place for the appropriate bootloader to be burned. I’m not sure I want to try uploading your makefile since it’s a specialized IR function and I don’t want to build the circuit for testing. I do have CrossPack installed and I will try to figure out how to use that instead of Arduino.

    Weird how it appears to work, and does but not when the crystal is in the mix. Are we totally sure that new boards.txt file is working? Seems like it should be.

  14. Lauszus
    April 11th, 2012 at 23:37 | #14

    @Robb Kunz
    Okay, that’s very weird.

    No you misunderstand me. The makefile has nothing to do with my program. It’s just an easier way of compiling and uploading your program.
    For instance check out this blink led program I wrote a while back:
    http://www.tkjelectronics.dk/uploads/Blink.zip
    Just open a terminal window in the folder and type “make writeflash” and it should upload the program.
    Now connect a LED to pin PB0 (pin 5) and it should start to blink!

    Hmm, you are using this one right? I can confirm that it’s working.

    Regards
    Lauszus

  15. Robb Kunz
    April 12th, 2012 at 00:21 | #15

    Hmm. Why yes. That does indeed work. But I see that I will have to learn C very quickly to make it work, eh? Arduino syntax isn’t going to get a pass, is it? I tell you what… I will reset the fuses using Terminal, then upload your program and see if it works. If not, I’m back to first square.
    If it DOES work, I may have an old coding of my program that a friend did for me in C. Bang, done! But otherwise, I don’t have time to learn C in the next day or two. I have to start fabbing the circuits and it’s a one man assembly line.

    I really really appreciate all your help in the past few days. It’s folks like you who make the Internet so helpful, informative and rich.
    -robb

  16. Lauszus
    April 12th, 2012 at 00:28 | #16

    @Robb Kunz
    You shouldn’t have to, it should work with the Arduino IDE. The blink program is just a small test to see if it works – then I can see if it’s a problem with your setup or something like that.

    The Arduino IDE should work. Have you tried other versions of the ArduinoISP sketch. I couldn’t get it working properly with the one in IDE Ver 1.0, but the one in Ver. 0.22 worked perfectly. So try to download that version and upload using that one instead.

    Good work with the boards – send me a link when you have then thing up an running. I have my fingers crossed! ๐Ÿ™‚

    Thank you very much. Feedback like yours is why we do this! ๐Ÿ˜‰

    Regards
    Lauszus

  17. Robb Kunz
    April 13th, 2012 at 22:29 | #17

    Wow! So, you want to know the central problem? Brown out detection
    level was set to 4.3V and I stupidly had a Schottky diode inline
    with the VCC so it was dropping around a half volt and getting
    right down to the brown out level. Hence the weird dim flickering.

    Anyway, the good news is after a couple hours of pulling out my
    hair, I finally got the two circuits working and they are sitting here
    blinking in unison for a half hour now. Definitely synchronized enough
    for my needs. Thank you.

    I have one question though. I want to still use Arduino to program
    my chips (instead of the Crosspack/Terminal combo). Unfortunately,
    I cannot decipher the hex coding for the fuses. The fuse calculator
    generates hex settings that seem to be a bit different than the board.txt
    syntax.

    I would really like to add to a setting to my boards.txt that is:
    16MHz external crystal, 2.7V BOD
    Can you quickly assist me with crafting such an entry?
    I’d be ever so grateful!

  18. Lauszus
    April 13th, 2012 at 22:37 | #18

    @Robb Kunz
    Nice to hear you got it working ๐Ÿ™‚

    Just add the following to boards.txt:

    attiny85at16e.name=ATtiny85 @ 16 MHz (external crystal; 2.7 V BOD)

    # The following do NOT work…
    # attiny85at16e.upload.using=avrispv2
    # attiny85at16e.upload.using=Pololu USB AVR Programmer

    # The following DO work (pick one)…
    attiny85at16e.upload.using=arduino:arduinoisp
    # attiny85at16e.upload.protocol=avrispv2
    # attiny85at16e.upload.using=pololu

    attiny85at16e.upload.maximum_size=8192

    # Ext. Crystal Osc.; Frequency 8.0- MHz; Start-up time PWRDWN/RESET: 16K CK/14 CK + 65 ms; [CKSEL=1111 SUT=11]
    # Brown-out detection level at VCC=2.7 V; [BODLEVEL=101]
    # Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
    # Serial program downloading (SPI) enabled; [SPIEN=0]

    attiny85at16e.bootloader.low_fuses=0xFF
    attiny85at16e.bootloader.high_fuses=0xD5
    attiny85at16e.bootloader.extended_fuses=0xFF
    attiny85at16e.bootloader.path=empty
    attiny85at16e.bootloader.file=empty85at16.hex

    attiny85at16e.build.mcu=attiny85
    attiny85at16e.build.f_cpu=16000000L
    attiny85at16e.build.core=tiny

    Regards
    Lauszus

  19. Robb Kunz
    April 13th, 2012 at 22:46 | #19

    Rad! Thanks so much!

  20. Lauszus
    April 13th, 2012 at 22:54 | #20

    @Robb Kunz
    Your welcome ๐Ÿ™‚
    Keep me updated on your progress!

    Regards
    Lauszus

  21. Robb Kunz
    April 13th, 2012 at 22:56 | #21

    I think there was a small error with that code at least for the Arduino.
    attiny85at16.bootloader.unlock_bits=0xFF
    attiny85at16.bootloader.lock_bits=0xFF

    I deleted those two lines and now it works fine.

  22. Lauszus
    April 13th, 2012 at 22:59 | #22

    @Robb Kunz
    I just discovered that I had an old version of the board.txt file. I have modified the reply accordingly.

    Regards
    Lauszus

  23. Robb Kunz
    April 13th, 2012 at 23:20 | #23

    Hmm, using that new code… it now no longer shows up as a board in Arduino.
    I looked it over pretty good and I can’t spot any syntax problems.

  24. Lauszus
    April 13th, 2012 at 23:28 | #24

    @Robb Kunz
    Have you remembered to restart the Arduino IDE?

  25. Robb Kunz
    April 13th, 2012 at 23:38 | #25

    Quit and restart. Yup.

  26. Lauszus
    April 13th, 2012 at 23:43 | #26

    @Robb Kunz
    I just added it to my setup. It works perfectly fine with me – running Arduino IDE 1.0.

  27. Robb Kunz
    April 14th, 2012 at 00:07 | #27

    There’s no bootloader files to change or anything else?
    Just add that entry? Weird. It was there and then I updated with
    that updated entry and now it’s no longer an option.
    You still have that previous code?
    This is becoming ghost in the machine stuff.
    Quite sorry.

  28. Lauszus
    April 14th, 2012 at 00:09 | #28

    @Robb Kunz
    No, it’s just like usual.

    Here is the previous one:

    attiny85at16.name=ATtiny85 @ 16 MHz (external crystal; 2.7 V BOD)

    # The following do NOT work…
    # attiny85at16.upload.using=avrispv2
    # attiny85at16.upload.using=Pololu USB AVR Programmer

    # The following DO work (pick one)…
    attiny85at16.upload.using=arduino:arduinoisp
    # attiny85at16.upload.protocol=avrispv2
    # attiny85at16.upload.using=pololu

    attiny85at16.upload.maximum_size=8192

    # Ext. Crystal Osc.; Frequency 8.0- MHz; Start-up time PWRDWN/RESET: 16K CK/14 CK + 65 ms; [CKSEL=1111 SUT=11]
    # Brown-out detection level at VCC=2.7 V; [BODLEVEL=101]
    # Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
    # Serial program downloading (SPI) enabled; [SPIEN=0]

    attiny85at16.bootloader.low_fuses=0xFF
    attiny85at16.bootloader.high_fuses=0xD5
    attiny85at16.bootloader.extended_fuses=0xFF
    attiny85at16.bootloader.path=empty
    attiny85at16.bootloader.file=empty85at16.hex

    attiny85at16.bootloader.unlock_bits=0xFF
    attiny85at16.bootloader.lock_bits=0xFF

    attiny85at16.build.mcu=attiny85
    attiny85at16.build.f_cpu=16000000L
    attiny85at16.build.core=tiny

    As you can see, the only difference is the unlock and lock bits.

  29. Robb Kunz
    April 14th, 2012 at 00:31 | #29

    I give up for today. But thanks for the help as always.

  30. Lauszus
    April 14th, 2012 at 00:32 | #30

    @Robb Kunz
    Your welcome ๐Ÿ™‚

  31. Robb Kunz
    April 16th, 2012 at 22:55 | #31

    Gave it a day’s rest and came back to it.
    Now no problem. But I’m not at the workshop…
    which is in a former immigration prison. It makes
    me wonder if the place is cursed. Or perhaps my
    bench power supply needs to be looked at. Clean
    power is everything.

  32. Lauszus
    April 16th, 2012 at 23:11 | #32

    @Robb Kunz
    Haha, yes that might be a good idea. Or you could always power it from another Arduino ๐Ÿ™‚

  33. Robb Kunz
    April 16th, 2012 at 23:30 | #33

    Yeah, but sometimes I get an error that the Arduino is sucking too much power
    via USB. Heia, I wonder if you could modify the fuse entry for No BOD?

    I remade my code to work in infinite loop without problem. So even if this
    supercapacitor messes around with the VCC levels, it will not matter. At the moment,
    the 2.7V BOD is doing something odd with the circuit. I wish I had a battery with me.

  34. Lauszus
    April 16th, 2012 at 23:37 | #34

    @Robb Kunz
    Okay, you are powering it from 3.3V right? It actually one of the things they improved in the Arduino Uno – see http://www.ladyada.net/library/arduino/unofaq.html at “More 3.3v power!”. So I’m guessing that you are not using a Uno? ๐Ÿ™‚

    You could also drop the BOD al together? and then run it of the internal oscillator? Actually the AVR is not rated to run at 16MHz when running at only 3.3V, so that might also be a problem.

    Regards
    Lauszus

  35. Robb Kunz
    April 16th, 2012 at 23:56 | #35

    It’s a Duemilanove plugged into USB. I testy exactly 5volts coming
    out of it, even with load.

    Ideally, I think I would like to use the external 16MHz crystal (which
    is working great) but with no BOD. The idea is that my circuit VCC gets
    switched off but a super cap keeps the chip running long enough to detect
    the cut, and activate a solid state relay for 4 seconds, then loop until
    power is restored. Removing the influence of the BOD would help a great
    deal. I’ll see if I can decipher the fuse settings for that.

  36. Robb Kunz
    April 17th, 2012 at 00:01 | #36

    P.s. I’m thinking that it’s not enough to change the boards.txt.
    There’s a call for a bootloader hex file. Must that be changed too?

  37. Lauszus
    April 17th, 2012 at 20:24 | #37

    @Robb Kunz
    Okay, I thought you wanted to use it with 3.3V? But anyways, plug in an external power adapter to your Arduino, so doesn’t draw more current than the allowed from your USB port (500mA).

    There is no bootloader for ATtiny85 – if you look at the file it’s called “empty85at16.hex”. So it’s only necessary to change the fuse settings.

  38. Robb Kunz
    April 19th, 2012 at 01:02 | #38

    Change the fuse settings in the board.txt right?
    Tried doing that. But it doesn’t work. The fuse
    calculator generates fuse settings that are not
    consistent with the existing boards.txt. I’m not
    sure how you generate code that is consistent,
    but if you have an entry for:
    (16MHz external crystal, no BOD), I’d be the happiest
    man in Seattle (which isn’t hard).
    cheers,
    Robb

  39. Lauszus
    April 19th, 2012 at 07:33 | #39

    Here is the entry:

    attiny85at16e.name=ATtiny85 @ 16 MHz (external crystal; No BOD)

    # The following do NOT work…
    # attiny85at16e.upload.using=avrispv2
    # attiny85at16e.upload.using=Pololu USB AVR Programmer

    # The following DO work (pick one)…
    attiny85at16e.upload.using=arduino:arduinoisp
    # attiny85at16e.upload.protocol=avrispv2
    # attiny85at16e.upload.using=pololu

    attiny85at16e.upload.maximum_size=8192

    # Ext. Crystal Osc.; Frequency 8.0- MHz; Start-up time PWRDWN/RESET: 16K CK/14 CK + 65 ms; [CKSEL=1111 SUT=11]
    # Brown-out detection disabled; [BODLEVEL=111]
    # Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]
    # Serial program downloading (SPI) enabled; [SPIEN=0]

    attiny85at16e.bootloader.low_fuses=0xFF
    attiny85at16e.bootloader.high_fuses=0xD7
    attiny85at16e.bootloader.extended_fuses=0xFF
    attiny85at16e.bootloader.path=empty
    attiny85at16e.bootloader.file=empty85at16.hex

    attiny85at16e.build.mcu=attiny85
    attiny85at16e.build.f_cpu=16000000L
    attiny85at16e.build.core=tiny

  40. robb kunz
    April 20th, 2012 at 20:20 | #40

    THanks a bunch. I’ll give it a shot later today.
    I’ve been sidetracked by other work lately.

  41. robb kunz
    April 25th, 2012 at 21:43 | #41

    Finally got a chance to try this. I don’t understand why but after adding this entry to my boards.txt, it simply does not appear in my list of programming boards in Arduino. How do you know how to code this entry? The syntax of the actual entry name does not seem to follow any apparent logic. Look at these three entries:
    attiny85at16e.name=ATtiny85 @ 16 MHz (external crystal; No BOD)
    attiny85at16.name=ATtiny85 @ 16 MHz (external crystal; 2.7 V BOD)
    attiny85at16e.name=ATtiny85 @ 16 MHz (external crystal; 4.3 V BOD)

    Why do the first and third have ‘e’ in the name and not the second? This isn’t indicated in the fuse calculator. Do you follow some logic or syntax for that? I wonder why that new entry for
    BOD disabled can’t register? Totally mystifying.

  42. robb kunz
    April 25th, 2012 at 22:13 | #42

    Actually, the 2.7V BOD seems to be working for my needs. So don’t trouble over this. I’m still confused about the syntax thing but I certainly wil not lose sleep over it. THanks again!

  43. Lauszus
    April 25th, 2012 at 22:53 | #43

    @robb kunz
    Sorry, I missed that. It seems like the e indicate that it should use a external crystal and a p indicate that is must use the internal PLL.
    So it should work, but I think that you might have a problem when running it at 16MHz and then disabling the BOD, as it must run at almost 5V to run at 16MHz, so maybe you should try to use the internal oscillator at 8Mhz instead.

  44. robb kunz
    April 27th, 2012 at 22:46 | #44

    Hmm, well… it seems to be working alright. Some of the supercaps I use to keep it
    going for a few extra seconds aren’t adequate to activate the last command (pin 1 high
    for 5 seconds at 25mA sink). Anyway, I can’t use the internal oscillator. It’s terriblly
    inaccurate. That’s the whole point.

  45. Lauszus
    April 28th, 2012 at 00:15 | #45

    @robb kunz
    Have you tried to use the TinyTuner, to adjust the internal clock?
    I haven’t tried it myself, but you might be able to adjust so it is able to send ir commands.

  46. CK
    May 28th, 2012 at 06:43 | #46

    *LIKE !

  47. February 1st, 2013 at 01:30 | #47

    Hello,
    Amazing work. Thanks. Being very new to the whole arduino/AVR explosion, I was wondiering if there is a way to use your code and schematics to simply built an IR emitter using Attiny85 and a seperate IR receiver using Atting85 that would USB to a pc. Is there a way to tweak your codes and hardware to do this? Is there a way to seperate the two entities. Basically, what I want to do is make a simple device that scrolls the mouse up and down using a small ring size gadget and use IR as the communication. Would appreciate any help.

  48. February 2nd, 2013 at 13:41 | #48

    @Temoor
    Yes that should be pretty easy. Just extract the parts that receives and send the IR command into two separate programs.
    To make your ATtiny85 show up as a mouse, see the V-USB library: http://www.obdev.at/products/vusb/index.html and here is a guide to get you started: http://codeandlife.com/2012/02/22/v-usb-with-attiny45-attiny85-without-a-crystal/

  49. Matt Bedard
    April 29th, 2013 at 16:39 | #49

    Wow! Thank you so much for this post. It is nearly exactly what I’m trying to do! Only difference is I have a relay to fire a PC, and I’m using Sony codes to control a JVC receiver ๐Ÿ™‚ I should be able to modify your code pretty easily.

  50. April 29th, 2013 at 21:31 | #50

    @Matt Bedard
    You are welcome. Yes that shouldn’t be that hard to do ๐Ÿ™‚

  51. Moe
    January 3rd, 2014 at 21:25 | #51

    Just wanted to thank you for putting very good comments on your GitHub code.

  52. January 4th, 2014 at 03:57 | #52

    @Moe
    You are welcome ๐Ÿ™‚

  53. Karo Minkkinen
    March 24th, 2014 at 03:33 | #53

    Thank’s for this great article!
    Two years has passed and it’s still the most valid information for working with IR and ATTiny85.
    I’m not so skilled with coding and I’m getting gray hair trying to extract the sending part of you code. I simply have to send few (long) raw ir-codes with ATTiny85, nothing else to maximize the memory left for the other part of the application. I’m looking for to command my heat pump with this. Could you give a little help?
    Thank’s

  54. March 28th, 2014 at 00:55 | #54

    @Karo Minkkinen
    Yes of course. What typo of device is it? Have you checked that it is not already supported by the IRremote library: https://github.com/shirriff/Arduino-IRremote? If it is, then it should be much easier to implement support for it.

  55. Karo Minkkinen
    March 28th, 2014 at 21:20 | #55

    I’m having just barebones attiny85 with 16mhz crystal. Hardware is working, my ir timings are working with arduino and libraries.
    With Attiny, IRremote gave me plenty of errors that maybe could be fixed by changing the timers etc. The problem is that I’m getting lost with those libraries and I guess it’s eating more memory? Also to learn, could be better to start from naked sketch…?

  56. Jack
    March 29th, 2014 at 02:14 | #56

    First off, Thank you for your awesome code. Second I’m a little stuck on how to change your send codes from JVC to NEC. I have compared it with https://github.com/shirriff/Arduino-IRremote and am still stuck (beginner here, sorry =). Any advice to send NEC instead? -Thanks, Jack

  57. March 29th, 2014 at 12:23 | #57

    @Karo Minkkinen
    You can just use an Uno or similar to find out if your protocol is supported by the IRremote library, then it will be much easier to implement it on the ATTiny85.

    @Jack
    I guess you have already studied the decodeNEC function: https://github.com/shirriff/Arduino-IRremote/blob/master/IRremote.cpp#L454-L500?

    Here is a site that described the NEC protocol in more detail: http://www.sbprojects.com/knowledge/ir/nec.php.

  58. Karo Minkkinen
    March 30th, 2014 at 11:42 | #58

    @Lauszus
    Would be too easy…
    I have long 288 bits code sent twice with long pause between. From raw timings I can read headers, mark and spaces. From thereon I could obviously calculate binary data. But I don’t know how to send it with attiny85.
    If I could just extract that sending part of you code and use it to send raw timings or even in binary…

  59. March 31st, 2014 at 09:51 | #59

    @Karo Minkkinen
    Okay. First of all you need to read and understand these blog posts: http://www.sbprojects.com/knowledge/ir/index.php and http://www.righto.com/2009/07/secrets-of-arduino-pwm.html.
    Also please read the datasheet for the ATtiny85 starting from page 83-94: http://www.atmel.com/Images/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf.

    Then finally try to understand the sending part of the code: https://github.com/TKJElectronics/ATtinyRemote/blob/master/ATtinyRemoteVer2/ATtinyRemoteVer2.ino#L185-L209. Please note that you will properly need to modify this code to reflect your IR protocol. Also just assume that nrRepeats is 0, as it this was specific for my device.

  60. Aki
    April 5th, 2014 at 15:47 | #60

    I have been working on sending an IR single using an attiny 85 for a couple of days now and i still i haven’t come up with anything. I consider my self a beginner to this kind of stuff. I have read and tried every piece of code there is in the internet and i still can’t seem to send a single. every time a try a code i get a kind of error.

    Finally i came across your code…when i tried to upload it to my attiny it worked like a charm with no errors at all….but then i took a look at your circuit and code and couldn’t understand a thing.

    So i was wondering if it possible to make your code dead simple….like hooking up an IR to a attiny and make it send any single.

    your help will be really appreciated.
    love your work btw

  61. April 5th, 2014 at 16:35 | #61

    @Aki
    Are you looking at version 1 og version 2 of the code?
    Version 1 is a lot slower, but is also easier to understand. If that is not simple enough, then am I afraid that you need to spent some more hours studying the code ๐Ÿ˜‰

  62. Karo Minkkinen
    April 8th, 2014 at 22:27 | #62

    I red all the links you gave me, thank’s for those! Little step forward, the problem is that I should study basic coding more than else… Basically I need something like Aki was asking above:)

    Anyway I wanted to ask about that duty cycle, thing that is rarely mentioned: How can I know if it should be 1/3 or 1/4 or something else, how much it has importance?

  63. April 9th, 2014 at 00:08 | #63

    @Karo Minkkinen
    It depends on the protocol, but normally it is 1/3.
    If you got a scope you can measure it if you want.

  64. Gรผnther
    November 13th, 2014 at 20:32 | #64

    Sorry folks. While this all sounds great there is 1 thing I don’t understand (correct me if I’m wrong!) – the IRREMOTE library does not work with the ATTINY85 – if yes does that mean you or somebody else modified it?
    Even I found traces in the www that someone reportedly modified the IRREMOTE lib neither that one or the original one work (at least for me) with my ATTINY85’s – in the Arduino IDE, they wouldn’t compile. Any thoughts?

  65. November 13th, 2014 at 22:51 | #65

    @Gรผnther
    I ported it a while back: https://github.com/TKJElectronics/ATtinyRemote/blob/master/IRremote.h and https://github.com/TKJElectronics/ATtinyRemote/blob/master/IRremote.cpp, but I have removed all the protocols that I didn’t need, but it should be fairly easy to add them back.

  66. Nico
    November 14th, 2014 at 15:26 | #66

    Hi!
    I’d also like to share my very own IRL library that also can capture Panasonic protocols. The library is very lightweight and should work for attinys perfectly.

    A new update is coming this day or tomorrow with improvements and PCINT funktion to use it with an attiny. So check this out in the next few days:

    https://github.com/NicoHood/IRLremote

    ~Nico

  67. November 15th, 2014 at 00:45 | #67

    @Nico
    Thanks for sharing ๐Ÿ˜‰

  68. Nico
    November 15th, 2014 at 22:56 | #68

    It’s now working with PCINT on almost any pin. This should also work on Attinys and on the 16u2 with HoodLoader2 perfectly.

    Feedback here or via my blog appreciated ๐Ÿ™‚
    http://nicohood.wordpress.com/2014/09/20/new-lightweight-infrared-library-for-arduino/

  69. Gรผnther
    November 21st, 2014 at 19:24 | #69

    @ all: Thanks for your feedback! While I was googling for a while and couldn’t find anything I could use or I liked your replies made me really happy. Thanks again!
    I shortly tried Nico’s lib – while it seems to work with IDE 1.5.7 (at least it compiles, couldn’t test it with an Arduino) it doesn’t with IDE 1.0.6 (doesn’t compile). Will try further after Xmas when I’m back home again – but what I read is very very promising – I’m looking very much forward to a much leaner IR library than Ken Sheriff’s (credits to Ken: but it works really well!)

  70. Nico
    November 21st, 2014 at 20:21 | #70

    @ Gรผnther, someone already reported this bug. Version 1.5.8 is recommended.
    I’ll still try to fix this bug though. Thx for the note ๐Ÿ™‚

    It should now work with PCINT as well, so its very easy to use on almost any pin. Its also compatible with HoodLoader2. (usb core is online in the dev tree)!!!

    ~Nico

  1. No trackbacks yet.