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.

New Software for Analyzing IR Signals

It was my pleasure to be an Indigogo supporter and beta tester of the new software solution for analyzing infrared signals using Arduino, Raspberry Pi and other controllers. It is a Windows application called AnalysIR. Software is now available for the general public here http://www.analysir.com/blog/

One of the nicest features of this system is that it allows you to use and IR learner chip to directly decode raw IR signals rather than using a decoder bandpass filter and AGC style chip that I normally recommend for my projects. This is essential if you do not know the base frequency of an unknown protocol.

The Arduino portion of their software is freely distributable at some point I will be adding something to my IRLib library for Arduino that will allow you to do frequency analysis. But no matter what I come up with it’s not going to be as useful as this full-featured package which is now available at a reasonable price considering the effort they’ve put into it.

I’ve had many requests for output of IR signals in different formats such as ProntoHEX that I’ve not yet been able to implement in my code. However this software easily outputs that format.

I highly recommend you check out the software.

Resetting an Adafruit Trinket using an Arduino Uno

satb100Sometimes when you’re designing electronic circuit boards especially on a budget it’s easy to cut corners and only put the very bare essentials into the board. But the folks at Adafruit Industries make quality inexpensive products and they never cut corners. Case in point is there new ATtiny85 development boards the Adafruit Trinket and Adafruit Gemma. Other boards using the ATtiny85 require you to physically unplug and re-plug their boards every time you want to load a new sketch. On the other hand Adafruit included a reset button and they broke out the reset line on one of the breakout pins. For most people that’s probably not a big deal but for someone with a disability with myself, the inability to physically plug and unplug the board is a dealbreaker. Thanks to Adafruit including this reset breakout I was able to use another microcontroller namely an Arduino Uno to toggle the reset for me and allow me to use the board despite my disability. Here is a demo video I created for the weekly Adafruit Show-and-Tell.

Here is a code used on the Arduino Uno to toggle the pin 5 low for 1/10 of a second
//Sends reset signal from Arduino to
//Adafruit trinket by pulsing the reset line
//low for 1/10 of a second
int reset_pin = 5;
void setup() {
pinMode(reset_pin, OUTPUT);
digitalWrite(reset_pin, HIGH);
delay(100);
digitalWrite(reset_pin, LOW);
delay(100);
digitalWrite(reset_pin, HIGH);
}
void loop() {
}

