Pin conflict using two libraries?

I’m using IRremote and Tlc5940 libraries in my sketch below. Examples for these two libraries have need for the use of pin 3. I’ve looked through the libraries trying to spot a line where that could be changed in one or the other but didn’t come up with anything that looked like it could be changed to another pin. How can this be accomplished? Also, is it just coincidence that they both utilize pin 3 or does it perhaps have something to do with clocking? - Scotty

P.S. The line #define PIN_IR 2 //output to IR transmitter
was previously #define PIN_IR 3 //output to IR transmitter
Having the IR transmitter on pin 2 was working for the sensor part of this project. I changed it to pin to to free up pin 3 for the Tlc5940. Changing the IR transmitter to pin 2 caused the IR receiver not to function.

Code:

/*
 TLC5940 demonstration sketch
 John Boxall - http://tronixstuff.com/partreviews - 17 July 2010
 uses code and library by Alex Leone 
 <acleone ~AT~ gmail.com>, 2009-02-03 
 TLC5940 library falls under GPLv3 license - see http://www.gnu.org/licenses/
 */
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Warning //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////// You need external power for your Arduino board - USB is not enough!!/////////////
///////////// TLC5940 + 16 LEDs draw over 300 mA at full brightness! ///////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

#include <IRremote.h>
#include "Tlc5940.h"

#define PIN_IR 2 //output to IR transmitter
#define PIN_IR_DETECT 4 //tied to output of IR detector
#define PIN_IR_STATUS 6 //IR LED indicator
#define PIN_PIR_DETECT 5 //tied to output of PIR detector
#define PIN_PIR_STATUS 7 //PIR LED indicator
#define LDR_PIN A3
boolean IR_Status;
boolean PIR_Status;
int LDR_Value;
boolean Night_Status;

void setup()

