IRLib Updated to Version 1.3

A new version of IRLib is now available on GitHub at
https://github.com/cyborg5/IRLib/

Down three IRLib is a library of code for Arduino-based microcontrollers that facilitates sending, receiving, decoding and analyzing infrared remote signals. Here is an overview of the changes.

  • NEW FILES

    • Added new file IRLibRData.h and moved irparams structure and related items to that file. Allows users to create custom IRrecv classes
  • NEW EXAMPLES
    • Rewrote Samsung36 example to include both send and receive
    • Added new examples for new protocols DirecTV and GIcable
    • Added new example IRanalyze gives more detailed analysis of timing. Useful in analyzing the protocols
    • Added new example IRfreq reports modulation frequency of a signal. Requires TSMP58000 IR learner chip
    • Cleanup of other example routines.
  • NEW CLASSES
    • Created IRrecvBase class to allow custom receiver classes. IRrecv is now a derived class from it.
    • Created IRrecvLoop class which receives IR signals without using any hardware interrupts or timers. Also created IRrecvPCI class which uses Pin Change Interrupts to receive IR signals. These new receivers are more accurate than the 50µs timing of the original IRrecv. However they also have other limitations described in comments.
  • NEW FUNCTIONS, VARIABLES AND METHODS
    • In IRrecvBase added “unsigned char Mark_Excess” with default value 100. Was a define macro but now is user settable.
    • In IRrecvBase added method “unsigned char getPinNum(void);” which retrieves the pin number used from irparams.recvpin. This value not normally accessible to end user.
    • Globally available function “void do_Blink(void);” blinks pin 13 LED. For use by user created extensions of IRrecvBase.
  • INTERNAL CHANGES
    • Data collected by IRrecvBase classes in irparams.rawbuf is now converted to actual microseconds rather than clock ticks of 50 µs each. IRrecvBase::GetResults has a new parameter “Time_per_Ticks” that is used to convert ticks into actual microseconds if needed.
    • Adjustments to mark and space to deal with overreporting and underreporting of intervals is now done once in IRrecvBase::GetResults eliminating the need for MATCH_MARK(d,v) and MATCH_SPACE(d,v). Just use MATCH(d,v) everywhere.
    • Modified IRLibsendBase::mark() and IRLibsendBase::space() to overcome limitations of “delayMicroseconds()”.
    • Changed many int to char or unsigned char to save memory
    • Eliminated DEBUG macro in IRLib.h and its use elsewhere. Macro TRACE is more useful.
    • Changed IRTYPES to unsigned char and a list of #defines rather than an enum (even though I still really like enums, changing it saves memory)
  • MEMORY EFFICIENCY
    • Code changes result in memory savings of approximately 54 bytes in code space and 39 bytes of RAM.

    For more information see my IRLib page.

Programmable Christmas Lights Using Arduino and Neopixels

satb100I have a little Christmas tree that I put up in my office every year that I call my “Charlie Brown tree”. It’s a scrawny looking little artificial tree with a little white Christmas balls on it and a strand of cheap flights. This year I decided to fancy it up a little bit by adding a 3 meter strand of Adafruit neopixels containing 90 pixels. I started out with the standard strand test sketch that is available from Adafruit and then modified it to add my own special patterns. I showed it on a recent Adafruit Saturday night Show-and-Tell Google+ video chat. There were a number of other Christmas displays shown that night but people seem to especially like my candy stripe pattern.

One viewer liked it so much he wrote me and asked me for the candy stripe code. He then incorporated it into his outdoor display and showed it in a subsequent Show-and-Tell a few weeks later. I had always intended to write a blog post about it and to include the code but I got so busy over the holidays that I didn’t have time to clean up the code and make it suitable for public sharing. The holidays are over and I’m finally getting around to sharing the code.

Here is a YouTube video showing a slightly earlier version of the pattern.

Here is the Adafruit Show-and-Tell on Google+ where I showed off the tree and my blinking Christmas card.

Here is the Show-and-Tell of the other guy named Kenneth who borrowed my candy stripe code. His display used a full 10 meters of pixels. Unfortunately there were bad audio problems that evening but I will put the video here anyway. His segment starts at about six minutes into the video.

Here are some links to the products used in this project. All were purchased from Adafruit.com

Now finally here is the code edited for public consumption with comments.

#include <Adafruit_NeoPixel.h>

#define Count 12
#define Pin 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Count,Pin,NEO_GRB + NEO_KHZ800);

