VS838 IR receiver led anyone got it working with mys?



  • Hi,

    I can get the sample IRrecord working, so it is not HW issue. But when I add my mys code I get no output in the serial monitor. Here is my code just I case I made some huge error 😉

    /*
      M-BED-LED 5V pro mini + 3.3V for nrf
    
      D9,10,11,12,13 - nrf24
      D3 IR LED Tx
      D4 LED (not used).
      D8 IR LED Rx
      D7 Sound module for alarm (TBA)
      A4 Data  BH1750
      A5 Clk   BH1750
    */
    
    #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    #define MY_RF24_PA_LEVEL   RF24_PA_LOW
    #define MY_NODE_ID 25
    #define MY_RF24_CHANNEL (97)
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    //#define MY_REPEATER_FEATURE
    //#define MY_SIGNING_ATSHA204
    //#define MY_SIGNING_REQUEST_SIGNATURES
    #define CHILD_ID_IR 0
    #define CHILD_ID_IRRX 1
    #define CHILD_ID_AUTO_LIGHTS 2
    #define CHILD_ID_LUX 3
    #define CHILD_ID_COLOUR 4
    #define CHILD_ID_LIGHTS 5
    #define CHILD_ID_SOUND 6
    #define CHILD_ID_SOUND_ARMED 7
    
    int Auto_lights = 1;
    int last_Auto_lights = 0;
    int newcodeRX = 1;               // alert to new message from controller.
    #include <IRremote.h>
    IRsend irsend;
    #include <avr\wdt.h>
    #include <MySensors.h>
    #include <BH1750.h>
    #include <Wire.h>
    
    int RECV_PIN = 6;
    IRrecv irrecv(RECV_PIN);
    decode_results results;
    
    #define LED_ON 0xFFA25D
    #define LED_OFF 0xFFE21D
    #define LED_RED 0xFF6897
    #define LED_WHITE 0xFF52AD
    #define LED_LUX- 0xFF906F
    #define LED_LUX+ 0xFFA857
    
    
    unsigned int lightlevel = 10;
    unsigned int lightrequest = 0;
    unsigned long IRrxvalue = 0;
    unsigned long code = 0x12345678; //dummy fill
    unsigned int lights = 0;
    unsigned int last_lights = 0;
    unsigned long loop_time = 300000;
    unsigned long last_loop_time = 0;
    unsigned int LAST_SOUND_Armed = 0;
    unsigned int SOUND_Armed = 0;
    unsigned int Sound = 0;
    
    
    BH1750 LightMeter;
    
    MyMessage msgCode(CHILD_ID_IR, V_IR_SEND);
    MyMessage msgIRrxvalue(CHILD_ID_IRRX, V_IR_RECEIVE);
    MyMessage msgAuto_Lights(CHILD_ID_AUTO_LIGHTS, V_STATUS);
    MyMessage msgLux(CHILD_ID_LUX, V_LEVEL);
    MyMessage msgColout(CHILD_ID_COLOUR, V_RGBW);
    MyMessage msgLights(CHILD_ID_LIGHTS, V_STATUS);
    MyMessage msgSound(CHILD_ID_SOUND, V_TRIPPED);
    MyMessage msgSOUND_Armed(CHILD_ID_SOUND_ARMED, V_ARMED);
    
    void setup()
    {
      irrecv.enableIRIn(); // Start the receiver
      LightMeter.begin();
      lights = loadState(10);
      SOUND_Armed = loadState(4);
      if (lights == 1) {
        code = 0xFFA25D;
      }
      else if (lights == 0) {
        code = 0xFFE21D;
      }
      wdt_enable(WDTO_8S);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("MYS-M-Bed-LED", "0.2");
      wait(100);
    
      present(CHILD_ID_IR, S_IR, "IR Send");
      wait(100);
      present(CHILD_ID_IRRX, S_IR, "IR Receive");
      wait(100);
      present(CHILD_ID_AUTO_LIGHTS, S_BINARY, "Auto Lights");
      wait(100);
      present(CHILD_ID_LUX , S_LIGHT_LEVEL, "LUX");
      wait(100);
      present(CHILD_ID_COLOUR , S_RGBW_LIGHT, "Colour");
      wait(100);
      present(CHILD_ID_LIGHTS , S_BINARY, "Lights");
      wait(100);
      present(CHILD_ID_SOUND , S_DOOR, "Alarm");
      wait(100);
      present(CHILD_ID_SOUND_ARMED , S_BINARY, "Armed");
      wait(100);
      send(msgAuto_Lights.set(Auto_lights));
    
    }
    
    
    void loop() {
    
      wdt_reset();
    
      if (newcodeRX == 1 || lightrequest == 1) {
        irsend.sendNEC(code, 32);
        if (code == 0xFFA25D) {
          lights = 1;
        }
    
        if (code == 0xFFE21D) {
          lights = 0;
        }
    
        if (lights != last_lights) {
          saveState(10, lights);
          send(msgLights.set(lights));
          last_lights = lights;
        }
    
        newcodeRX = 0;
        lightrequest = 0;
        wait(10);
      }
    
      if (irrecv.decode(&results)) {
        Serial.print(results.value, HEX);
      //  IRrxvalue = (results.value, HEX);
      //  Serial.println(IRrxvalue);
        /*
          switch (IRrxvalue) {
          case LED_ON
          lights = 1;
          sendMsg.....
          saveState();......
          break;
    
          case LED_OFF
          lights = 0;
          break;
    
          case LED_RED
          break;
    
          case LED_WHITE
          break;
    
          case LED_LUX-
          break;
    
          case LED_LUX+
          break;
        */
    
        irrecv.resume(); // Receive the next value
        delay(100);
      }
    
      if (LAST_SOUND_Armed != SOUND_Armed) {
        saveState(4, SOUND_Armed);
        LAST_SOUND_Armed = SOUND_Armed;
      }
      //Add send alarm on tripped for sound sensor.....Sound = int0 interrupt.......
      if (Sound >= 50 && SOUND_Armed == 1) {
        send(msgSound.set(1));
      }
    
      if (millis() - last_loop_time >= loop_time) {
        last_loop_time = millis();
        lightlevel = LightMeter.readLightLevel();
        send(msgLux.set(lightlevel));
        if (lightlevel <= 6 && Auto_lights == 1) {
          lightrequest = 1;
          code = LED_ON;
        }
        /*
          else if (lightlevel >= 40 && Auto_lights == 1) {
          lightrequest = 1;
          code = LED_OFF;
          }*/
      }
    }
    
    // process incoming message
    void receive(const MyMessage &message) {
    
      if (message.type == V_IR_SEND) {
        code = strtoul(message.getString(), NULL, 0);
        newcodeRX = 1;
      }
    
      if (message.sensor == CHILD_ID_AUTO_LIGHTS) {
        Auto_lights = (message.getInt());
      }
      // Add sound sensor arm and alert here....
    
      if (message.type == V_ARMED) {
        if (message.sensor == CHILD_ID_SOUND_ARMED) {
          SOUND_Armed = message.getInt();
        }
      }
    }
    

    So with only the IR code I can see the IR hex codes being received, but not when I use the 'full' code above and I am darned if I can work out why? A fresh pair of eyes might help me see the light (no pun intended) 😉



  • Is the baudrate set correctly?
    Default is 115200



  • @electrik Baud rate is OK for mysensors as I see the initial presentation sequence, but I don't see anything in the serial monitor when pressing a button on the remote with the above code. If I just use the remote code without all the mysensors/ights lines then it works, but the baud rate is then 9600.
    I tried adding Serial.begin(9600) to setup, but that didn't cure the issue.
    Maybe I need to set 9600 in mysensors.h and try again. There's a big storm lashing us here at the moment, so I won't be going out today!



  • Ah okay
    So perhaps one of the devices you add in setup cause it to stop there.
    For example the lightmeter
    We have the same storm I think 😉


  • Mod



  • @electrik Pretty windy to say the least! I have not had time to look into this today as I had hoped....soon I hope.

    @Yveaux Yes, that is the one. It is a simple example that works on it's own and yet when added to the mys sketch it seems to not detect presses of the IR remote. Maybe a conflict somewhere?


  • Mod

    @skywatch What Arduino and hardware connection are you using?

    The sketch suggests "5V pro mini" and IR receiver connected to D8 (?) but sketch defines RECV_PIN = 6...

    Also, you could try connecting a LED to a free PWM output pin and pass this pin as second parameter to "IRrecv irrecv(RECV_PIN, LED_PIN);" (ref https://github.com/z3t0/Arduino-IRremote/blob/master/irRecv.cpp#L110) so the LED flashes when data comes in.



  • @Yveaux Thanks for the assistance- I am using 5V pro-mini and it works as a stand alone with the IRremote example with IR Rx LED on D6. I tried D8 and D6 but same results (in the demo it is pin 11 and that would conflict with the nrf pins). I have D4 for data if needed already in the sketch (but no led as it won't be needed).

    I have tried without the lightmeter BH1750 and still the same results. I also tried with MYS Debug commented out and still the same.

    After your post I tried....

    int blinkpin = 4;
    int RECV_PIN = 6;
    IRrecv irrecv(RECV_PIN,blinkpin);
    

    No output to the serial monitor - I will try again tomorrow when I have (hopefully) had a good nights sleep!



  • I just noticed a 'delay(100);' in the code above. It shouldn't be there, so will change it to 'wait(100);' and see if that was the problem - A new day a new try!

    Well that wasn't the issue and I successfully combined the IRreceive and BH1750 sketches and all worked as expected. So something is happening when MySendors is involved, the question is what? - I'll continue to think on this and see what else I can think to try.



  • @skywatch
    What is your memory usage?



  • @electrik At compilation I get the following....

    Sketch uses 21718 bytes (70%) of program storage space. Maximum is 30720 bytes.
    Global variables use 1207 bytes (58%) of dynamic memory, leaving 841 bytes for local variables. Maximum is 2048 bytes.
    
    

    It looks OK to me, but I have been wrong before (and will be again, probably quite soon ) ; ).

    I have 2 other nodes that will also require IR Tx/Rx between them so will try and build them this weekend and see if I get the same issue.



  • You could also add debug prints at specific points so you find out where the code still runs.

    edit To me the memory looks fine. Only if use a lot of stack it could give trouble, but it seems enough space is available



  • @electrik It seems that the IR if statement is never actioned.

    I added

    Serial.println("Enabling IRin");
      irrecv.enableIRIn(); // Start the receiver
      Serial.println("Enabled IRin");
    

    To setup and that seems to be OK....

    121 !MCO:SND:NODE NOT REG
    1123 MCO:REG:REQ
    1126 TSF:MSG:SEND,25-25-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    1133 TSF:MSG:READ,0-0-25,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    1138 MCO:PIM:NODE REG=1
    1140 MCO:BGN:STP
    Enabling IRin
    Enabled IRin
    1153 MCO:BGN:INIT OK,TSP=1
    1227 TSF:MSG:SEND,25-25-0-0,s=5,c=1,t=2,pt=3,l=2,sg=0,ft=0,st=OK:1
    

    But for some reason I can't find, it never executes the receive If code.
    Also tried input pins D2.4,6,8 and all show the same lack of doing what they should!
    Very strange!


  • Mod

    @skywatch I found some time to rebuild your setup:
    Arduino UNO, nRF24 default connection no IRQ, TSOP1738 connected to D6, Arduino IDE 1.8.10

    Tested first with IRRecord sketch, same pinning, working fine.

    Absolute bare minimum sketch, containing MySensors (2.3.2) and IR Receiver using the same library (current version):

    #define MY_DEBUG
    
    #define MY_BAUD_RATE (57600)
    #define MY_RADIO_RF24
    
    #define MY_RF24_CE_PIN              (9)
    #define MY_RF24_CS_PIN              (10)
    
    #define MY_NODE_ID                  (254)
    #define MY_PARENT_NODE_ID           (0)
    #define MY_PARENT_NODE_IS_STATIC
    
    #include <Arduino.h>
    #include <IRremote.h>
    #include <MySensors.h>
    
    const int RECV_PIN = 6;
    IRrecv irrecv(RECV_PIN);
    
    void presentation()
    {
        Serial.println(F("-- Init MySensors"));
        sendSketchInfo(F("IRSensor"), F("1.0"));
    }
    
    void setup()
    {
        irrecv.enableIRIn();
    }
    
    void loop()
    {
        decode_results results;
        if (irrecv.decode(&results))
        {
            for (int i = 0; i < results.rawlen - 1; ++i)
            {
                Serial.print(results.rawbuf[i], DEC);
            }
            Serial.println();
            irrecv.resume();
        }
    }
    

    Added basic MySensors sketch, same pinning working fine:

    33 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=255,VER=2.3.2
    54 TSM:INIT
    56 TSF:WUR:MS=0
    64 TSM:INIT:TSP OK
    67 TSM:INIT:STATID=254
    72 TSF:SID:OK,ID=254
    75 TSM:FPAR
    77 TSM:FPAR:STATP=0
    81 TSM:ID
    82 TSM:ID:OK
    86 TSM:UPL
    89 TSF:MSG:SEND,254-254-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    101 TSF:MSG:READ,0-0-254,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    110 TSF:MSG:PONG RECV,HP=1
    115 TSM:UPL:OK
    118 TSM:READY:ID=254,PAR=0,DIS=1
    124 TSF:MSG:SEND,254-254-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    138 TSF:MSG:READ,0-0-254,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    149 TSF:MSG:SEND,254-254-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
    163 TSF:MSG:SEND,254-254-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    -- Init MySensors
    2177 TSF:MSG:SEND,254-254-0-0,s=255,c=3,t=11,pt=0,l=8,sg=0,ft=0,st=OK:IRSensor
    2193 TSF:MSG:SEND,254-254-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
    2205 MCO:REG:REQ
    2209 TSF:MSG:SEND,254-254-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2223 TSF:MSG:READ,0-0-254,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2232 MCO:PIM:NODE REG=1
    2237 MCO:BGN:STP
    2240 MCO:BGN:INIT OK,TSP=1
    142892861371371371371371227137128137137137128128128128128128712271326132712812271326137132712812812713713713713271281227122713271227
    113792861371371371371281326137137137137137128128128128128128712271327122712812271327127132712812812812812812713271281227132613271227
    113692861371371371371371327127137137137137137137137128128128713261327122713713261327128122713712812812812812812271281227132712271227
    113692871281271371371371327128127137137137137137137137137128713261327122713713261327128122712813713712812812812271371326132712271326
    113692871281281271371371327128128127137137137137137128137138613271227122713713271227128122713713713713712812812271281227132712271326
    2699393861371371361461371327137137137136146137137137137137138613271326132613713271326137132613713713713713713713261371326142613261325
    113692861371371371371371326137137137137137137136146137137138614261326132713614261326137132614613713713713713713261371327132613261327
    113692861371371371371371326137137137137137137137137136146138713261326132713713261326137132713614613713713713713261461327132613251526
    113691871371281281281281227137128128128128128128127137137138712271227132712811281227137122812713712812812812812271371228122713261327
    1137898912811911911911911281281191191191191191191191010109118912271227122812811281227128112912810911911911911911291181129122712281128
    113789891371281281191281227128128128128128128128119128118128812271227122812812271227128122812811812812812812812281271228122712281227
    

    I suggest to try with my sketch and see if that works.

    BTW. Passing a LED pin to the constructor as status indicator doesn't seem to work, or my eyes are just too slow 😏



  • @Yveaux I cannot thank you enough for doing this to try and help me out. It is really kind of you.
    I am using 1.8.9 IDE as I had issues with 1.8.10 (as did others). Also I notice that you have forced 57600 as the baud rate in the sketch. Is this the magic bullet I wonder as I left mine at the default 115200 setting. I can't imagine why it would make a difference though.
    I will be trying it shortly and will report back with anything I find.
    I owe you a beer for sure! 😉


  • Mod

    @skywatch said in VS838 IR receiver led anyone got it working with mys?:

    @Yveaux I cannot thank you enough for doing this to try and help me out. It is really kind of you.

    Glad I could help!

    I am using 1.8.9 IDE as I had issues with 1.8.10 (as did others).

    I didn't encounter any issues with 1.8.10 so far, but I don't expect it will make a difference in your case

    Also I notice that you have forced 57600 as the baud rate in the sketch. Is this the magic bullet I wonder as I left mine at the default 115200 setting. I can't imagine why it would make a difference though.

    57600 is the default baud rate at 3v3 for pro mini iirr. This might be related to when using the internal oscillator and the frequency errors introduced by it. But pro mini uses an external crystal so I have to dig the datasheets to know for sure. Maybe some other forum member knows it by heart...

    I owe you a beer for sure! 😉

    Great! That I will remember 😆



  • @Yveaux Your code works.....until I add it to mine and then it stops working for some inexplicable reason that will drive me insane I think. 😉
    I copied across your code line by line and still it refuses to 'see' any IR commands being received.

    I have tried excluding the watchdog, excluding the bh1750, adding arduino.h and excluding wire.h and none of those make any difference.


  • Mod

    @skywatch Maybe the cause lies outside your sketch; Are you using MySensors 2.3.2? Or do try with Arduino 1.8.10



  • @Yveaux I have narrowed it down to a small section of code.....still working on it!



  • @Yveaux Ihave 2 issues that I have identified, but can't work out the cause.

    Issue 1 - No IR received seems to be caused by thise section of code. Commenting it out and it works as expected (but of course will never transmit).....

     if (newcodeRX == 1 || lightrequest == 1) {
        irsend.sendNEC(INcode, 32);
        newcodeRX = 0;
        lightrequest = 0; 
       }
    

    Second issue, is when receiving IR is working I cannot do anything useful with it. I have tried 2 methods to get a value and perform a function with it and both fail. See the 2 methods tried here......

     decode_results results;
    
      if (irrecv.decode(&results)) {
        Serial.print("IR Received... ");
        Serial.println(results.value, HEX);
        IRin = (results.value, HEX);
        Serial.print(" IRin... ");
        Serial.println(IRin);
         irrecv.resume(); // Receive the next value
      }
    
      if (IRin == 0xFFA25D) {
        lights = 1;
        Serial.print("Lights ON... ");
      }
    
      if ((results.value, HEX) == 0xFFE21D) {
        lights = 0;
        Serial.print("Lights OFF... ");
      }
    
    

    I need to eat now, will get back to this later on......



  • Second issue now solved, just the first one to investigate.... 😉



  • Both issues now resolved! 🙂

    More to follow..... 😉



  • So here is what I learned from all this....

    Issue 1 - Was caused by the fact that IRsend was called at first boot - nothing wrong with that, but what I didn't know was that IRsend disables IR receive.
    The solution was as simple as adding one more line to that section of code as follows.....

     if (newcodeRX == 1 || lightrequest == 1) {
        irsend.sendNEC(INcode, 32);
        newcodeRX = 0;
        lightrequest = 0; 
        irrecv.enableIRIn(); // Start the receiver
       }
    

    This re-enables the receiver and then all is working as expected!

    As for the second issue......Well, I'll just post the code for anyone interested.....

     if (irrecv.decode(&results)) {
        IRin = results.value,HEX;
        
      if (IRin == 0xFFA25D) {
        lights = 1;
        Serial.print("Lights ON... ");
      }
    
      if (IRin == 0xFFE21D) {
        lights = 0;
        Serial.print("Lights OFF... ");
      }
    
      if (lights != last_lights) {
        saveState(10, lights);
        send(msgLights.set(lights));
        last_lights = lights;
        }
    
         irrecv.resume(); // Receive the next value
    
      }
    

    It's always soooooo easy when you know how! 😉

    Onwards and upwards! 🙂


  • Mod

    @skywatch great to hear you resolved your issues!



  • Many thanks @electrik and @Yveaux , some moral support is often pivotal in getting things done!

    @Yveaux IDE 1.8.12 is now available and working fine on win10 x64 for me 🙂


Log in to reply
 

Suggested Topics

  • 9
  • 3
  • 35
  • 7
  • 14
  • 4
  • 14
  • 30

181
Online

9.4k
Users

10.0k
Topics

104.4k
Posts