Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. twosh
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by twosh

    • RE: Decoding / converting IR-codes

      I will check and post my on and off codes later tonight if I can find the time. I have only access to the remote until next weekend so I won't be able to actually verify anything until then. :s

      @Moshe-Livne I agree that the remote must be sending not only the "on"-command, but the whole state as currently displayed on the remote, because if you point the remote away from the pump, make some changes, then point it at the pump and make another change all the changes will come into effect. Then again, the pump itself (mine at least) does remember its last state because it can wake up after a power outage with the same settings as before the outage.

      posted in Troubleshooting
      twosh
      twosh
    • Decoding / converting IR-codes

      Hi,

      I've built the IR sender/receiver sensor and I am alble to receive and send codes without problems when using codes for my Sony receiver. However the main reason for building this particular sensor is that I would like to control my Mitshubishi Kirigamine air to air heat pump. The remote model for the pump is KM08A.

      I can't find any codes on the net for this remote som I tried receiving the code when pushing the on/off button. I thought that I could capture the code and then use it to send the command I wanted. This is what I got via the serial monitor:

      Decoded Unknown: Value:0 (0 bits)
      Raw samples(100): Gap:17100
        Head: m3400  s1800
      0:m350 s1350	1:m350 s1350		 2:m400 s450	3:m400 s450		 
      4:m400 s500	5:m350 s1350		 6:m350 s500	7:m400 s450		 
      8:m350 s1400	9:m350 s1350		 10:m350 s500	11:m350 s1350		 
      12:m400 s450	13:m350 s500		 14:m400 s1350	15:m350 s1350		 
      
      16:m350 s500	17:m350 s1350		 18:m350 s1350	19:m400 s500		 
      20:m350 s500	21:m350 s1350		 22:m350 s500	23:m350 s500		 
      24:m400 s1300	25:m350 s550		 26:m350 s500	27:m350 s500		 
      28:m350 s500	29:m350 s500		 30:m400 s450	31:m400 s500		 
      
      32:m350 s500	33:m350 s500		 34:m350 s500	35:m350 s500		 
      36:m350 s500	37:m350 s550		 38:m350 s500	39:m350 s500		 
      40:m350 s500	41:m400 s450		 42:m400 s500	43:m350 s500		 
      44:m350 s500	45:m350 s1350		 46:m350 s500	47:m350 s500		 
      
      48:m400
      Extent=57850
      Mark  min:350	 max:400
      Space min:450	 max:1400
      
      

      But how do I use this? Can I convert it somwhow to the 0x00000 format used in the sketch? I appreciate any thoughts and suggestions!

      Cheers,
      Tim

      posted in Troubleshooting
      twosh
      twosh
    • RE: Controlling existing relays

      @phil-pritchard No, not really. As I've mentioned tinkering with hardware is new to me so I don't actually have any knowledge of what exists and whats possible from that side of the table. Would you like to expand on your thoughts? 🙂

      I've ordered a bunch of these hall effect sensors: http://www.ebay.com/itm/221649135732?rmvSB=true

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Thanks @sparkman for once again nudging me in the right direction!
      I went trough the code in my sketch a couple of times commenting out various sections and suddenly the sensor started functioning correctly. So I checked that function closely and noticed that I was out of bounds in a for-loop. that stupid NUMBER_OF_CURRENT_PINS +1 . That +1 had accidentally stayed there from an early version of the sketch. Correcting that, my sketch seems to load without problems - go figure! 😛

      posted in Hardware
      twosh
      twosh
    • RE: Sensebender Micro

      @tbowmo It was just a thought I came up with and thought to share my idea and arguments. 🙂
      I think the Sensebender Micro is great especially if you would like to monitor temperatures (which of course many of us wants to), but I just think that a less expensive, light option (that would be available to order... 🙂 ) could appeal to many. Great that you have requested a quote!

      posted in Announcements
      twosh
      twosh
    • RE: Controlling existing relays

      @Sparkman
      I tried powering the Megas radio from a Nanos 3.3V pin and GND. The Nano is working fine as a sensor by itself, so I guess the radio gets enough power from it. However, this way I only got "check wires" from the Mega... 😞

      Just a thought; if it helps, I'm defining these pins for the Mega in my sketch, but I don't see how that could affect this particular problem...

      const int relayPin[] = {22, 23, 24, 25, 26, 27, 28, 29};
      const int currentPin[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
      
      posted in Hardware
      twosh
      twosh
    • RE: Sensebender Micro

      @hek said:

      That's the old A10. It would probably work but A20 has some firmware fixes and more tests performed on it.
      I have nothing to say about the price. It is the same as for A20.. As you can see it is the most expensive part on the micro board (30% of it's price).

      Would you consider a Sensebender Micro Light-version without this component? i mean, if it's 30 % of the price, not available and not imo a critical component (you could always add your own humidity/temp sensors), there are quite a few reasons why a light version would be tempting. At least to me. 🙂

      Cheers,
      Tim

      posted in Announcements
      twosh
      twosh
    • RE: Controlling existing relays

      Thanks for the suggestion, @Sparkman !
      I have just the radio connected for now, but still getting that "version mismatch"-error. I will try getting a separate 3.3v power to the radio tomorrow and see if that would help.

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Tried powering the Mega from computers USB 5V, and two different 12V DC adapters - still getting version mismatch. Anybody knows what's going on?

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Finally found a combination that worked with the mega as a sensor. Here is the pin mapping if it will save time for anyone:

      9 CE
      10 CSN/CS
      52 SCK
      51 MOSI
      50 MISO
      2 IRQ

      Doesn't require any config changes, but I am currently getting some "0;0;3;0;9;version mismatch" in serial monitor. Have 10 uF cap on the radio.

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      My Mega arrived today so I could load it with my customized sketch that I've worked on for controlling relays as well as measuring current. I'm still waiting for the current sensors, but I've already got a problem... I keep getting "check wires" via the serial monitor, and the Mega is not detected by the gateway.

      Basically I think that the wiring of the radio to the Mega is wrong, but after scavenging the forum and trying a handfull of different wiring combinations I still can't get this to work.

      I have tried using the normal (nano, pro mini) pins, using pins 14-16, 50-52, etc. but nothing seems to work. I have NOT modified any config files yet, but based on the various threads I've read it's unclear to me if you should or shouldn't.

      @Sparkman , do you use a mega yourself, and have successfully wired the radio?

      @hek, would it be possible to add instructions for the Mega (and perhaps the Uno as well) to the general build guide for connecting the radio?

      posted in Hardware
      twosh
      twosh
    • RE: Newbie with vera

      Hi @csnij !

      Have you tried adding a capacitor to the radio as suggested in the guide http://www.mysensors.org/build/connect_radio#connecting-a-decoupling-capacitor ?

      You might also have some bad quality clones of the NRF24L01+ chip. Try searching the forum for fake clones or bad clones and you will probably see some threads discussing it.

      Then again, you might have normal interference from e.g. walls. Is there clear sight between the node and the gateway or do you have thick walls etc?

      Best wishes,
      Tim

      posted in Vera
      twosh
      twosh
    • RE: Energy pulse meter + outside temperature

      @mbj Would you mind sharing your sketch? 🙂 Right now I'm using two separate arduinos for measuring energy and temperature (hot/cold side) on my heat pump. Would be nice to combine this into one arduino, one sketch.

      Cheers,
      Tim

      posted in My Project
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      I'm back to choosing between no sleep, and the sleep(); function posted above. I can't get gw.sleep(); to work with either one or two interrupts, with or without declaring interrupts(); and/or attachInterrupt();.

      I'm ready to try more stuff if anyone got any ideas, but with my own limited understanding of both hardware in general and arduino in particular it feels like I'm running on fumes here. 😮

      Thanks everyone for your contribution, and @hek - you've done a great job with MySensors! 👏

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Hi again!

      I've tried different approaches now with the gw.sleep(); func without success, using CHANGE, RISING or FALLING. No reaction either from tag or the Vera.

          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength)); 
          // gw.sleep(2000);
        }
        gw.sleep(0, CHANGE, 1, CHANGE, 0); // int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
      }
      

      I've also tried adding this to setup();

        interrupts();
      

      as well as this:

        attachInterrupt(0, loop, CHANGE);
        attachInterrupt(1, loop, CHANGE);
      

      Nothing happens. It just continues to sleep...

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Ah, there it is! I was looking at his:
      https://github.com/mysensors/CodeBender/blob/master/MySensor.h

      Big thanks @hek ! I'll try this when I get home!

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Hi @hek and thanks for the info!

      However, I'm not sure that I find anything regarding listening for both D2 and D3-pins in MySensors.h, I only find:

      */**
      	 * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change.
      	 * See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin
      	 * is assigned to what interrupt. On Nano/Pro Mini: 0=Pin2, 1=Pin3
      	 * @param interrupt Interrupt that should trigger the wakeup
      	 * @param mode RISING, FALLING, CHANGE
      	 * @param ms Number of milliseconds to sleep or 0 to sleep forever
      	 * @return true if wake up was triggered by pin change and false means timer woke it up.
      	 */
      	bool sleep(int interrupt, int mode, unsigned long ms=0);
      

      Which is the same as the documentation, right?

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Earlier I tried using gw.sleep(2, CHANGE, 1000); but that didn't work then. Should I use it another way? And how do I make sure I listen for interrupts on both the D2 and D3 pins?

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Hi all!

      Soldered a cable between D3 and the IRQ on the RFID-chip and it seems to have solved my problem. The response time is a bit slow - I need to keep my tag pressed to the RFID-chip for 2-5 seconds before it switches mode. Any idea why that would be? Note that I'm using the sleep function from http://forum.mysensors.org/topic/1112/how-low-can-arduino-can-go/20 and not gw.sleep();

      My sketch looks like this:

      /* 
        RFID Lock sensor/actuator
        
        Henrik Ekblad <henrik.ekblad@mysensors.org>
      
        Use RFID tag to lock/unlock a door or trigger a scene on your controller.
        This example sketch allows you to add an optional relay or solenoid 
        which can be activated/opened by RFID or controller.  
      
        Use the I2C wiring option for your RFID module and connect to the following Arduino pins.
        
        RFID       Arduino
        -----      -------
        GND   ->   GND
        VCC   ->   +5V
        SCL   ->   A5
        SDA   ->   A4
        
        Use normal wiring for NRF24L01 radio
        
        Attach a optional relay or solonoid lock to pin 4
        
      */
       
      #include <MySensor.h>  
      #include <SPI.h>
      #include <Wire.h>
      #include <PN532_I2C.h>
      #include <PN532.h>
      #include <avr/sleep.h>
      
      
      // Add your valid rfid keys here. To find you your key just run sketch; hold your new RFID tag in fron ot the reader; 
      // and copy the key from serial output of this sketch.
      const uint8_t maxKeyLength = 7;
      uint8_t validKeys[][maxKeyLength] = {
                            //Removed my keys here when posting the sketch
                        };
      int keyCount = sizeof validKeys / maxKeyLength; 
      
      
      #define CHILD_ID 99   // Id of the sensor child
      #define YELLOWLED 5  // Pin for the Yellow led.
       
      /*Pin definitions*/
      const int lockPin = 4;         // (Digital 4) The pin that activates the relay/solenoid lock.
      
      bool lockStatus;
      MySensor gw;
      MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS);
      PN532_I2C pn532i2c(Wire);
      PN532 nfc(pn532i2c);
       
      void setup() {
        
        pinMode(lockPin, OUTPUT);
        pinMode(YELLOWLED, OUTPUT);
      
        nfc.begin();
        uint32_t versiondata = nfc.getFirmwareVersion();
        if (! versiondata) {
          Serial.print("Couldn't find PN53x board");
          while (1); // halt
        }
        Serial.print("Found NFC chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
        Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
        Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
        // Set the max number of retry attempts to read from a card
        // This prevents us from waiting forever for a card, which is
        // the default behaviour of the PN532.
        nfc.setPassiveActivationRetries(0x3);
        
        // configure board to read RFID tags
        nfc.SAMConfig();
      
        // Init mysensors library
        gw.begin(incomingMessage);
        
        gw.sendSketchInfo("RFID Lock", "1.0");
        gw.present(CHILD_ID, S_LOCK);
        
        lockStatus = gw.loadState(0);    // Read last lock status from eeprom
        setLockState(lockStatus, true); // Now set the last known state and send it to controller
        
      }
       
      void loop() {
        gw.process(); // Process incomming messages
      
        boolean success;
        uint8_t key[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
        uint8_t currentKeyLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
      
        
        // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
        // 'uid' will be populated with the UID, and uidLength will indicate
        // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
        success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength);
        
        if (success) {
          Serial.print("Found tag id: ");
          for (uint8_t i=0; i < currentKeyLength; i++) 
          {
            if (i>0) Serial.print(",");
            Serial.print("0x");Serial.print(key[i], HEX); 
          }
          for (uint8_t i=currentKeyLength; i < maxKeyLength; i++) 
          {
            Serial.print(",0x00"); 
          }
      
      
          Serial.println("");
      
          boolean valid = false;
          // Compare this key to the valid once registered here in sketch 
          for (int i=0;i<keyCount && !valid;i++) {
            for (int j=0;i<currentKeyLength && !valid;j++) {
              if (key[j] != validKeys[i][j]) {
                break;
              }
              if (j==currentKeyLength-1) {
                valid = true;
              }
            }
          }
          if (valid) {
            // Switch lock status
            setLockState(!lockStatus, true);       
          }
          
          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength)); 
          //gw.sleep(2000);
        }
        sleep();
      } 
       
       
       
      // Unlocks the door.
      void setLockState(bool state, bool send){
        if (state) {
           Serial.println("close lock");
           digitalWrite(YELLOWLED, HIGH);}
        else {
           Serial.println("open lock");
           digitalWrite(YELLOWLED, LOW);}
        if (send)
          gw.send(lockMsg.set(state));
        digitalWrite(lockPin, state);
        gw.saveState(0,state);
        lockStatus = state;
      }
       
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LOCK_STATUS) {
           // Change relay state
           setLockState(message.getBool(), false); 
        
           // Write some debug info
           Serial.print("Incoming lock status:");
           Serial.println(message.getBool());
         } 
      }
      
      void sleep(){
         // disable ADC
        ADCSRA = 0;  
      
        // clear various "reset" flags
        MCUSR = 0;     
        // allow changes, disable reset
        WDTCSR = bit (WDCE) | bit (WDE);
        // set interrupt mode and an interval 
        WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 1 second delay
        wdt_reset();  // pat the dog
        
        set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
        noInterrupts ();           // timed sequence follows
        sleep_enable();
       
        // turn off brown-out enable in software
        MCUCR = bit (BODS) | bit (BODSE);
        MCUCR = bit (BODS); 
        interrupts ();             // guarantees next instruction executed
        sleep_cpu ();  
        
        // cancel sleep as a precaution
        sleep_disable();
      }
      
      
      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Thanks @BulldogLowell ! I can see that the chip has an IRQ pin and GND among others. SInce I'm not a hardware guy could you tell me if it would be enough to connect the IRQ to my arduino D3-pin? Would I need to connect some other pins as well, e.g. the RFID GND to Arduino GND? (The RFID is already connected to Arduino GND via the 4 pins mentioned in the MySensor guide for connecting the RFID.)

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      @BulldogLowell Thanks - this sounds like a plan! 🙂

      I'm using this RFID-chip: http://www.ebay.com/itm/271316626820?rmvSB=true
      I've got a lot of these resistors lying http://www.ebay.com/itm/220954677122?rmvSB=true but are they too large? 5V / 4,7 kOhm ~ 1 mA, would it trigger? I've got D3 free on my arduino which interrupts, D2 is used by the radio.

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Meh...

      Trying bits and pieces from all over the web for using the hardware timer, but since I'm not exactly sure what I'm doing when it comes to this level of hardware interaction - well the following crude sketch doesn't work. 🙂

      /* 
        RFID Lock sensor/actuator
        
        Henrik Ekblad <henrik.ekblad@mysensors.org>
      
        Use RFID tag to lock/unlock a door or trigger a scene on your controller.
        This example sketch allows you to add an optional relay or solenoid 
        which can be activated/opened by RFID or controller.  
      
        Use the I2C wiring option for your RFID module and connect to the following Arduino pins.
        
        RFID       Arduino
        -----      -------
        GND   ->   GND
        VCC   ->   +5V
        SCL   ->   A5
        SDA   ->   A4
        
        Use normal wiring for NRF24L01 radio
        
        Attach a optional relay or solonoid lock to pin 4
        
      */
       
      #include <MySensor.h>  
      #include <SPI.h>
      #include <Wire.h>
      #include <PN532_I2C.h>
      #include <PN532.h>
      #include <avr/sleep.h>
      #include <avr/io.h>
      #include <avr/interrupt.h>
      
      
      // Add your valid rfid keys here. To find you your key just run sketch; hold your new RFID tag in fron ot the reader; 
      // and copy the key from serial output of this sketch.
      const uint8_t maxKeyLength = 7;
      uint8_t validKeys[][maxKeyLength] = {
      
                        };
      int keyCount = sizeof validKeys / maxKeyLength; 
      
      
      #define CHILD_ID 99   // Id of the sensor child
      #define YELLOWLED 5  // Pin for the Yellow led.
       
      /*Pin definitions*/
      const int lockPin = 4;         // (Digital 4) The pin that activates the relay/solenoid lock.
      
      bool lockStatus;
      MySensor gw;
      MyMessage lockMsg(CHILD_ID, V_LOCK_STATUS);
      PN532_I2C pn532i2c(Wire);
      PN532 nfc(pn532i2c);
       
      void setup() {
        
        pinMode(lockPin, OUTPUT);
        pinMode(YELLOWLED, OUTPUT);
      
        nfc.begin();
        uint32_t versiondata = nfc.getFirmwareVersion();
        if (! versiondata) {
          Serial.print("Couldn't find PN53x board");
          while (1); // halt
        }
        Serial.print("Found NFC chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
        Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
        Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
        // Set the max number of retry attempts to read from a card
        // This prevents us from waiting forever for a card, which is
        // the default behaviour of the PN532.
        nfc.setPassiveActivationRetries(0x3);
        
        // configure board to read RFID tags
        nfc.SAMConfig();
      
        // Init mysensors library
        gw.begin(incomingMessage);
        
        gw.sendSketchInfo("RFID Lock", "1.0");
        gw.present(CHILD_ID, S_LOCK);
        
        lockStatus = gw.loadState(0);    // Read last lock status from eeprom
        setLockState(lockStatus, true); // Now set the last known state and send it to controller 
        
          // initialize Timer1
          cli();          // disable global interrupts
          TCCR1A = 0;     // set entire TCCR1A register to 0
          TCCR1B = 0;     // same for TCCR1B
       
          // set compare match register to desired timer count:
          OCR1A = 15624;
          // turn on CTC mode:
          TCCR1B |= (1 << WGM12);
          // Set CS10 and CS12 bits for 1024 prescaler:
          TCCR1B |= (1 << CS10);
          TCCR1B |= (1 << CS12);
          // enable timer compare interrupt:
          TIMSK1 |= (1 << OCIE1A);
          // enable global interrupts:
          sei();
        
      }
       
      void loop() {
        gw.process(); // Process incomming messages
      
        boolean success;
        uint8_t key[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
        uint8_t currentKeyLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
      
        
        // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
        // 'uid' will be populated with the UID, and uidLength will indicate
        // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
        success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength);
        
        if (success) {
          Serial.print("Found tag id: ");
          for (uint8_t i=0; i < currentKeyLength; i++) 
          {
            if (i>0) Serial.print(",");
            Serial.print("0x");Serial.print(key[i], HEX); 
          }
          for (uint8_t i=currentKeyLength; i < maxKeyLength; i++) 
          {
            Serial.print(",0x00"); 
          }
      
      
          Serial.println("");
      
          boolean valid = false;
          // Compare this key to the valid once registered here in sketch 
          for (int i=0;i<keyCount && !valid;i++) {
            for (int j=0;i<currentKeyLength && !valid;j++) {
              if (key[j] != validKeys[i][j]) {
                break;
              }
              if (j==currentKeyLength-1) {
                valid = true;
              }
            }
          }
          if (valid) {
            // Switch lock status
            setLockState(!lockStatus, true);       
          }
          
          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength)); 
          //gw.sleep(2000);
        }
        sleep();
      } 
       
       
       
      // Unlocks the door.
      void setLockState(bool state, bool send){
        if (state) {
           Serial.println("close lock");
           digitalWrite(YELLOWLED, HIGH);}
        else {
           Serial.println("open lock");
           digitalWrite(YELLOWLED, LOW);}
        if (send)
          gw.send(lockMsg.set(state));
        digitalWrite(lockPin, state);
        gw.saveState(0,state);
        lockStatus = state;
      }
       
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LOCK_STATUS) {
           // Change relay state
           setLockState(message.getBool(), false); 
        
           // Write some debug info
           Serial.print("Incoming lock status:");
           Serial.println(message.getBool());
         } 
      }
      
      void sleep(){
         // disable ADC
        ADCSRA = 0;  
      
        // clear various "reset" flags
        MCUSR = 0;     
        // allow changes, disable reset
        WDTCSR = bit (WDCE) | bit (WDE);
        // set interrupt mode and an interval 
        WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 1 second delay
        wdt_reset();  // pat the dog
        
        set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
        noInterrupts ();           // timed sequence follows
        sleep_enable();
       
        // turn off brown-out enable in software
        MCUCR = bit (BODS) | bit (BODSE);
        MCUCR = bit (BODS); 
        interrupts ();             // guarantees next instruction executed
        sleep_cpu ();  
        
        // cancel sleep as a precaution
        sleep_disable();
      }
      
      ISR(TIMER1_COMPA_vect)
      {
        boolean success;
        uint8_t key[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
        uint8_t currentKeyLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
      
        
        // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
        // 'uid' will be populated with the UID, and uidLength will indicate
        // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
        success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength);
        
        if (success) {
          Serial.print("Found tag id: ");
          for (uint8_t i=0; i < currentKeyLength; i++) 
          {
            if (i>0) Serial.print(",");
            Serial.print("0x");Serial.print(key[i], HEX); 
          }
          for (uint8_t i=currentKeyLength; i < maxKeyLength; i++) 
          {
            Serial.print(",0x00"); 
          }
      
      
          Serial.println("");
      
          boolean valid = false;
          // Compare this key to the valid once registered here in sketch 
          for (int i=0;i<keyCount && !valid;i++) {
            for (int j=0;i<currentKeyLength && !valid;j++) {
              if (key[j] != validKeys[i][j]) {
                break;
              }
              if (j==currentKeyLength-1) {
                valid = true;
              }
            }
          }
          if (valid) {
            // Switch lock status
            setLockState(!lockStatus, true);       
          }
          
          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength)); 
          //gw.sleep(2000);
        }
      }
      

      Help is appreciated...

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Ok, using the code from http://forum.mysensors.org/topic/1112/how-low-can-arduino-can-go/20 (thanks @funky81 ) I get the Arduino sleeping peacefully while still reacting to interrupts.

      Since my rfid doesn't generate an interrupt (attached to A4 and A5) I need to set a timer to wake the little beast up every couple of seconds just to check if there happen to be a tag nearby then. I'll let you know how this turns out! 🙂

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Well, that was fast... It didn't work... 😞

          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength)); 
        }
        gw.sleep(2, CHANGE, 1000);
      } 
      

      Am I missing something or am I trying to do something that isn't possible right now?

      posted in Troubleshooting
      twosh
      twosh
    • RE: How to sleep the Arduino but still have it respond to the Vera?

      Hi @fleinze , and thanks for your suggestion. I couldn't find anything in the API or during a quick search of the forum how to do this. Do you have some code for it or?

      However, when I checked the API again and I found something I could try, namely the interrupt variable in the sleep function:

      bool sleep(int interrupt, int mode, unsigned long ms=0);
      

      I'll try something like this and see how it works!

      posted in Troubleshooting
      twosh
      twosh
    • How to sleep the Arduino but still have it respond to the Vera?

      Hi,

      I'm trying to save some cpu cycles here! I'm using the pretty much unmodified rfid lock sketch, except I've added code for a LED diode to show if it's armed or disarmed. Since this puppy will only be used when you leave or enter the house, 99% of the time it could sleep. Here is the loop:

      void loop() {
        gw.process(); // Process incomming messages
      
        boolean success;
        uint8_t key[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
        uint8_t currentKeyLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
      
        
        // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
        // 'uid' will be populated with the UID, and uidLength will indicate
        // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
        success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength);
        
        if (success) {
          Serial.print("Found tag id: ");
          for (uint8_t i=0; i < currentKeyLength; i++) 
          {
            if (i>0) Serial.print(",");
            Serial.print("0x");Serial.print(key[i], HEX); 
          }
          for (uint8_t i=currentKeyLength; i < maxKeyLength; i++) 
          {
            Serial.print(",0x00"); 
          }
      
      
          Serial.println("");
      
          boolean valid = false;
          // Compare this key to the valid once registered here in sketch 
          for (int i=0;i<keyCount && !valid;i++) {
            for (int j=0;i<currentKeyLength && !valid;j++) {
              if (key[j] != validKeys[i][j]) {
                break;
              }
              if (j==currentKeyLength-1) {
                valid = true;
              }
            }
          }
          if (valid) {
            // Switch lock status
            setLockState(!lockStatus, true);       
          }
          
          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength));
        }
        gw.sleep(2000);
      } 
      

      Using this loop the arduino works great when using the rfid-tag to trigger a change in armed / disarmed, but the arduino does NOT respond to commands from my Vera (UI7).

      I think I know what the problem is - basically the Arduino is sleeping when the command from the controller arrives, and thus it can't process it. Changing the last bit of code like this (moving the gw.sleep(2000) only to trigger if an rfid-tag has been read works:

          // Wait for card/tag to leave reader    
          while(nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &key[0], &currentKeyLength)); 
          gw.sleep(2000);
        }
      } 
      

      But then again, using this code it doesn't sleep at all except for the 2 seconds 2 times a day when I trigger it. 🙂

      So, how could I have the best of both worlds? I want to let it sleep until 1) there is an incoming command from my Vera or 2) an rfid-tag is recognized. Is it possible?

      As always, thanks in advance for any input!

      posted in Troubleshooting
      twosh
      twosh
    • RE: Controlling existing relays

      I read the site and concluded that I will first of try with the suggested components (thanks again @Sparkman ). Ordered a bunch of them and a Mega. I'll let you know of my progress when they arrive! Thanks everybody!

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Thanks for the link - will read it tomorrow! 🙂

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      @jeylites - thanks for the alternate suggestion! 🙂

      @Sparkman , to clarify, my light switches does glow constantly when turned on, so there is constant current on the output side of the relay going to the light switches. I've measured the voltage and it is 24VAC. So I think that, disregarding the power measurement possibility, I could use that circuit as well.

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Great, thanks for the clarifications @Sparkman !

      Being able to measure power would of course be a nice bonus! I'll think about it. I have another question (of course... 🙂 ).

      The Nano and Pro mini have only 6 analogue inputs, I would be having need for 8... Would I need to use two arduinos or is there any other way?

      Best,
      Tim

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      @Sparkman I think that would work out quite nicely! But I think I would rather stay away from the 230VAC and use it on the 24VAC instead - feels safer. If I don't misunderstand how the current sensor works it shouldn't matter if I hard wire it on 230VAC or 24VAC, right?

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Is this what I would need? http://www.ebay.com/itm/310506962976?rmvSB=true

      How would I wire this? Should it sit between the house relay and the light switch (serial), or would I run it parallel somehow? I guess I would need 8 of these to measure my 8 relays / light switches?

      Thanks!

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Thank you all for the various ideas and input!

      I've figured out what I had done wrong (not feeding the relays with the common wire correctly). I've also changed the sketch to give a 35 ms impulse, and connected everything. Working great! Here is my sketch if anyone needs it:

      // Example sketch showing how to control physical relays. 
      // This example will NOT remember relay state even after power failure.
      
      #include <MySensor.h>
      #include <SPI.h>
      
      #define RELAY_ON 0  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
      
      #define noRelays 8
      const int relayPin[] = {A0, A1, A2, A3, A4, A5, 3, 4};
      
      MySensor gw;
      
      void setup()  
      {   
        // Initialize library and add callback for incoming messages
        gw.begin(incomingMessage, AUTO, true);
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Relay", "1.0 AD");
      
        // Fetch relay status
        for (int sensor=0; sensor < noRelays; sensor++)
        {
          // Register all sensors to gw (they will be created as child devices)
          gw.present(sensor+1, S_LIGHT);
          // Then set relay pins in output mode
          pinMode(relayPin[sensor], OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          //digitalWrite(relayPin[sensor], gw.loadState(sensor+1)?RELAY_ON:RELAY_OFF);
        }
      }
      
      
      void loop() 
      {
        // Alway process incoming messages whenever possible
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message)
      {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LIGHT)
        {
           if (message.sensor <= noRelays)
           {
               digitalWrite(relayPin[message.sensor-1], RELAY_ON);
               delay(35); // 35 ms impulse used by my relays
               digitalWrite(relayPin[message.sensor-1], RELAY_OFF);
           }
      
           // Store state in eeprom
           //gw.saveState(message.sensor, message.getBool());
           
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      

      As @Sparkman says, I won't actually know if the light is on or off, since I can't register a change that would happen via the physical light switches in the house. Any suggestions on how to do this is of course welcome! The output side of the house relay is 230 VAC to the lights, and 24 VAC to the leds in the light switches. What kind of hardware would I need for sensing current and reporting it back to the Arduino? Is there any sketch I could use that lays the groundwork?

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      @TimO said:

      I suppose the relays are impulse relays, which need a impulse to change the state (on/off). I'm using the Relay-Modules you mentioned above to control my impulse relays. My impulse relays are controlled with 230V. The relays are connected in parallel to the existing switches and use a 100ms impulse to change the state.
      Works like a charme.

      Could you share your experience in more detail? It feels like you have accomplished what I would like to happen at this point. 🙂

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Found some specs on my house relays: http://www.switchtec.co.uk/relay_catalog/129_LR-28.pdf

      It's the esmi nr-8251 latching relay if this helps!

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Thanks a lot @jeylites !

      A couple of question; you are using physical buttons mapped to your pins d3-d8 - 6 in total. The rest of the digital pins are taken up by the radio I guess, since they are for me. Does that mean that this sketch is limited to 6 relays as well since the Relay class seems to match one button pin with one relay pin. Or can I just define 6 buttons and 8 relays, like this?

      const int relayPin[] = {A0, A1, A2, A3, A4, A5, A6, A7};
      const int buttonPin[] = {3, 4, 5, 6, 7, 8, NULL, NULL};
      

      I could use the A0-A7 pins for my 8 relays but I'm unsure if the above 6+NULL+NULL buttons to 8 relays mapping will cause problems?

      To clarify, the problem I'm facing when using my sketch above is not that the arduino relays would not obey, it is that the relays controlled by the arduino relays stays "on" all the time. The physical buttons i keep mentioning are connected to the HOUSE relays (i.e. lightswitches), not to the Arduino.

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Here's my sketch @jeylites !

      I'm using this 8 channel relay board: http://www.ebay.com/itm/181242936438?rmvSB=true

      Had to switch the GPIO HIGH/LOW values around compared to the original sketch, and added two analogue pins controlling channel 7 and 8 on the board.

      // Example sketch showing how to control physical relays. 
      // This example will remember relay state even after power failure.
      
      #include <MySensor.h>
      #include <SPI.h>
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define RELAY_1A  0  // Arduino Analog I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 6 // Total number of attached relays
      #define NUMBER_OF_ANALOG_RELAYS 2 // Total number of attached relays
      #define RELAY_ON 0  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
      
      MySensor gw;
      
      void setup()  
      {   
        // Initialize library and add callback for incoming messages
        gw.begin(incomingMessage, AUTO, true);
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Relay", "1.0 AD");
      
        // Fetch relay status
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          gw.present(sensor, S_LIGHT);
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
      
        // Fetch and present the analogue relays  
        int sensor=NUMBER_OF_RELAYS+1;
        gw.present(sensor++, S_LIGHT);
        pinMode(A0, OUTPUT);
        digitalWrite(A0, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
        gw.present(sensor++, S_LIGHT);
        pinMode(A1, OUTPUT);
        digitalWrite(A1, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
        
      }
      
      
      void loop() 
      {
        // Alway process incoming messages whenever possible
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LIGHT) {
           
          // Change relay state
           if (message.sensor <= NUMBER_OF_RELAYS)
             digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           else if (message.sensor == NUMBER_OF_RELAYS+1) //First analogue sensor
             digitalWrite(A0, message.getBool()?RELAY_ON:RELAY_OFF);
           else //Second analogue sensor
             digitalWrite(A1, message.getBool()?RELAY_ON:RELAY_OFF);
             
           // Store state in eeprom
           gw.saveState(message.sensor, message.getBool());
           
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Want to share my progress since my 8 relay arrived today! 🙂

      I've successfully modified the relay example sketch to use two analogue pins for the 7:th and 8:th relays, so everything software wise is fine for now.

      I connected one of the arduino relay outputs to one of my house relays for testing and succeeded to get the house relay to switch on by having the arduino relay low. But I can't get the house relay to turn off again, no matter if I turn the arduino relay high, nor low again. I had to use the physical light switch to turn the relay off again.

      What am I missing..?

      posted in Hardware
      twosh
      twosh
    • RE: Vera Edge UI7 - Serial USB Fix!!!

      Can add that this worked for me as well, using firmware 1.7.1089 on my Vera Edge. Thanks @jeylites !

      posted in Vera
      twosh
      twosh
    • RE: EnergyMeterPulseSensor reporting incorrect power draw?

      Alright - as usual, the code and hardware is fine -> stupid user error! 😛

      @AWI The pulses were indeed not reported as expected - thanks for putting me on the right track! The LM393 is directional and I had to bend it toward the power meter's light - I had it basically 90 degrees off (as it came in the mail). That done the values are absolutely perfect.

      Big thanks to @AWI !

      posted in Troubleshooting
      twosh
      twosh
    • RE: EnergyMeterPulseSensor reporting incorrect power draw?

      @AWI Ok! I'll dig out my volt meter and try. I guess I'll measure between the digital out and ground?

      posted in Troubleshooting
      twosh
      twosh
    • RE: EnergyMeterPulseSensor reporting incorrect power draw?

      @AWI said:

      @twosh Are you able to measure the pulse output from the light sensor to see if you the right pulse rate comes in?

      Thanks for the fast reply! I'm sorry, but I'm not sure how I would do that?

      posted in Troubleshooting
      twosh
      twosh
    • EnergyMeterPulseSensor reporting incorrect power draw?

      Hi,

      I'm using the unmodified code from EnergyMeterPulseSensor.ino (as my power meeter uses 1000 imp / kWh) with a Nano v3 (clone) and a LM393 Light Sensor. The Nano is powered via the USB-port from a 230 V wall plug, the radio is on the Nano's 3v3 pin, and the light sensor on the 5v pin. I'm using a Vera Edge UI7 as controller and having a Nano V3 (clone) as a serial gateway.

      The issue I'm having is that the reported current wattage as well as the cumulative kWh is way of. I'm currently drawing 150 W +/- 5 W but the sensor is showing 615 watts current draw and within an hour the kWh has risen to almost 60 kWh as you can see below:

      powerDraw.png

      What could be the cause for this? Should I calibrate the sensor or something? Any suggestions at all are welcome! 🙂

      Thanks,
      Tim

      posted in Troubleshooting
      twosh
      twosh
    • RE: Controlling existing relays

      @ceech said:

      If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
      triaccontroller.png
      It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

      Based on @jeylites comments I'm starting to think that this triac circuit completely replaces the current relay (not just the Arduino relay board), as well as adding dimmer functionality - is this correct? Confused

      But would I loose the current physical buttons' functionality or could those also be wired into the triac?

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Thanks guys! I will try to get a friend over who knows his stuff when it comes to electricity to help me out with the wiring.

      Breaking it down, I'll need one arduino for controlling the relay board, and if I want a dimmer I would need to rig another Arduino with a dimmer circuit after each 230v relay I want to dim the lamps for.

      @ceech - nice! I'll keep that diagram as an option as well - it would basically eliminate the need for the Arduino relay board I guess.

      Thanks again!

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Latching relays - I can see a small latch physically move when I switch on / off the lights. I think they might be powering my button lights as well since there are a thin wire connected to each relay in addition to the 230V wire. At least that thin wire must be for the impulse making the relay switch. Does this simplify things @Sparkman ?

      @TimO , could you visualize how you have connected the different parts, or better yet use my uploaded pic to show me how I should connect everything?

      Greatly appreciated!

      posted in Hardware
      twosh
      twosh
    • RE: Controlling existing relays

      Thanks for your input @rvendrame & @Sparkman !

      So basically I should connect my Arduino with e.g. this one http://www.ebay.com/itm/5V-12V-24V-10A-1-Channel-Relay-Module-Optocoupler-H-L-Level-Triger-for-Arduino-/181479686454 so that the Arduino triggers this relay, which in turn triggers my current relay, right?

      Well, the buttons being momentary is just my guess pretty much just based on that they "spring" back and lights up, as well as if we have a power shortage, pressing a button doesn't change anything - the light is still on if it was on before the outage. But then again, as I said, hardware isn't my forte so I could be completely wrong.

      In any case, you're probably right about the control panel, @Sparkman, since I guess that it is the thin wire going into the relay that sends the on/off impulse and since it's only one wire I guess there need to be some master box somewhere where all the rooms' wires are connected.

      Reg. dimmer had had thought about adding a z-wave dimming circuit after the relay, but just thought about not getting any power to stay connected if the relay was off. When the light would turn on, it would probably require some time before it would connect to my VeraEdge again and thus enable dimming. But using and Arduino to power the circuit it would always be connected to my controller, thus enabling "dimming" even though the light would be off. I'll think some more about this.

      Thanks again for the advice!

      posted in Hardware
      twosh
      twosh
    • Controlling existing relays

      Hi,

      First of, I'm really new to both home automation and arduino, but really excited about the possibilities. So please be gentle! 🙂 So far I've ordered a bunch of arduino boards, sensors and misc stuff based on a few of the helpful examples listed here to get me started. I really think MySensors.org is a great way to get into home automation if you like to build stuff like I do!

      My technical knowledge however is more on the programming side so I'll start of with a hardware question and see how far my (unfortunately somewhat rusty) programming skills take me after that. 🙂

      In my house built in the early 90's I've got these kind of momentary/pulse (I think) buttons in every room controlling most of the lighting in the house:
      https://www.dropbox.com/s/lfbg7c3pqilnhek/WP_20150420_19_40_43_Pro.jpg?dl=0

      When I press one of the buttons in any room a corresponding relay in my main electrical cabinet switches on or off, thus turning the light in the room on or off. The relays look like this:
      https://www.dropbox.com/s/sux7bujrr4ae1qd/WP_20150420_08_03_25_Pro.jpg?dl=0

      My question is; what hardware would I need in addition to an Arduino Nano to control each of these relays, and how should I wire it to the existing relays? Or would I need to replace the relays completely?

      To add another layer of complexity, would it be possible to add a dimmer to some of the relays in order to be able to dim the lights in certain rooms?

      Thanks in advance the help!

      posted in Hardware
      twosh
      twosh