Here is the code that you load onto the trinket so that it will blink a particular pattern. That verifies that you successfully uploaded.
//Modified trinket blink sketch
int led = 1; // blink pin 1 the built in red LED
void setup() {
pinMode(led, OUTPUT);
}
void Signal (char N,int T) {
for(int i=0;i

Here is the Adafruit Show-and-Tell from September 21, 2013 where I demonstrated this project.

Information Technology to Rescue Census Again

A recent article on the technology blog Engadget reports that the 2020 census will probably take greater advantage of the Internet rather than mailing out census forms printed on paper. The article says it’s only natural since so much of the rest of our world is forgoing “snail mail” and going to Internet-based data collection. The article says that the 2010 census cost $95 per household to process. The cost savings of using Internet should be substantial.

However this is not the first time that information technology has come to the rescue of the US Census Bureau. The census is a vital part of our government because census data is used to draw congressional districts and to allocate federal funds to various areas based on population in addition to all the other useful information it provides for city and state planners and policymakers at all levels of government.

When the country was going at a huge rate in the late 1800s the census was also vital because the population was shifting so rapidly with tens of thousands of immigrants coming in all the time and people moving to different parts of the country as we expanded westward. However the task of taking the census and tabulating the data by hand was overwhelming. It took a full eight years to tabulate the 1880 census and estimates were that the 1890 census could take as long as 11 years to tabulate. Of course by then we would already be a year overdue for the 1900 census.

The census however was rescued by Herman Hollerith. He worked for the Census Bureau and came up with an idea of using pieces of cardboard with holes punched in strategic locations to represent data. He’d gotten the idea by seeing a device called a jacquard loom. The jacquard loom would weave intricate patterns of lace and other woven materials by using a set of punched cards. Metal pins would either drop into the holes or be blocked by the absence of a hole to determine which threads should be raised or lowered as the material was woven. He concluded that we could punch holes in cards to represent different bits of data and that a machine could be built to tabulate those results electronically. Metal contacts would either drop through the holes or be blocked by the absence of a hole in it would trigger an electric counter. He designed the cards to be the size of dollar bills at that time since there were already pieces of equipment available to handle slips of paper that size.

The end result was a tabulating machine that was used in the 1890 census to tabulate it in just one year instead of the predicted 11 years. He formed a company known as the “Tabulating Machine Company” which later merged with other firms to form the “Computing Tabulating Recording Company“. That company was later renamed in 1927 to be called “International Business Machines” more commonly known by the initials IBM.

Click on the name Herman Hollerith to read the Wikipedia article giving more details about the man and his inventions and how he revolutionized data collection by using the infamous punched cards. You don’t see punched cards anymore these days but in its day, it was information technology that rescued the census.

Electronics Pun

Once upon a time there was an evil dictator of a small country. Rebel forces within the country fought for freedom of the people and repeatedly attempted to overthrow him. When he would find a village that was harboring the resistance fighters he would routinely cut off the electrical service to the village. However when that would happen, cargo planes would mysteriously appear over the villages and drop supplies to them. The parachute dropped crates contained rechargeable batteries and solar powered chargers. He ordered his army to investigate the source of these parachute drops. He suspected the American CIA or other outside forces were supporting the rebels. However his chief military advisor who happened to be a former electrical engineer reported to him that it was not outside influences but that “internal resistance was responsible for the voltage drops”.

IRLib Tutorial part 4: IR Remote Mouse

Click this logo to see my Adafruit Show-and-Tell presentation June 22, 2013

Click this logo to see my Adafruit Show-and-Tell presentation June 22, 2013

The reason I got into working with Arduino and IR remotes was to create adaptive technology for disabled people like myself. After building a specialized TV remote, the next project I tackled was to create an IR remote controlled mouse and keyboard emulator that allows me to use my IR remote to move the mouse, the arrow keys, and even type complete messages using a full keyboard.

First I would like to share with you some background as to why I created this device and then we will show you how to make a simplified version of this IR remote mouse that would be useful to anyone who uses a computer… not just someone with a disability.

My Dragon Isn’t Draggin’ Very Well

Normally I control my computer using dictation software known as Dragon NaturallySpeaking however there are some things which Dragon does not do well. Ironically a program called “Dragon” isn’t very good at draggin’ the mouse. There are mouse control commands but they are sometimes difficult to use. Also it is very difficult to use control click, shift click and (although I’ve never had to) alt click. I also have a graphics program which occasionally requires you to drag the mouse holding the right button. To my knowledge there’s no way to do that with Dragon. I also have an app on my iPod touch which allows me to wirelessly control the mouse. However it has even fewer dragging capabilities than Dragon. And there are just times when Dragon gets locked up for some reason and doesn’t work. I needed an alternative way to access my computer when something goes wrong with my usual methods. So creating an Arduino-based IR controlled mouse has been a real godsend.

Okay you’re thinking “Come on Chris isn’t it a little bit egotistical to call a device you designed a godsend?” But it really has been a blessing that such technology is available for me to create this device. When I first came up with the idea for it I was going to have to use a Arduino Uno. But it isn’t very well suited to doing mouse and keyboard emulation. You have to use an ISP to reprogram the USB controller and then you have to use an ISP to upload sketches. I had done Google searches to learn how to do it and it wasn’t going to be fun. There were some libraries available but I thought it was going to be a pretty steep learning curve about USB protocols in order to write the code to make this happen. I was still very new working with Arduino and I wasn’t looking forward to getting into something that complicated.

Arduino Leonardo

Arduino Leonardo

Leonardo to the Rescue

Finally one day I did one last Google search on “how to emulate a mouse using an Arduino” and up popped something new! A new kind of Arduino called “Arduino Leonardo“. It was designed specifically for this purpose to be able to do mouse and keyboard commands. It has all of the necessary libraries built in. I could use the device as a mouse or keyboard and I could still upload sketches directly through the USB port using the traditional Arduino IDE. It literally brought tears to my eyes when I realized that what I feared was going to be unbelievably difficult was now going to be almost trivially easy. I immediately went to the Adafruit website and ordered a brand-new Arduino Leonardo and other necessary parts to build the device shown below. Inside the box is a Leonardo, and IR receiver, and a 20 character by 4 line LCD text display and then I2C backpack for controlling the display. Here is an image of what I built and use every day.

My Leonardo-based Mouse and Keyboard Emulator

My Leonardo-based Mouse and Keyboard Emulator

Mouse Mode Display

Mouse Mode Display

The device had three modes of operation. In mouse mode you could move the mouse up, down, left, right and all 4 diagonal directions. You could left click, right-click, scroll wheel and you can also left drag or right drag. You can also toggle the control, shift, or alt keys by pushing a particular button. The display on mouse mode really didn’t tell you much except for the status of the control, shift, or alt keys and the speed at which you move the mouse. The “lr” changes to “Lr” or “lR” if you are dragging with the left or right buttons respectively. The “sca” change to uppercase if you are toggling the Shift, Control, or Alt keys respectively. The other strings of text shown on the screen are some universal keyboard commands that work in mouse or arrow modes. They are only on the screen to remind me which buttons do which functions. For example the text “Pl=^V” reminds me that the “Play” button on the remote sends a “ctrl-v” which is the same as a “Paste” function.

Arrow Mode Display

Arrow Mode Display

In arrow key mode the arrows on the TV remote don’t move the mouse, they move the arrow keys. This has been an especially useful feature for me when selecting large numbers of files in Windows Explorer. To do it with voice control I would select the first file an attempt to say the phrase “press shift down” dozens of times to select a bunch of files. If you accidentally mispronounce that phrase or if it misunderstands you it can do something completely different and you have to start over. This image shows arrow mode which again doesn’t really show you much except the status of the control, shift, alt keys and the reminders of other program keys.

Finally there is a full keyboard mode and that is the reason we needed the 20×4 character LCD display. In this mode there is a blinking cursor that you move around on the screen and when you get to the key that you wish to press you hit the select button on the remote and it types that key. It can type any key that is normally available from a standard PC keyboard including function keys and any combination of control, shift, and alt keys. This was really more of a proof-of-concept than a practical application but there have been times when everything else on my PC was locked up and I could type commands using this mode. I even plugged this device into my Raspberry Pi when doing the initial configuration although it was a bit tricky to type in the passwords before the session timed out. Here is an image of keyboard mode.

Keyboard Mode Display

Keyboard Mode Display

satb100Here is a YouTube video that I created for the weekly Adafruit Google+ Hangout Show-and-Tell where I demonstrate the various uses of my device. Unfortunately technical difficulties prevented me from showing this video on the live chat however you can see the video below and you can also click on the Show-and-Tell icon on the left to see the actual Google+ Hangout where I attempted unsuccessfully to show the video.

Sometimes Smaller is Better

Recently I purchased a new Windows 8 laptop from Dell. I knew I needed to make another IR mouse but I didn’t want something as big and bulky as a full-size Leonardo and a 20×4 character display. I really didn’t need the keyboard mode. It was more just a proof-of-concept. I really only needed mouse and arrow key mode. I thought perhaps I could get by with just a few indicator LEDs to let me know if I was dragging the mouse or if the control, alt, or shift toggles were on.

Fortunately the technology has improved yet again since I built my first mouse and keyboard emulator. There is an even smaller Arduino available known as the Arduino Micro. It was designed by our friends at Adafruit Industries. It uses the same ATmega32u4 chip that the Arduino Leonardo uses. It is essentially a miniature Leonardo and it can also be used as a mouse and keyboard emulator. Here’s what it looks like…

Arduino Micro: a mini Leonardo

Arduino Micro: a mini Leonardo

Adafruit RGB LED NeoPixels

Adafruit RGB LED NeoPixels

I still needed some sort of indicators to show me if I was holding down the shift, control, or alt and if I was dragging with the left or right mouse button. I would also need an indication if I was in mouse mode or arrow mode. This was a total of six indicators. Rather than wire up six individual multicolored LEDs complete with current limiting resistors and to take up six output pins, I decided to use two of these tiny Adafruit NeoPixel RGB LEDs. You can string dozens of them together and control them all with a single control wire. Add the +5v and ground wires and thus you only need three wires for an entire strand. The driver chip in each pixel controls the current so you don’t need to add resistors or anything. Since they are RGB I decided I can get by with just two of them. The wiring diagram below shows two of the pixels and an IR receiver wired into the back side of the Arduino Micro.

Wiring Diagram for IR Mouse

Wiring Diagram for IR Mouse

I placed a piece of double stick tape on the backside of the Micro and stuck the IR receiver and pixels onto the back of it. Arranging the parts in this particular way made it very easy to wire up the circuit. Here is an image of the completed device.

Completed Project

Completed Project

At some point I will probably cover the exposed wires with some hot glue or perhaps encase the entire device in some Sugru putty. I will need to maintain access to the six pins on the front side in case I ever want to rewrite the boot loader and access to the reset button might be necessary.

This new miniaturized person of my IR mouse not only helps me with my computer in light of my disability but it could be a useful gadget for anyone to use. Although you can purchase IR mouse controllers from a variety of sources, it’s always more fun to build your own and you can custom program in additional features not available in the commercially available products. For example if you are controlling a PowerPoint presentation on a projection monitor you might want to be free to move around the room while talking and using a small IR remote to click on the next image or do various other functions.

You can use any IR remote control such as a TV, DVD etc. to control the mouse as long as it uses a protocol that IRLib can understand. For this tutorial we are going to use a mini remote from Adafruit. It has 21 buttons and uses the NEC protocol. It’s small pocket-sized would make it ideal for controlling a PowerPoint presentation. Here is what the remote looks like

Adafruit Mini Remote

Adafruit Mini Remote

Programming the Commands

That takes care of the hardware. Now we need to write some software. We have 21 buttons available on this remote. Obviously we want to assign the mouse directions to the four arrow buttons. The four buttons diagonally from these arrows are an obvious choice for moving the mouse diagonally. And in arrow mode those corner buttons are obviously a good choice to assign the Home, End, Page Up, and Page Down functions. Among the other mouse functions are left and right click, left and right drag, faster or slower mouse movements, and scroll wheel up and down. Other arrow mode functions will include Backspace, Space, Escape, Tab, and a GUI key such as the Windows key. You can modify the program to put any command in any of these slots. This is just a suggestion.

Several of the buttons operate identically in either mouse or arrow mode. The top row of buttons toggle the Alt, Control, and Shift keys. The “Mode” button toggles between mouse mode and arrow mode. The “Release” button releases all held mouse buttons and toggle keys. Here is a graphic which shows which of the buttons on the remote performed which functions in either mouse mode or arrow mode.

Assigning Commands to Buttons

Assigning Commands to Buttons

One of the RGB pixels will show red, green, or blue if the Alt, Control, or Shift toggles are on. The other pixel shows blue when the left mouse button is dragging and read when the right mouse button is dragging. It shows green when you are in arrow mode.

The NEC protocol we are using sends a special code of 0xffffffff as a repeat code whenever you hold down a button. In order to process this we will always store any received codes so when we receive the repeat code we know what function to repeat. However the toggle keys should not be repeated without lifting off of the button so we have zeroed out the previous code when pressing one of those toggles.

Here is a complete listing of the code.
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.1 April 2013 by Chris Young http://tech.cyborg5.com
* "IRmouse" Control a PCs mouse or arrow keys using an IR remote
*/
#include
#include
#include
//The IR codes shown below are for the Adafruit mini remote
//which uses an easy protocol. The comments after each code refer to the buttons
//on that remote and not to their actual function on this device.

//Codes used by both mouse and arrow modes
#define CodeAlt 0xfd00ff //Vol-
#define CodeCtrl 0xfd807f //Play/Pause
#define CodeShift 0xfd40bf //Vol+
#define CodeRls 0xfda857 //5
#define CodeMode 0xfd9867 //8

//Used by mouse and arrow but have different meanings
#define CodeUp 0xfda05f //Up arrow
#define CodeDown 0xfdb04f //Down arrow
#define CodeLeft 0xfd10ef //Left arrow
#define CodeRight 0xfd50af //Right arrow

//Used only in mouse mode
#define CodeUpLf 0xfd20df //Set up
#define CodeUpRt 0xfd609f //Stop/mode
#define CodeLfClk 0xfd906f //Enter/save
#define CodeDnLf 0xfd30cf //0 10+
#define CodeDnRt 0xfd708f //Repeat
#define CodeLfDrag 0xfd08f7 //1
#define CodeRtDrag 0xfd8877 //2
#define CodeRtClk 0xfd48b7 //3
#define CodeFaster 0xfd28d7 //4
#define CodeScrUp 0xfd6897 //6
#define CodeSlower 0xfd18e7 //7
#define CodeScrDn 0xfd58a7 //9

//Arrow mode only
#define CodeHome 0xfd20df //Set up
#define CodePgUp 0xfd609f //Stop/mode
#define CodeEnter 0xfd906f //Enter/save
#define CodeEnd 0xfd30cf //0 10+
#define CodePgDn 0xfd708f //Repeat
#define CodeGUI 0xfd08f7 //1
#define CodeInsert 0xfd8877 //2
#define CodeDelete 0xfd48b7 //3
#define CodeBkSp 0xfd28d7 //4
#define CodeSpace 0xfd6897 //6
#define CodeEsc 0xfd18e7 //7
#define CodeTab 0xfd58a7 //9

#define Bright 16 //brightness of pixels

#define MOUSE_MODE 0
#define ARROW_MODE 1
#define MAX_MODE (ARROW_MODE+1)

#define MOUSE_LED 0
#define SHIFT_LED 1

Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, 6, NEO_GRB + NEO_KHZ800);//Output pin 6
IRrecv My_Receiver(11); //Input pin 11
IRdecodeNEC My_Decoder;

int Speed;
int Current_Mode;
char Control_State;
char Shift_State;
char Alt_State;
long Previous;
uint32_t Shift_Status, Mouse_Status;

void UpdateStatus () {
Mouse_Status=0;
Shift_Status=0;
strip.setPixelColor(MOUSE_LED,Bright*Mouse.isPressed(MOUSE_LEFT),Bright*Current_Mode,Bright*Mouse.isPressed(MOUSE_RIGHT));
strip.setPixelColor(SHIFT_LED,Bright*Alt_State,Bright*Control_State,Bright*Shift_State);
strip.show();
};
//This Change_Mode routine is overly complex but it's a holdover from earlier code
//where I had three modes instead of two. Note we do not want to repeat feature
//on this function or on the toggle functions so we set Previous=0
void Change_Mode () {
Current_Mode=(++Current_Mode) % MAX_MODE;
Previous=0; UpdateStatus(); delay(500);
};

void setup() {
strip.begin(); strip.show();
Shift_Status=0; Mouse_Status=0;
My_Receiver.enableIRIn(); // Start the receiver
Current_Mode=0;
Control_State=0; Shift_State=0; Alt_State=0;
Speed=8; Previous=0; UpdateStatus();
Mouse.begin();
}

void Toggle_Mouse(int Button) {
if(Mouse.isPressed(Button)) Mouse.release(Button);
else Mouse.press(Button);
Previous=0; UpdateStatus(); delay(500);
}

void Mouse_Mode() {
switch (My_Decoder.value) {
case CodeLeft: Mouse.move(-Speed,0,0); break;
case CodeRight: Mouse.move( Speed,0,0); break;
case CodeUp: Mouse.move(0,-Speed,0); break;
case CodeDown: Mouse.move(0, Speed,0); break;
case CodeUpRt: Mouse.move( Speed,-Speed,0); break;
case CodeUpLf: Mouse.move(-Speed,-Speed,0); break;
case CodeDnLf: Mouse.move(-Speed, Speed,0); break;
case CodeDnRt: Mouse.move( Speed, Speed,0); break;
case CodeLfClk: Mouse.release(MOUSE_LEFT); Mouse.click(MOUSE_LEFT); delay(400);break;
case CodeRtClk: Mouse.release(MOUSE_RIGHT); Mouse.click(MOUSE_RIGHT); delay(400);break;
case CodeLfDrag: Toggle_Mouse(MOUSE_LEFT); break;
case CodeRtDrag: Toggle_Mouse(MOUSE_RIGHT); break;
case CodeFaster: Speed=min(30,++Speed); delay(100); break;
case CodeSlower: Speed=max(1,--Speed); delay(100); break;
case CodeScrUp: Mouse.move(0,0,1); delay(100); break;
case CodeScrDn: Mouse.move(0,0,-1); delay(100); break;
};
};

void Toggle_Key(char *Toggle,char Key) {
if(*Toggle){
Keyboard.release(Key); *Toggle=0;
}
else{
Keyboard.press(Key); *Toggle=1;
};
Previous=0; UpdateStatus(); delay(500);
};
//Releases all held mouse buttons and toggle keys
void Release_All() {
Keyboard.releaseAll();
Mouse.release(MOUSE_LEFT); Mouse.release(MOUSE_RIGHT); Mouse.release(MOUSE_MIDDLE);
Alt_State=0; Control_State=0; Shift_State=0;
UpdateStatus();
};
//In my experience some keys work better if you put a little extra delay.
void Key_Press (char Key,int D) {
Keyboard.write(Key); delay(150+D);
}

void Arrow_Mode() {
switch (My_Decoder.value) {
case CodeLeft: Key_Press(KEY_LEFT_ARROW,0); break;
case CodeRight: Key_Press(KEY_RIGHT_ARROW,0); break;
case CodeUp: Key_Press(KEY_UP_ARROW,0); break;
case CodeDown: Key_Press(KEY_DOWN_ARROW,0); break;
case CodeInsert: Key_Press(KEY_INSERT,0); break;
case CodeEnter: Key_Press(KEY_RETURN,100); break;
case CodeBkSp: Key_Press(KEY_BACKSPACE,100); break;
case CodePgUp: Key_Press(KEY_PAGE_UP,200); break;
case CodePgDn: Key_Press(KEY_PAGE_DOWN,200); break;
case CodeHome: Key_Press(KEY_HOME,0); break;
case CodeEnd: Key_Press(KEY_END,0); break;
case CodeGUI: Key_Press(KEY_LEFT_GUI, 100); break;
case CodeSpace: Key_Press(32, 100); break;//ASCII space
case CodeEsc: Key_Press(KEY_ESC, 100); break;
case CodeTab: Key_Press(KEY_TAB, 100); break;
};
};
/*
//You can uncomment and use this routine to send control characters such as
//control-z for an undo button or control-c for copy etc.
void Send_Control(char Key,int D) {
Release_All(); Keyboard.press(KEY_LEFT_CTRL);
Keyboard.write(Key); Release_All();delay(150+D); Update ();
}
*/
void loop() {
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
//Adafruit remote uses NEC protocol which sends a special repeat code
//if you are holding down the same button. We store each received code
//in "Previous" so that we can properly handle repeat codes.
if(My_Decoder.value==0xffffffff)
My_Decoder.value=Previous;
else
Previous=My_Decoder.value;
switch(Current_Mode) {
case MOUSE_MODE: Mouse_Mode(); break;
case ARROW_MODE: Arrow_Mode(); break;
}
switch (My_Decoder.value) {
case CodeMode: Change_Mode(); break;
case CodeAlt: Toggle_Key(&Alt_State,KEY_LEFT_ALT); break;
case CodeShift: Toggle_Key(&Shift_State,KEY_LEFT_SHIFT); break;
case CodeCtrl: Toggle_Key(&Control_State,KEY_LEFT_CTRL); break;
case CodeRls: Release_All(); break;
};
My_Receiver.resume();
}
}