{
  Serial.begin(9600);
  /* Call Tlc.init() to setup the tlc.
   You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
  Tlc.init();
}

void loop(){

  IR_Status = digitalRead(PIN_IR_DETECT);
  LDR_Value = analogRead(LDR_PIN);
  PIR_Status = digitalRead(PIN_PIR_DETECT);
  Serial.print ("PIN_IR_DETECT =  ");
  Serial.print (IR_Status);
  Serial.print ("    PIN_PIR_DETECT =  ");
  Serial.print (PIR_Status);
  Serial.print ("     LDR Value = ");
  Serial.println(LDR_Value);
  if (LDR_Value >700){
    Night_Status = false;
    Serial.print ("It is daytime. No sensors monitored.  ");
    Serial.print ("LDR Value = ");
    Serial.println(LDR_Value);
  }
  else{
    Serial.println("It is nightime. Sensors are monitored.  ");
    Serial.print ("LDR Value = ");
    Serial.println(LDR_Value);
  }

  if (IR_Status){
    digitalWrite(PIN_IR_STATUS,HIGH);
    Serial.println(" IR BEAM BROKEN ");
  }
  else{
    digitalWrite(PIN_IR_STATUS,LOW);
  }

  if (PIR_Status){
    digitalWrite(PIN_PIR_STATUS,HIGH);
    Serial.println(" PIR DETECTION");
  }
  else{
    digitalWrite(PIN_PIR_STATUS,LOW);
  }

 /* if(Night_Status == false &&(IR_Status || PIR_Status)){
    Tlc.clear();
for (int l=0; l<10; l++){
for (int p=0; p<4096; p+=10){ // increase brightness
Tlc.set(l, p);
Tlc.update();
      delay(5);
}
}
  }
}
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Warning //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////// You need external power for your Arduino board - USB is not enough!!/////////////
///////////// TLC5940 + 16 LEDs draw over 300 mA at full brightness! ///////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

Where in your code do you reference PIN_IR? Nowhere that I can see.

My apologies. Screwed up merging sketches. Corrected code is below. I think the output pin 3 for the transmitter is decided in the library. I suppose in that case it doesn’t do me any good to reference it at all in the sketch. - Scotty

/*
 TLC5940 demonstration sketch
 John Boxall - http://tronixstuff.com/partreviews - 17 July 2010
 uses code and library by Alex Leone 
 <acleone ~AT~ gmail.com>, 2009-02-03 
 TLC5940 library falls under GPLv3 license - see http://www.gnu.org/licenses/
 */
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Warning //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////// You need external power for your Arduino board - USB is not enough!!/////////////
///////////// TLC5940 + 16 LEDs draw over 300 mA at full brightness! ///////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

#include <IRremote.h>
#include "Tlc5940.h"

#define PIN_IR 2 //output to IR transmitter
#define PIN_IR_DETECT 4 //tied to output of IR detector
#define PIN_IR_STATUS 6 //IR LED indicator
#define PIN_PIR_DETECT 5 //tied to output of PIR detector
#define PIN_PIR_STATUS 7 //PIR LED indicator
#define LDR_PIN A3
boolean IR_Status;
boolean PIR_Status;
int LDR_Value;
boolean Night_Status;
IRsend irsend;

void setup()
{
  Serial.begin(9600);
  /* Call Tlc.init() to setup the tlc.
   You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
  Tlc.init();
  pinMode(PIN_IR_DETECT, INPUT);
  pinMode(PIN_IR_STATUS, OUTPUT);
  pinMode(PIN_PIR_DETECT, INPUT);
  pinMode(PIN_PIR_STATUS, OUTPUT);
  irsend.enableIROut(38);
  irsend.mark(0);
}

void loop(){

  IR_Status = digitalRead(PIN_IR_DETECT);
  LDR_Value = analogRead(LDR_PIN);
  PIR_Status = digitalRead(PIN_PIR_DETECT);
  Serial.print ("PIN_IR_DETECT =  ");
  Serial.print (IR_Status);
  Serial.print ("    PIN_PIR_DETECT =  ");
  Serial.print (PIR_Status);
  Serial.print ("     LDR Value = ");
  Serial.println(LDR_Value);
  if (LDR_Value >700){
    Night_Status = false;
    Serial.print ("It is daytime. No sensors monitored.  ");
    Serial.print ("LDR Value = ");
    Serial.println(LDR_Value);
  }
  else{
    Serial.println("It is nightime. Sensors are monitored.  ");
    Serial.print ("LDR Value = ");
    Serial.println(LDR_Value);
  }

  if (IR_Status){
    digitalWrite(PIN_IR_STATUS,HIGH);
    Serial.println(" IR BEAM BROKEN ");
  }
  else{
    digitalWrite(PIN_IR_STATUS,LOW);
  }

  if (PIR_Status){
    digitalWrite(PIN_PIR_STATUS,HIGH);
    Serial.println(" PIR DETECTION");
  }
  else{
    digitalWrite(PIN_PIR_STATUS,LOW);
  }
  delay(1000);

  /* if(Night_Status == false &&(IR_Status || PIR_Status)){
   Tlc.clear();
   for (int l=0; l<10; l++){
   for (int p=0; p<4096; p+=10){ // increase brightness
   Tlc.set(l, p);
   Tlc.update();
   delay(5);
   }
   }
   }*/
}
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// Warning //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////// You need external power for your Arduino board - USB is not enough!!/////////////
///////////// TLC5940 + 16 LEDs draw over 300 mA at full brightness! ///////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////

IRremoteInt.h defines which timer to use, and therefore which pin the transmitter is on. The choices for the Duemilanove (which I have) are pins 3 (timer 2) (the default) or 9 (timer 1).

Be aware that using timer 1 affects a number of other things.

I don't know which pins the TLC library uses, or which timers, if any. I don't know if pin 9 is free for you to switch to, or if doing so will mess anything else up.

Thanks for the direction. I think I see it now:

// Arduino Mega

if defined(AVR_ATmega1280)

//#define IR_USE_TIMER1 // tx = pin 11

define IR_USE_TIMER2 // tx = pin 9

//#define IR_USE_TIMER3 // tx = pin 5 //#define IR_USE_TIMER4 // tx = pin 6 //#define IR_USE_TIMER5 // tx = pin 46

// Teensy 1.0

elif defined(AVR_AT90USB162)

define IR_USE_TIMER1 // tx = pin 17

// Teensy 2.0

elif defined(AVR_ATmega32U4)

//#define IR_USE_TIMER1 // tx = pin 14 //#define IR_USE_TIMER3 // tx = pin 9

define IR_USE_TIMER4_HS // tx = pin 10

// Teensy++ 1.0 & 2.0

elif defined(AVR_AT90USB646) || defined(AVR_AT90USB1286)

//#define IR_USE_TIMER1 // tx = pin 25

define IR_USE_TIMER2 // tx = pin 1

//#define IR_USE_TIMER3 // tx = pin 16

// Sanguino

elif defined(AVR_ATmega644P) || defined(AVR_ATmega644)

//#define IR_USE_TIMER1 // tx = pin 13

define IR_USE_TIMER2 // tx = pin 14

// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, etc

else

//#define IR_USE_TIMER1 // tx = pin 9

define IR_USE_TIMER2 // tx = pin 3

endif

Also found this:

Timer1: Timer1 is a 16bit timer. In the Arduino world the Servo library uses timer1 on Arduino Uno (timer5 on Arduino Mega).

Timer2: Timer2 is a 8bit timer like timer0. In the Arduino work the tone() function uses timer2.

This project is for controlling A Tlc5940 based on the conditions of three sensors. That's all it does. My plan is to switch the commented and uncommented lines and try that.

  • Scotty