#define Brightness 10 //Set brightness to 1/10th
#define Full (255/Brightness)
//Create scrolling red and white candy cane stripes.
//Try adjusting the width in pixels for various results.
//Value "sets" should evenly divide into strand length
void CandyCane  (int sets,int width,int wait) {
  int L;
  for(int j=0;j<(sets*width);j++) {
    for(int i=0;i< strip.numPixels();i++) {
      L=strip.numPixels()-i-1;
      if ( ((i+j) % (width*2) )<width)
        strip.setPixelColor(L,Full,0,0);
      else
        strip.setPixelColor(L,Full,Full, Full);
    };
    strip.show();
    delay(wait);
  };
};

//Create sets of random white or gray pixels
void RandomWhite (int sets, int wait) {
  int V,i,j;
  for (i=0;i<sets;i++) {
    for(j=0;j<strip.numPixels();j++) {
      V=random(Full);
      strip.setPixelColor(j,V,V,V);
    }
    strip.show();
    delay(wait);
  }
};
//Create sets of random colors
void RandomColor (int sets, int wait) {
  int i,j;
  for (i=0;i<sets;i++) {
    for(j=0;j<strip.numPixels();j++) {
      strip.setPixelColor(j,random(255)/Brightness,random(255)/Brightness,random(255)/Brightness);
    }
    strip.show();
    delay(wait);
  }
};
void RainbowStripe (int sets,int width,int wait) {
  int L;
  for(int j=0;j<(sets*width*6);j++) {
    for(int i=0;i< strip.numPixels();i++) {
      L=strip.numPixels()-i-1;
      switch ( ( (i+j)/width) % 6 ) {
        case 0: strip.setPixelColor(L,Full,0,0);break;//Red
        case 1: strip.setPixelColor(L,Full,Full,0);break;//Yellow
        case 2: strip.setPixelColor(L,0,Full,0);break;//Green
        case 3: strip.setPixelColor(L,0,Full,Full);break;//Cyan
        case 4: strip.setPixelColor(L,0,0,Full);break;//Blue
        case 5: strip.setPixelColor(L,Full,0,Full);break;//Magenta
//        default: strip.setPixelColor(L,0,0,0);//Use for debugging only
      }
    };
    strip.show();
    delay(wait);
  };
};
//These routines were modified from Adafruit strand test sketch
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void rainbowCycle(uint8_t sets, uint8_t wait) {
  uint16_t i, j;
  for(j=0; j<256*sets; j++) { //cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(strip.numPixels()-i-1, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color((WheelPos * 3)/Brightness, (255 - WheelPos * 3)/Brightness, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color((255 - WheelPos * 3)/Brightness, 0, (WheelPos * 3)/Brightness);
  } else {
   WheelPos -= 170;
   return strip.Color(0,(WheelPos * 3)/Brightness, (255 - WheelPos * 3)/Brightness);
  }
}

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  randomSeed(1234);//Set up random number generator
}

void loop() {
  CandyCane(30,8,50);//30 sets, 8 pixels wide, 50us delay
  RainbowStripe(5,4,75);//5 cycles, 4 pixels wide, 50 delay
  RandomWhite(50,200);//50 sets of random grayscale
  RandomColor(50,200);//50 sets of random colors
  colorWipe(strip.Color(Full, 0, 0), 50); // Red
  colorWipe(strip.Color(Full, Full, 0), 50); // Yellow
  colorWipe(strip.Color(0, Full, 0), 50); // Green
  colorWipe(strip.Color(0, Full, Full), 50); // Cyan
  colorWipe(strip.Color(0, 0, Full), 50); // Blue
  colorWipe(strip.Color(Full, 0, Full), 50); // Magenta
  rainbowCycle(10,2);//10 rainbow cycles
  colorWipe(0,5);//Black
}

Hope you find this code useful. Have a very Merry Christmas and a blessed new year.

Constant Current IR Driver Circuit

Our friends at AnalysIR who make Windows software to assist in decoding IR signals have come up with a nice schematic for a constant current IR LED driver circuit that we thought would be of interest to our users here. Here is a link to their blog post describing the circuit. We’ve not tested it out here yet but we have seen similar schematics and we trust these guys to do it right anyway. Their explanation of the circuit is outstanding.

  • AnalysIR blog post on constant current IR LED driver


They also have many other interesting articles in their blog and they have a user forum with lots of interesting information and exchange of ideas between users.