Chris Roberts
Published © GPL3+

IR LaunchPad to LaunchPad Communication

Send text from one LaunchPad to another using the Grove IR emitter and receiver!

IntermediateFull instructions provided2 hours3,043
IR LaunchPad to LaunchPad Communication

Things used in this project

Story

Read more

Code

IRSendSerial

C/C++
Uploaded to the 5529 to read Serial input and emit it over IR.
#include <IRSendRev.h>
#define pb1 PUSH1 
#define BIT_LEN         0
#define BIT_START_H     1
#define BIT_START_L     2
#define BIT_DATA_H      3
#define BIT_DATA_L      4
#define BIT_DATA_LEN    5
#define BIT_DATA        6
 
const int ir_freq = 38;                 // 38k
IRSendRev IR;
unsigned char dtaSend[40];
String buffer;
 
void setup()
{
    IR.setSend(40);
    Serial.begin(115200);
}
 
void loop()
{
  if (Serial.available()){
    buffer = "";
    while(Serial.available()>0){
      buffer += char(Serial.read());
    }
    dtaSend[BIT_DATA_LEN] = buffer.length();
    int i;
    for(i = 0; i<buffer.length();i++){
      dtaSend[BIT_DATA+i] = buffer[i];
    }
    IR.Send(dtaSend, 38);
  }
    delay(100);
}

IRRecvSerial

C/C++
Code uploaded to the 6989 to receive ASCII codes over IR and print them on the built in LCD display.
#include <LCD_Launchpad.h>

#include <IRSendRev.h>
 
#define BIT_LEN         0
#define BIT_START_H     1
#define BIT_START_L     2
#define BIT_DATA_H      3
#define BIT_DATA_L      4
#define BIT_DATA_LEN    5
#define BIT_DATA        6

const int pinRecv = 5;              // ir receiver connect to D2
IRSendRev IR; 
boolean state = 0;
LCD_LAUNCHPAD LCD;
char buffer[40]; 
int dta[40];

void setup()
{
    Serial.begin(115200);
    IR.Init(pinRecv);
    LCD.init();
}

 
void loop()
{
  if(IR.IsDta())                  // get IR data
  {
    IR.Recv(dta);               // receive data to dta
    int i;
    for (i = 0;i<dta[BIT_DATA_LEN];i++){
      buffer[i] =  char(dta[BIT_DATA+i]);
    }
    buffer[i] = '\0';
    LCD.displayScrollText(buffer,400);
  }
}

IRGrove

C/C++
Library used to enable IR communication
No preview (download only).

Credits

Chris Roberts

Chris Roberts

8 projects • 21 followers
I am an applications engineer with Texas Instruments working with the Launchpad by trade, and a maker by passion!

Comments