For reference purposes here’s a link to the documentation on the keyboard and mouse libraries for use with Leonardo or other comparable Arduinos.
http://arduino.cc/en/Reference/MouseKeyboard

You will also need the special library for Adafruit RGB NeoPixels which can be downloaded from GitHub.
https://github.com/adafruit/Adafruit_NeoPixel

Simply download and unzip the library into your library folder.

Note that the latest Arduino IDE (version 1.0.5 as I write this) lists the Arduino Micro as one of the boards it supports. When using either the Leonardo or Micro you will need a special driver for Windows computers. This driver is available in the driver’s library of the latest Arduino IDE. The latest drivers combine drivers for all of the supported boards into a single Windows 8 compatible signs package.

Simply plug the Arduino Micro into the USB port, upload the sketch, and then point your remote at the receiver. The device initializes into mouse mode so you should be able to move the mouse around using the arrow keys. Try switching to arrow mode using the “Mode” button. Go back to mouse mode and try pressing the faster or slower buttons. You won’t notice anything while pressing them however subsequent mouse movements will be faster or slower.

Here are links to the hardware mentioned in this tutorial:

Here are links to hardware used in the original IR mouse and keyboard emulator. At some point I will clean up the code on that project and publish it. If you have an immediate use for such a device, feel free to contact me and I will give you what I have but for now it’s not really fit for public consumption.

