I use my Arduino as a remote control for my PC. It has a IR Receiver connected, it decodes the RC5 protocol and sends a character through the serial port.
My Arduino uses a FT232RL chip.
It works perfectly, except for the fact that after a long period of time(sometimes 30min, sometimes 3hours), it simply stops sending data through the serial port.
It continues to receive and decode the signals from the IR remote, but no longer sends them through the serial port. (the FT232RL "TX" LED no longer lights up).
This looks like a Windows driver problem to me.
Sometimes, disconnecting and reconnecting the USB cable fixes the problem, but many times, I can't even shut down the computer and have to reset it.
I have Windows 7 x64, and Virtual Com Port driver 2.8.17. (I have tested 2.08.14 and it behaves the same).
Has anyone experienced anything like this before?
Thank you in advance.
Here is my code just in case you need it.
int ir_pin = 2; //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13;
int debug_pin = 11; //"Ready to Recieve" flag, not needed but nice
int debug = 0; //Serial connection must be started to debug
int start_bit = 2000; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)
int data[12];
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(debug_pin, OUTPUT);
pinMode(ir_pin, INPUT);
digitalWrite(led_pin, HIGH);
digitalWrite(debug_pin, HIGH);
delay(100);
digitalWrite(led_pin, LOW);
digitalWrite(debug_pin, LOW);
delay(150);
digitalWrite(led_pin, HIGH);
digitalWrite(debug_pin, HIGH);
delay(100);
digitalWrite(led_pin, LOW);
digitalWrite(debug_pin, LOW);
delay(150);
digitalWrite(led_pin, HIGH);
digitalWrite(debug_pin, HIGH);
delay(100);
digitalWrite(led_pin, LOW);
digitalWrite(debug_pin, LOW);
Serial.begin(9600);
}
void loop() {
int key;
while(1)
{
key = getIRKey(); //Fetch the key
// Serial.print("Key Recieved: "+ key);
if (key > 0)
{
//Serial.println(key);
Serial.print(char(key));
}
else
{
digitalWrite(debug_pin, HIGH);
}
}
}
int getIRKey() {
digitalWrite(led_pin, LOW); //Ok, i'm ready to recieve
digitalWrite(debug_pin, LOW);
while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
}
digitalWrite(led_pin, HIGH);
data[0] = pulseIn(ir_pin, LOW); //Start measuring bits, I only want low pulses
data[1] = pulseIn(ir_pin, LOW);
data[2] = pulseIn(ir_pin, LOW);
data[3] = pulseIn(ir_pin, LOW);
data[4] = pulseIn(ir_pin, LOW);
data[5] = pulseIn(ir_pin, LOW);
data[6] = pulseIn(ir_pin, LOW);
data[7] = pulseIn(ir_pin, LOW);
data[8] = pulseIn(ir_pin, LOW);
data[9] = pulseIn(ir_pin, LOW);
data[10] = pulseIn(ir_pin, LOW);
data[11] = pulseIn(ir_pin, LOW);
if(debug == 1) {
Serial.println("-----");
}
for(int i=0;i<11;i++) { //Parse them
if (debug == 1) {
Serial.print(i);
Serial.print(":");
Serial.println(data[i]);
}
if(data[i] > bin_1) { //is it a 1?
data[i] = 1;
} else {
if(data[i] > bin_0) { //is it a 0?
data[i] = 0;
} else {
data[i] = 2; //Flag the data as invalid; I don't know what it is!
}
}
}
for(int i=0;i<11;i++) { //Pre-check data for errors
if(data[i] > 1) {
return -1; //Return -1 on invalid data
}
}
int result = 0;
int seed = 1;
for(int i=0;i<11;i++) { //Convert bits to integer
if(data[i] == 1) {
result += seed;
}
seed = seed * 2;
}
return result; //Return key number
}