IR send and receive using Shirriff library

Status
Not open for further replies.

DJ Namaste

Active member
Hello, using Ken Shirriff's irremote library, I want to send data using a remote to one teensy and have it relay that same code to another teensy. So one relays to the other the same value. I have a sketch that is set up to send and receive the data The IR emitter is connected to pin 5 on teensy, the ir receiver is on pin 6.

The original emitter sketch example does not define the emitter pin and requires pin 3 on arduino uno. On teensy it requires pin 5 according to the website. Any guidance?

PHP:
#include <IRremote.h>

IRsend irsend;
const int RECV_PIN = 6;
const int pinSendIR = 5;
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}


void loop() {
   if (irrecv.decode(&results)) {
    irsend.sendSony(0x68B92, 20);
    delay(100);
    irsend.sendSony(0x68B92, 20);
    delay(100);
    irsend.sendSony(0x68B92, 20);
    delay(300);
        Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}
 
Okay, this code is sending ir data from one teensy to the other teensy.
Now instead of a NEC code, I want to send a random number generated from the sending board to the receiving board so they each get the same random number. How can you send a data value over IR?

PHP:
#include <IRremote.h>

IRsend irsend;
const int RECV_PIN = 6;
//const int SEND_IR = 5;
IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}


void loop() {
// irsend.sendNEC(3898168033, 20);
//   delay(1000);
   irsend.sendNEC(2026743005, 32);
delay(1000);

  if (irrecv.decode(&results)) {
//  irsend.sendSony(0x9D52009D, 10);
//  delay(100);
//    irsend.sendSony(0x68B92, 20);
//    delay(100);
//    irsend.sendSony(0x68B92, 20);
//    delay(3000);
        Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
 }
 //irrecv.resume(); // Receive the next value
}
 
Last edited:
Normal process would be to bitwise OR(|) a indicator and your random digits together so something like:

uint32_t typeKey = 0x6A000000; //indicator
float randomval = random(); //value between 0 and 1;
randomval=randomval*0x00FFFFFF; //scales up to 6 bytes
uint32_t sendValue = floor(randomval); //round down to whole number
sendValue = sendValue|typeKey; //should get 6 random bytes with the typekey as header
irsend.sendNEC(sendValue,32);

If you need more bits then you use different typeKey values and reassembly at the far end, You can change the size of your key based on how many actual bits you need. A four byte key will give lots of possible codes but not a lot of sendable bits, or you could just send 32 random bits and hope you can re-assemble at the far end.

If more reliability is needed you start adding checksums, either as bits to each message, or as a final message.
 
I'm kind of following you but don't quite understand some of it. I've found in other discussions that say you cant generate and send new data using send.raw as it requires a defined value stored in memory.

So if I want to generate a random number between 0-200 by one teensy and to receive that number on the next teensy, how can I send it? Using nec codes I can send and receive. But when I try to send a specific number not in nec code it results in various numbers. I understand you are explaining how to structure the way nec code sends and receives bits but I don't know if it will work for this purpose. I'm still learning and trying to piece it together.
 
If you are only sending 200 different values then things are a bit simpler. Sounds like the library is doing some shenanigans with constants. Not having the hardware setup, if you do

irsend.sendNEC(2026743005, 32);
delay(1000);
irsend.sendNEC(2026743006, 32);
delay(1000);

uint32_t sendVal = 2026743005; //indicator
irsend.sendNEC(sendVal, 32);
delay(1000)
sendVal++;
irsend.sendNEC(sendVal, 32);
delay(10000)

What actual values do you get spat out at the far end? if the recived value isn't the same but is different by one then do a program that does a while loop adding 1 each time and see if the resulting values also go up by one. It's not actually critical that the numbers at each end match, as long as the value out of the receive code are the same each time you send a given input value, and are in some form of pattern.

If you just want to get things done, with 200 possible values it would be doable to either cut and paste by hand or use something like Excel to produce 200 IF statements and have everything hard coded.
 
Status
Not open for further replies.
Back
Top