IRLib Tutorial part 3: Overview Sending IR Codes

Part 3 of this tutorial is so big we have spread it over 4 installments. This blog post is just to pull all of those post together in a single location.

Part 3a: Sending IR Codes
In this segment we create a small Arduino sketch that allows you to type IR codes into the serial monitor and have them transmitted by your IR LED.

satb100Part 3b: Creating a Virtual Remote Using Python
In the segment we use a Python script on a PC or Raspberry Pi to communicate over the serial port with the Arduino. By clicking on the virtual buttons on the PC, the Python script transmits the codes to the Arduino which in turn translates into your device by your IR LED.

Part 3c: Python, PySerial and PyGame Installation on Windows
Because Python and the other tools for creating the Virtual Remote may not be on your system, we have included this extra tutorial on how to install the necessary software on a Windows PC. While it isn’t technically connected to IRLib, we thought it would be useful to a variety of people not just users of our library.

Part 3d: Installing the Arduino IDE on a Raspberry Pi
Again this is not strictly related to IRLib but if you want to run the Part 3b example on a Raspberry Pi you will need to install the Arduino IDE. General users of Arduino and Raspberry Pi might be interested in this even if they do not use our libraries. If you do not use a Raspberry Pi then you do not need this part of the tutorial.

IRLib Tutorial part 3d: Installing the Arduino IDE on a Raspberry Pi

