Wish IRremote library

atiaust

Active Member
Licensed User
Longtime User
Hi All,

I have been playing with the KEYES IRremote control for Arduino.

This works extremely well and would be good to be able to use it with B4R.
Attached are the libraries that I have tested.

Anyone able to create the wrappers for B4R to use the basic functions as in the IRremote.ino attached.

Thanks..
 

Attachments

  • IRremote.jpg
    IRremote.jpg
    136.5 KB · Views: 534
  • IRremote.zip
    13.8 KB · Views: 352

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
1. Copy the three library files to rCore folder in the internal libraries folder.
2. Run this code:

B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private lastRead As UInt 'ignore
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("enableIRIn", Null)
   AddLooper("Looper1")
End Sub

Sub Looper1
   If Millis > lastRead + 500 Then
     Dim res As UInt = RunNative("read", Null)
     If res > 0 Then
       Log("Received: ", res)
     End If
   End If
End Sub


#if C
#include "IRremote.h"
IRrecv irrecv(11); //signal pin. Change as needed
decode_results results;
B4R::Object res;
void enableIRIn(B4R::Object* o) {
   irrecv.enableIRIn();
}
B4R::Object* read(B4R::Object* o) {
   ULong result = 0;
   if (irrecv.decode(&results)) {
     irrecv.resume();
     b4r_main::_lastread = millis();
     result = results.value;
   }
   return res.wrapNumber(result);
}
#end if
 

atiaust

Active Member
Licensed User
Longtime User
Hi Erel,

That works just fine.

Just added a sub to convert the return value to the key description.

Thanks
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks for this example. It shows very well how to use Inline C. Confirmed working fine.
Added select statement in the looper to check which key been pressed, to then turn the internal LED (ledPin assigned to pin 13) on as an example of acting on key pressed.
B4X:
Select res
  'Remote Control Key 1 = 12495
  Case 12495
    Log("Remote Control Key 1 pressed")
    ledPin.DigitalWrite(True)
  'Remote Control Key 2 = 6375
  Case 6375
    Log("Remote Control Key 2 pressed")
    ledPin.DigitalWrite(False)
  'Remote Control Key 3 = 31365
  Case 31365
     Log("Remote Control Key 3 pressed")
  'ADD MORE...
End Select
 
Last edited:

inakigarm

Well-Known Member
Licensed User
Longtime User
One question: Any hint on how to adapt this code for passing the input pin to inline C# code IRrecv??

PD:
As for the image I have exactly the same IR Keyes sensor but the codes 1,2,3 represents 3,4,5 keys on mine IR remote ...??o_O (changed to my values but it's a bit strange)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example that calls IRsend.sendSony:
B4X:
Sub Process_Globals
  Public Serial1 As Serial
  Private lastRead As UInt 'ignore
  Private mData As ULong 'ignore
  Private mNbits As Int 'ignore
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("enableIRIn", Null)
   AddLooper("Looper1")
   SendSony(2323, 4)
End Sub

Sub SendSony (data As ULong, nbits As Int)
   mData = data
   mNbits = nbits
   RunNative("sendSony", Null)
End Sub


Sub Looper1
  If Millis > lastRead + 500 Then
  Dim res As UInt = RunNative("read", Null)
  If res > 0 Then
  Log("Received: ", res)
  End If
  End If
End Sub


#if C
#include "IRremote.h"
IRrecv irrecv(11); //signal pin. Change as needed
IRsend irsend;
decode_results results;
B4R::Object res;
void enableIRIn(B4R::Object* o) {
  irrecv.enableIRIn();
}
B4R::Object* read(B4R::Object* o) {
  ULong result = 0;
  if (irrecv.decode(&results)) {
  irrecv.resume();
  b4r_main::_lastread = millis();
  result = results.value;
  }
  return res.wrapNumber(result);
}
void sendSony (B4R::Object* o) {
   irsend.sendSony(b4r_main::_mdata, b4r_main::_mnbits);
}
#end if
You can easily modify it to send to other types.
 

derez

Expert
Licensed User
Longtime User
The library specifies that the output pin for the IR led is pin 3.
 

derez

Expert
Licensed User
Longtime User
The recording is OK and I get for the TV on-off signal 4335, but sending it does not work.
I tried both SendSony and SendNEC.
The code I use :
B4X:
Sub Process_Globals
  Public Serial1 As Serial
  Private lastRead As UInt 'ignore
  Private mData As ULong 'ignore
  Private mNbits As Int 'ignore
  Private pin8 As Pin
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("enableIRIn", Null)
   AddLooper("Looper1")
   pin8.Initialize(8,pin8.MODE_INPUT_PULLUP)

    pin8.AddListener("Button")
End Sub

Sub SendSony (data As ULong, nbits As Int)
   mData = data
   mNbits = nbits
   RunNative("sendSony", Null)
End Sub

Sub SendNEC (data As ULong, nbits As Int)
   mData = data
   mNbits = nbits
   RunNative("sendNEC", Null)
Log("sent nec")
End Sub


Sub Looper1

  If Millis > lastRead + 500 Then
      Dim res As UInt = RunNative("read", Null)
      If res > 0 Then
          Log("Received: ", res)
      End If
  End If

End Sub

Sub Button(State As Boolean)
    If State Then
        SendNEC(4335,4) ' I don't understand the meaning of the nbits (4) , tried other numbers also.
        'SendNEC(0x20DF10EF,20)
    End If
End Sub


#if C
#include "IRremote.h"
IRrecv irrecv(5); //signal pin. Change as needed
IRsend irsend;
decode_results results;
B4R::Object res;
void enableIRIn(B4R::Object* o) {
  irrecv.enableIRIn();
}
B4R::Object* read(B4R::Object* o) {
  ULong result = 0;
  if (irrecv.decode(&results)) {
  irrecv.resume();
  b4r_main::_lastread = millis();
  result = results.value;
  }
  return res.wrapNumber(result);
}

void sendSony (B4R::Object* o) {
   irsend.sendSony(b4r_main::_mdata, b4r_main::_mnbits);
}

void sendNEC(B4R::Object* o) {
    irsend.sendNEC(b4r_main::_mdata, b4r_main::_mnbits);
}
#end if

I am successful with arduino sketches that use IRlib, one records the signal (0x20DF10EF) and the other sends it.
B4X:
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3   January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
#include <IRLib.h>

IRsend My_Sender;

void setup()
{
  Serial.begin(9600);
  pinMode(8,INPUT);
}

void loop() {
  if (digitalRead(8) == HIGH) {
    //send the code  when the button is pressed
    //tv
    My_Sender.send(NEC,0x20DF10EF, 20);
  }
}
The decoding sketch and the library are attached.
 

Attachments

  • recorder.ino.zip
    1.9 KB · Views: 333
  • IRlib.zip
    18.3 KB · Views: 405
Last edited:

derez

Expert
Licensed User
Longtime User
Sensor TSOP 1736, the LED for sending is IR led, looks like a normal led but clear color.
 
Top