As we mentioned in part 3c, this section of the tutorial doesn’t have anything to do with IRLib specifically, however if you have not already installed the software necessary to run the tutorial part 3b then you will have to follow these instructions. In this section we will install the Arduino IDE on a Raspberry Pi. If you’re not using Raspberry Pi as a host machine but are using Windows like we did in part 3c then you do not need this tutorial at all.

Note: This article has only been tested with Arduino IDE version 1.0.x and not with the beta version 1.5.x. We cannot guarantee these procedures will work with the new version which may have a totally different structure since it is a fairly big upgrade.

We are assuming that you are using a plain vanilla Raspbian Wheezy OS on your Raspberry Pi. We cannot guarantee any of these instructions will work on other versions of the operating system. We are also assuming that your Raspberry Pi has Internet access for downloading updates. If your Raspberry Pi is not connected to the Internet you’ll have to figure out how to get the necessary files onto your system by an alternate means.

Raspbian Wheezy is actually a version of Debian Linux and according to the following reference http://playground.arduino.cc/Linux/Debian the Arduino IDE has already been prepackaged for easy installation. Go to a command prompt and type the following command
sudo apt-get install arduino
Breaking this command down for those of you who may not be familiar with Linux commands… The “sudo” stands for “Super User Do”. Access to the root directory and installation on your machine requires superuser privileges. This command temporarily gives you those privileges. And what are you going to do with them? You’re going to run the “apt-get” command. This is a system already set up in most Linux distributions to get various programs from a central repository. And the command that we passed this program is “install arduino”. I take the time to explain all of that because when I was new to Linux and didn’t know what I was doing, I would ask a question on the support forum and they would give me some obscure line of text type and I had absolutely no idea what I was doing or why.

This process not only installs the necessary Arduino components it also installs and/or updates various Java components necessary to run the Arduino IDE. If you do not have Internet access and did not use the “apt-get” command to install the package but simply copied the programs over to your Raspberry Pi, then you do not have the full package. The process of getting those additional Java packages is beyond the scope of this tutorial.

When the installation is completed most of the software is installed in the folder “/usr/share/arduino” and the folders inside that include “hardware”, “lib”, “libraries”, and “tools”. There is also an alias for the “examples” and “reference” folders however these folders are actually stored in “/usr/share/doc/arduino-core/”.

Also upon completion you will discover that your GUI start menu now has a new folder and it called “Electronics” which contains a link to the Arduino IDE as seen here.
startmenu
If you would like a shortstop on your desktop, the easiest way to do it is to collect up on the start but do not actually click on it. Instead do a right-click and there will be an opportunity to “Add to desktop” as seen here.
add2desktop
You now have an Arduino IDE shortcut on your desktop. For future reference your desktop icon is at /usr/share/pixmaps/arduino.xpm
icon
If you double-click on the desktop icon on select it from the start menu the Arduino IDE the first thing you will want to check is the version number. As of this writing the pre-packaged version of Arduino was only at version 1.0.1 however the most recent version was 1.0.4 which among other things added support for other Arduino boards such as the Arduino Esplora and Arduino Micro. If the above installation process did not get you the latest version then you will have to manually updated yourself. We successfully used the procedure below to update from 1.0.1 up to 1.0.4 and a week or so later ran the process again to get up to 1.0.5.

We’re going to assume you are starting out in a directory called “/home/pi” where “pi” is your username. If you’re logged in under a different username that will be different naturally. We recommend that you create a directory for downloading programs. At the command prompt type
mkdir downloads
Which obviously makes a directory called “downloads”. Then type…
cd downloads
Which changes your current directory to the downloads directory or folder. Then you should type the following command
wget http://arduino.googlecode.com/files/arduino-1.0.5-linux32.tgz
The “wget” command gets a file from the web. If you are installing something newer than 1.0.5 you will have to change the filename. If you are uncertain of the filename, call up a web browser in your computer and go to http://arduino.cc/en/Main/Software and then right-click on the 32-bit Linux link and copy shortcut. Then paste that text somewhere so that you can see the proper filename for the most recent version.

We will now use the “tar” utility to unzip the archive that we have downloaded. Issue the following command.
tar zxvf arduino-1.0.5-linux32.tgz
This will create a folder under your downloads folder called “arduino-1.0.5”. Then change to that folder with this command.
cd arduino-1.0.5
We now want to get rid of the “hardware/tools” folder inside the unzipped distribution. That is because the version that we have downloaded is compiled for an Intel x86 or AMD x86 processor and not the ARM chip that is in your Raspberry Pi. We will use the “rm” command to “remove” that folder.
rm -rf hardware/tools
Now we will copy using “cp” to copy the other files into their proper locations. We will go through the subfolders and overwrite any existing files.
cp -ru lib /usr/share/arduino
cp -ru libraries /usr/share/arduino
cp -ru tools /usr/share/arduino
cp -ru hardware /usr/share/arduino
cp -ru examples /usr/share/doc/arduino-core
cp -ru reference /usr/share/doc/arduino-core

Note some readers of this blog have reported that they needed to pre-append “sudo” to these commands above. If you are having difficulty with these commands you should try using “sudo cp -ru… etc.” instead.
Now if you launch the Arduino IDE you will see that the version has been updated. In this image we had only updated it to 1.0.4 but you can see it does have the additional boards that were missing from the 1.0.1 installation.
boards
One last item… If you were doing this in order to run the IRLib tutorial part 3b on your Raspberry Pi then you will also need Python, PySerial, and Pygame. Fortunately Python and Pygame are already installed on your system. Be sure to use the Python 2 and not Python 3. You will however have to install the PySerial module with the following command.
sudo apt-get install python-serial
That should be all you need.

IRLib Tutorial part 3c: Python, PySerial and PyGame Installation on Windows

Although technically this installment of our tutorial isn’t directly related to IRLib, we are including it here as part 3c because it may be necessary to do these steps if you want to use the example in part 3b of our tutorials.

We’re going to take you step-by-step through installing Python and other necessary modules on a Windows system. We used this method on a Windows 7 64-bit home premium PC. Other versions of Windows will have extremely similar installations.

In order to use the previous examples, we highly recommend that you use Python 2 rather than Python 3 and we recommend that you use the 32-bit version even if you are on a 64-bit Windows machine. You might be able to get our examples to work under 64 bits or Python 3 but we were warned there might be problems and we did encounter them and chose not to try to come up with workarounds.

 Installing the Python Interpreter

Python is an interpreted language rather than a compiled language. The Python interpreter is a program that runs on your PC, reads the text script of your Python program and executes the script rather than compiling it into native machine language for your type of hardware. You can download the Windows version of Python 2 or 3 at…

http://www.python.org/download/releases/

As of this writing the most recent version of Python 2 is 2.7.5 dated May 15, 2013. Download the file named “Windows x86 MSI Installer (2.7.5) (sig)” you can save the program and run it from the same location or run it immediately.

01 downloadInstall the program for all users.

02 all usersChoose your directory. The default will work.03 directory

The default for customization is install everything. That will work fine.

04 customize

And complete the installation

04 finishWhen you completed the installation the following items will be in your start menu.

06 start menuThere is a command line version that can run scripts directly or there is an IDE called “IDLE”. In our previous installment of the tutorial we use the IDE.

There is one more item we need to do to complete this installation. We need to add the Python interpreter to the default system path so that when you try to execute a Python script it will know where to find the interpreter. The process is slightly different on Windows XP versus Windows Vista, 7, or 8.

 Adjusting the path on Windows Vista, 7, or 8…

Go to your Control Panel and click on “System”. If you are in icon view you can click on “System” directly. If you are in category view you should click on “System and Security” and then click on “System”. You should next click on “Change Settings” as shown here

07 change settingsYou will get a system properties dialog that looks like this. You should click on the “Advanced” tab.

08 system propertiesNext click on environment variables.

09 advancedYou’ll get the Environment Variables dialog which looks like this.

In the upper section look for the item “Path”. Select it and click on “Edit” just below it.

11 pathThen very carefully go to the end of the variable value and add a semicolon followed by the path where you installed Python. Make sure do not erase any other text that was previously there. On my system I added “;C:\Python22” to the end of the value. Then click on okay and continue out of all of the open dialogues. You can now proceed to the next section where we will install pySerial.

Adjusting the path on Windows XP

Go to your Control Panel and click on “System”. If you are in classic icon view you can click on “System” directly. If you are in category view you should click on “Performance and Maintenance” and then click on “System”. Unlike later versions of Windows, this will take you directly to the “System Properties” dialog. You do not need to click on any “Change Settings” link. It will look like this…

08 system properties XPClick on the tab labeled “Advanced” and it will look like this

09 advanced XPClick on the “Environment Variables” button and you will see the following dialogue.

10 environment variables XPIn the lower section look for the item “Path”. Select it and click on “Edit” just below it.

11 path XPThen very carefully go to the end of the variable value and add a semicolon followed by the path where you installed Python. Make sure you do not erase any other text that was previously there. On my system I added “;C:\Python22” to the end of the value. Then click on okay and continue out of all of the open dialogues. You can now proceed to the next section where we will install pySerial.

Installing PySerial

Next we will install the PySerial module which will allow us to do serial communication through Python. The main page for the PySerial code is…

http://pyserial.sourceforge.net/

Click on the “Download Page” link as shown here
20 pySerialAt click on the big green download button. Save the file to a convenient location. Note that the version “2.6” refers to the pySerial version and not to the version of Python which you are running.

21 downloadUnzip the file. If you do not have a utility that can handle .tar.gz compressed files we recommend using “7 Zip” which can be downloaded here…

http://www.7-zip.org/

Now we will have to do something that Windows users rarely do. We need to type some command lines to install the package. Click on your start button and choose the “run” command and then type “cmd”.
22 run command
23 run dialog cmd

Or alternatively you may have a command prompt shortcut in your start menu under accessories as shown here.
24 command prompt

When the command line window comes up you need to change directories to where you unzipped the pySerial package. In my case it was in the c:\downloads\pyserial-2.6 so the command was…

cd c:\downloads\pyserial- 2.6

Then type the following command…

python setup.py install

25 set up install

When the installation is complete type “exit”
26 exit

 Instructions for Installing Pygame

Our final step is to install the Pygame package. You can download it at

http://www.pygame.org/

Click on the download link in the upper left menu

30 pygame

Scroll down to the section for windows and click on the link labeled “pygame-1.9.1.win32-py2.7.msi”
31 download

Or whatever the most recent 32-bit Windows installer link is. Simply run the installer and use all of the default settings to complete installation.

That’s everything you need to know to install Python, PySerial and Pygame on a Windows machine.

If you are using a Raspberry Pi you will already have Python and Pygame installed with the standard version of Raspbian. To install PySerial simply go to a command prompt and type

sudo apt-get install python-serial

This tells it to issue a superuser command to get the package and install it. In the next installment of this tutorial we will talk about how to install the Arduino IDE on a Raspberry Pi.