Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Is it possible to run more than one pin to an interrupt for sleep/wake purposes?

Is it possible to run more than one pin to an interrupt for sleep/wake purposes?

Scheduled Pinned Locked Moved Troubleshooting
55 Posts 7 Posters 14.2k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • karl261K karl261

    @AWI Finally:

    Yes, it works as expected. 4 pins are 0 V and 4 pins are 3.3 V. The chip is using 2.5 uA.

    I had to change a little bit the library, it did not compile and was slightly outdated, also the function we wanted to use was private, but I just did the changes in the library.

    I also needed to update to the latest arduino from 1.6.5 to 1.6.12, because i got an error: collect2.exe: error: ld returned 5 exit status. Now it works.

    Where do we go from here?

    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by
    #40

    @karl261 Thats good news! What you now have is 4 rows high/ 4 colums low (or v.v.). Now short a column with a row and and expect :baby: an interrupt (= keypress). If that is the case, you can create (or copy) a routine to read the key or keys pushed.

    karl261K 3 Replies Last reply
    0
    • AWIA AWI

      @karl261 Thats good news! What you now have is 4 rows high/ 4 colums low (or v.v.). Now short a column with a row and and expect :baby: an interrupt (= keypress). If that is the case, you can create (or copy) a routine to read the key or keys pushed.

      karl261K Offline
      karl261K Offline
      karl261
      wrote on last edited by
      #41

      @AWI yeah, I kind of thought the same. I'll try to have rows high and colls low and see if the interrupt pin finally triggers. I should have some pull up on the interrupt pin. Then I'll need to see if I need any pull up or down on the other lines..,

      Hope I'll get something done this weekend.

      1 Reply Last reply
      0
      • AWIA AWI

        @karl261 Thats good news! What you now have is 4 rows high/ 4 colums low (or v.v.). Now short a column with a row and and expect :baby: an interrupt (= keypress). If that is the case, you can create (or copy) a routine to read the key or keys pushed.

        karl261K Offline
        karl261K Offline
        karl261
        wrote on last edited by
        #42

        @AWI Ok, so far so good. If I connect 4 high wires to rows and 4 low wires to columns (or vice versa, no idea) then the interrupt pin indeed changes to 0. If I connect the interrupt pin of the IC to D3of the Arduino and then both through a pull up of 10 kOhm to Vcc, the interrupt is at 3.3 V. If I press a key it goes down to 0.040 V. That should be enough to read it as low.

        That sounds good, doesn't it? The question is, whether the key library still works...

        AWIA 1 Reply Last reply
        0
        • karl261K karl261

          @AWI Ok, so far so good. If I connect 4 high wires to rows and 4 low wires to columns (or vice versa, no idea) then the interrupt pin indeed changes to 0. If I connect the interrupt pin of the IC to D3of the Arduino and then both through a pull up of 10 kOhm to Vcc, the interrupt is at 3.3 V. If I press a key it goes down to 0.040 V. That should be enough to read it as low.

          That sounds good, doesn't it? The question is, whether the key library still works...

          AWIA Offline
          AWIA Offline
          AWI
          Hero Member
          wrote on last edited by AWI
          #43

          @karl261 Certainly and it can be pretty straight forward from here. Stick to the library you use (this), it contains all you need. You need to let MySensors catch the interrupt (in the sleep function) and have the callback routine (receive) execute char key = kpd.get_key(); as described in the example.

          1 Reply Last reply
          0
          • AWIA AWI

            @karl261 Thats good news! What you now have is 4 rows high/ 4 colums low (or v.v.). Now short a column with a row and and expect :baby: an interrupt (= keypress). If that is the case, you can create (or copy) a routine to read the key or keys pushed.

            karl261K Offline
            karl261K Offline
            karl261
            wrote on last edited by
            #44

            @AWI It does not compile... I get this stupid error again:

            collect2.exe: error: ld returned 5 exit status

            But I don't know what to do with it.

            1 Reply Last reply
            0
            • karl261K Offline
              karl261K Offline
              karl261
              wrote on last edited by
              #45

              current code

              sketch

              #include <Wire.h>
              #include <i2ckeypad.h>
              
              #define ROWS 4
              #define COLS 4
              
              // With A0, A1 and A2 of PCF8574 to ground I2C address is 0x20
              #define PCF8574_ADDR 0x38
              #define PCF8574_PIN_CONFIG 0xf0
              
              
              i2ckeypad kpd = i2ckeypad(PCF8574_ADDR, ROWS, COLS, PCF8574_PIN_CONFIG);
              
              void setup()
              {
                Serial.begin(9600);
              
                Wire.begin();
              
                kpd.init();
                 
              
                Serial.print("Testing keypad/PCF8574 I2C port expander arduino lib\n\n");
              
              //  pcf8574_write(pcf8574_i2c_addr, 0xf0);
              
              }
              
              void loop()
              {
                char key = kpd.get_key();
              
                if(key != '\0') {
                      Serial.print(key);
                }
              }
              

              .cpp

              /*
               *  i2ckeypad.cpp v0.1 - keypad/I2C expander interface for Arduino
               *
               *  Copyright (c) 2009 Angel Sancho <angelitodeb@gmail.com>
               *  All rights reserved.
               *
               *  Original source from keypad v0.3 of Mark Stanley <mstanley@technologist.com>
               *  (http://www.arduino.cc/playground/Main/KeypadTutorial)
               *
               *
               *  LICENSE
               *  -------
               *  This program is free software: you can redistribute it and/or modify
               *  it under the terms of the GNU General Public License as published by
               *  the Free Software Foundation, either version 3 of the License, or
               *  (at your option) any later version.
               *  
               *  This program is distributed in the hope that it will be useful,
               *  but WITHOUT ANY WARRANTY; without even the implied warranty of
               *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
               *  GNU General Public License for more details.
               *  
               *  You should have received a copy of the GNU General Public License
               *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
               *
               *
               *  EXPLANATION
               *  -----------
               *  This library is designed for use with PCF8574, but can possibly be
               *  adapted to other I2C port expanders
               *
               *  Wiring diagrams for PCF8574 and 4x3 keypad can be found under
               *  examples directory. Library runs correctly without cols pull-up
               *  resistors but it's better to use it
               *
               *  You can change pin connections between PCF8574 and keypad under
               *  PIN MAPPING section below
               *
               *  IMPORTANT! You have to call Wire.begin() before init() in your code
               *
               *  ... and sorry for my poor english!
               */
              
              #include "i2ckeypad.h"
              #include <Wire.h>
              
              //extern "C" {
              //  #include "WConstants.h"
              //}
              
              
              /*
               *  PIN MAPPING
               *
               *  Here you can change your wire mapping between your keypad and PCF8574
               *  Default mapping is for sparkfun 4x3 keypad
               */
              
              #define COL0  2  // P2 of PCF8574, col0 is usually pin 3 of 4x3 keypads
              #define COL1  0  // P0 of PCF8574, col1 is usually pin 1 of 4x3 keypads
              #define COL2  4  // P4 of PCF8574, col2 is usually pin 5 of 4x3 keypads
              #define COL3  7  // sorry, don't have a 4x4 keypad to try it
              #define ROW0  1  // P1 of PCF8574, row0 is usually pin 2 of 4x3 keypads
              #define ROW1  6  // P6 of PCF8574, row1 is usually pin 7 of 4x3 keypads
              #define ROW2  5  // P5 of PCF8574, row2 is usually pin 6 of 4x3 keypads
              #define ROW3  3  // P3 of PCF8574, row3 is usually pin 4 of 4x3 keypads
              
              
              /*
               *  KEYPAD KEY MAPPING
               *
               *  Default key mapping for 4x4 keypads, you can change it here if you have or
               *  like different keys
               */
              
              const char keymap[4][5] =
              {
                "123A",
                "456B",
                "789C",
                "*0#D"
              };
              
              
              /*
               *  VAR AND CONSTANTS DEFINITION. Don't change nothing here
               *
               */
              
              // Default row and col pin counts
              int num_rows = 4;
              int num_cols = 3;
              
              // PCF8574 i2c address
              int pcf8574_i2c_addr;
              
              // PCF8574 i2c pin configuration (high low)
              int pcf8574_i2c_pin_cfg;
              
              // Current search row
              static int row_select;
              
              // Current data set in PCF8574
              static int current_data;
              
              // Hex byte statement for each port of PCF8574
              const int hex_data[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
              
              // Hex data for each row of keypad in PCF8574
              const int pcf8574_row_data[4] = 
              {
                hex_data[ROW1] | hex_data[ROW2] | hex_data[ROW3] |
                hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                hex_data[ROW0] | hex_data[ROW2] | hex_data[ROW3] |
                hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                hex_data[ROW0] | hex_data[ROW1] | hex_data[ROW3] |
                hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                hex_data[ROW0] | hex_data[ROW1] | hex_data[ROW2] |
                hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
              };
              
              // Hex data for each col of keypad in PCF8574
              int col[4] = {hex_data[COL0], hex_data[COL1], hex_data[COL2], hex_data[COL3]};
              
              
              /*
               *  CONSTRUCTORS
               */
              
              i2ckeypad::i2ckeypad(int addr)
              {
                pcf8574_i2c_addr = addr;
              }
              
              i2ckeypad::i2ckeypad(int addr, int r, int c, int pinc)
              {
                pcf8574_i2c_addr = addr;
                num_rows = r;
                num_cols = c;
                pcf8574_i2c_pin_cfg = pinc;
              }
              
              
              /*
               *  PUBLIC METHODS
               */
              
              void i2ckeypad::init()
              {
                // All PCF8574 ports high
                pcf8574_write(pcf8574_i2c_addr, pcf8574_i2c_pin_cfg);
              
                // Start with the first row
                row_select = 0;
              }
              
              char i2ckeypad::get_key()
              {
                static int temp_key;
              
                int tmp_data;
                int r;
              
                int key = '\0';
              
                // Search row low
                pcf8574_write(pcf8574_i2c_addr, pcf8574_row_data[row_select]);
              
                for(r=0;r<num_cols;r++) {
                  // Read pcf8574 port data
                  tmp_data = pcf8574_byte_read(pcf8574_i2c_addr);
              
                  // XOR to compare obtained data and current data and know
                  // if some column are low
                  tmp_data ^= current_data;
              
                  // Key pressed!
                  if(col[r] == tmp_data) {
                    temp_key = keymap[row_select][r];
                    return '\0';
                  }
                }
              
                // Key was pressed and then released
                if((key == '\0') && (temp_key != '\0'))    
                {
                  key = temp_key;
                  temp_key = '\0';
                  return key;
                }
              
                // All PCF8574 ports high again
                pcf8574_write(pcf8574_i2c_addr, pcf8574_i2c_pin_cfg);
              
                // Next row
                row_select++;
                if(row_select == num_rows) {
                  row_select = 0;
                }
              
                return key;
              }
              
              /*
               *  PRIVATE METHODS
               */
              
              void i2ckeypad::pcf8574_write(int addr, int data)
              {
                current_data = data;
              
                Wire.beginTransmission(addr);
                Wire.write(data);
                Wire.endTransmission();
              }
              
              int i2ckeypad::pcf8574_byte_read(int addr)
              {
                Wire.requestFrom(addr, 1);
              
                return Wire.read();
              }
              

              .h

              #ifndef i2ckeypad_h
              #define i2ckeypad_h
              
              #include <inttypes.h>
              
              #if ARDUINO >= 100
              #include "Arduino.h"
              #else
              #include "WProgram.h"
              #endif
              
              
              class i2ckeypad {
              public:
                i2ckeypad(int);
                i2ckeypad(int, int, int, int);
                char get_key();
                void init();
                
              private:
                void pcf8574_write(int, int);
                int pcf8574_byte_read(int);
              };
              
              #endif
              
              AWIA 1 Reply Last reply
              0
              • karl261K karl261

                current code

                sketch

                #include <Wire.h>
                #include <i2ckeypad.h>
                
                #define ROWS 4
                #define COLS 4
                
                // With A0, A1 and A2 of PCF8574 to ground I2C address is 0x20
                #define PCF8574_ADDR 0x38
                #define PCF8574_PIN_CONFIG 0xf0
                
                
                i2ckeypad kpd = i2ckeypad(PCF8574_ADDR, ROWS, COLS, PCF8574_PIN_CONFIG);
                
                void setup()
                {
                  Serial.begin(9600);
                
                  Wire.begin();
                
                  kpd.init();
                   
                
                  Serial.print("Testing keypad/PCF8574 I2C port expander arduino lib\n\n");
                
                //  pcf8574_write(pcf8574_i2c_addr, 0xf0);
                
                }
                
                void loop()
                {
                  char key = kpd.get_key();
                
                  if(key != '\0') {
                        Serial.print(key);
                  }
                }
                

                .cpp

                /*
                 *  i2ckeypad.cpp v0.1 - keypad/I2C expander interface for Arduino
                 *
                 *  Copyright (c) 2009 Angel Sancho <angelitodeb@gmail.com>
                 *  All rights reserved.
                 *
                 *  Original source from keypad v0.3 of Mark Stanley <mstanley@technologist.com>
                 *  (http://www.arduino.cc/playground/Main/KeypadTutorial)
                 *
                 *
                 *  LICENSE
                 *  -------
                 *  This program is free software: you can redistribute it and/or modify
                 *  it under the terms of the GNU General Public License as published by
                 *  the Free Software Foundation, either version 3 of the License, or
                 *  (at your option) any later version.
                 *  
                 *  This program is distributed in the hope that it will be useful,
                 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
                 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                 *  GNU General Public License for more details.
                 *  
                 *  You should have received a copy of the GNU General Public License
                 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
                 *
                 *
                 *  EXPLANATION
                 *  -----------
                 *  This library is designed for use with PCF8574, but can possibly be
                 *  adapted to other I2C port expanders
                 *
                 *  Wiring diagrams for PCF8574 and 4x3 keypad can be found under
                 *  examples directory. Library runs correctly without cols pull-up
                 *  resistors but it's better to use it
                 *
                 *  You can change pin connections between PCF8574 and keypad under
                 *  PIN MAPPING section below
                 *
                 *  IMPORTANT! You have to call Wire.begin() before init() in your code
                 *
                 *  ... and sorry for my poor english!
                 */
                
                #include "i2ckeypad.h"
                #include <Wire.h>
                
                //extern "C" {
                //  #include "WConstants.h"
                //}
                
                
                /*
                 *  PIN MAPPING
                 *
                 *  Here you can change your wire mapping between your keypad and PCF8574
                 *  Default mapping is for sparkfun 4x3 keypad
                 */
                
                #define COL0  2  // P2 of PCF8574, col0 is usually pin 3 of 4x3 keypads
                #define COL1  0  // P0 of PCF8574, col1 is usually pin 1 of 4x3 keypads
                #define COL2  4  // P4 of PCF8574, col2 is usually pin 5 of 4x3 keypads
                #define COL3  7  // sorry, don't have a 4x4 keypad to try it
                #define ROW0  1  // P1 of PCF8574, row0 is usually pin 2 of 4x3 keypads
                #define ROW1  6  // P6 of PCF8574, row1 is usually pin 7 of 4x3 keypads
                #define ROW2  5  // P5 of PCF8574, row2 is usually pin 6 of 4x3 keypads
                #define ROW3  3  // P3 of PCF8574, row3 is usually pin 4 of 4x3 keypads
                
                
                /*
                 *  KEYPAD KEY MAPPING
                 *
                 *  Default key mapping for 4x4 keypads, you can change it here if you have or
                 *  like different keys
                 */
                
                const char keymap[4][5] =
                {
                  "123A",
                  "456B",
                  "789C",
                  "*0#D"
                };
                
                
                /*
                 *  VAR AND CONSTANTS DEFINITION. Don't change nothing here
                 *
                 */
                
                // Default row and col pin counts
                int num_rows = 4;
                int num_cols = 3;
                
                // PCF8574 i2c address
                int pcf8574_i2c_addr;
                
                // PCF8574 i2c pin configuration (high low)
                int pcf8574_i2c_pin_cfg;
                
                // Current search row
                static int row_select;
                
                // Current data set in PCF8574
                static int current_data;
                
                // Hex byte statement for each port of PCF8574
                const int hex_data[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
                
                // Hex data for each row of keypad in PCF8574
                const int pcf8574_row_data[4] = 
                {
                  hex_data[ROW1] | hex_data[ROW2] | hex_data[ROW3] |
                  hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                  hex_data[ROW0] | hex_data[ROW2] | hex_data[ROW3] |
                  hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                  hex_data[ROW0] | hex_data[ROW1] | hex_data[ROW3] |
                  hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                  hex_data[ROW0] | hex_data[ROW1] | hex_data[ROW2] |
                  hex_data[COL0] | hex_data[COL1] | hex_data[COL2] | hex_data[COL3],
                };
                
                // Hex data for each col of keypad in PCF8574
                int col[4] = {hex_data[COL0], hex_data[COL1], hex_data[COL2], hex_data[COL3]};
                
                
                /*
                 *  CONSTRUCTORS
                 */
                
                i2ckeypad::i2ckeypad(int addr)
                {
                  pcf8574_i2c_addr = addr;
                }
                
                i2ckeypad::i2ckeypad(int addr, int r, int c, int pinc)
                {
                  pcf8574_i2c_addr = addr;
                  num_rows = r;
                  num_cols = c;
                  pcf8574_i2c_pin_cfg = pinc;
                }
                
                
                /*
                 *  PUBLIC METHODS
                 */
                
                void i2ckeypad::init()
                {
                  // All PCF8574 ports high
                  pcf8574_write(pcf8574_i2c_addr, pcf8574_i2c_pin_cfg);
                
                  // Start with the first row
                  row_select = 0;
                }
                
                char i2ckeypad::get_key()
                {
                  static int temp_key;
                
                  int tmp_data;
                  int r;
                
                  int key = '\0';
                
                  // Search row low
                  pcf8574_write(pcf8574_i2c_addr, pcf8574_row_data[row_select]);
                
                  for(r=0;r<num_cols;r++) {
                    // Read pcf8574 port data
                    tmp_data = pcf8574_byte_read(pcf8574_i2c_addr);
                
                    // XOR to compare obtained data and current data and know
                    // if some column are low
                    tmp_data ^= current_data;
                
                    // Key pressed!
                    if(col[r] == tmp_data) {
                      temp_key = keymap[row_select][r];
                      return '\0';
                    }
                  }
                
                  // Key was pressed and then released
                  if((key == '\0') && (temp_key != '\0'))    
                  {
                    key = temp_key;
                    temp_key = '\0';
                    return key;
                  }
                
                  // All PCF8574 ports high again
                  pcf8574_write(pcf8574_i2c_addr, pcf8574_i2c_pin_cfg);
                
                  // Next row
                  row_select++;
                  if(row_select == num_rows) {
                    row_select = 0;
                  }
                
                  return key;
                }
                
                /*
                 *  PRIVATE METHODS
                 */
                
                void i2ckeypad::pcf8574_write(int addr, int data)
                {
                  current_data = data;
                
                  Wire.beginTransmission(addr);
                  Wire.write(data);
                  Wire.endTransmission();
                }
                
                int i2ckeypad::pcf8574_byte_read(int addr)
                {
                  Wire.requestFrom(addr, 1);
                
                  return Wire.read();
                }
                

                .h

                #ifndef i2ckeypad_h
                #define i2ckeypad_h
                
                #include <inttypes.h>
                
                #if ARDUINO >= 100
                #include "Arduino.h"
                #else
                #include "WProgram.h"
                #endif
                
                
                class i2ckeypad {
                public:
                  i2ckeypad(int);
                  i2ckeypad(int, int, int, int);
                  char get_key();
                  void init();
                  
                private:
                  void pcf8574_write(int, int);
                  int pcf8574_byte_read(int);
                };
                
                #endif
                
                AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by AWI
                #46

                @karl261 I compiled the thing without any errors...
                what I did:

                • All the files (including the library) in (sub)folder Keypad
                • Saved the sketch as Keypad.ino
                • Changed <i2ckeypad.h> to "i2ckeypad.h"

                p.s. a google search showed that the error occurs with many for no obvious reason...

                karl261K 2 Replies Last reply
                0
                • AWIA AWI

                  @karl261 I compiled the thing without any errors...
                  what I did:

                  • All the files (including the library) in (sub)folder Keypad
                  • Saved the sketch as Keypad.ino
                  • Changed <i2ckeypad.h> to "i2ckeypad.h"

                  p.s. a google search showed that the error occurs with many for no obvious reason...

                  karl261K Offline
                  karl261K Offline
                  karl261
                  wrote on last edited by
                  #47

                  @AWI yes, I checked Google too, but there is now real solution. I can go back to 1.6.5r5 maybe this works.

                  1 Reply Last reply
                  0
                  • AWIA AWI

                    @karl261 I compiled the thing without any errors...
                    what I did:

                    • All the files (including the library) in (sub)folder Keypad
                    • Saved the sketch as Keypad.ino
                    • Changed <i2ckeypad.h> to "i2ckeypad.h"

                    p.s. a google search showed that the error occurs with many for no obvious reason...

                    karl261K Offline
                    karl261K Offline
                    karl261
                    wrote on last edited by
                    #48

                    @AWI This makes no sense at all! I did what you did, and it compiled. Then I reverted the steps, to my original setup, and it compiles too. WHY? I would be SO HAPPY if somebody could explain.

                    So the sketch works, but not all keys...

                    1 Reply Last reply
                    0
                    • karl261K Offline
                      karl261K Offline
                      karl261
                      wrote on last edited by karl261
                      #49

                      Ok, the keypad works. All keys. Now I have to check the interrupt.

                      The interrupt is not working any more. At least I don't see it on the Voltmeter. The interrupt pin remains high all the time.

                      I think this is because to get the key pressed, the library is scanning through the pins and writes different high low states to the ports of the pcf. This kills again the interrupt functionality.

                      Yes, if I take out the loop function char key = kpd.get_key(); then the interrupt works again, because the library only writes 0xf0 and then it works. When the library is scanning, it does not work anymore.

                      maybe it is possible to write 0xf0 before going to sleep... Then it won't scan, just wait for the interrupt?

                      With the knew knowledge of 0xf0 writing I could also test the keypad_I2C library.

                      AWIA 1 Reply Last reply
                      0
                      • karl261K karl261

                        Ok, the keypad works. All keys. Now I have to check the interrupt.

                        The interrupt is not working any more. At least I don't see it on the Voltmeter. The interrupt pin remains high all the time.

                        I think this is because to get the key pressed, the library is scanning through the pins and writes different high low states to the ports of the pcf. This kills again the interrupt functionality.

                        Yes, if I take out the loop function char key = kpd.get_key(); then the interrupt works again, because the library only writes 0xf0 and then it works. When the library is scanning, it does not work anymore.

                        maybe it is possible to write 0xf0 before going to sleep... Then it won't scan, just wait for the interrupt?

                        With the knew knowledge of 0xf0 writing I could also test the keypad_I2C library.

                        AWIA Offline
                        AWIA Offline
                        AWI
                        Hero Member
                        wrote on last edited by
                        #50

                        @karl261 A lot of thoughts ;-) My idea is:

                        • write the 0x0f
                        • go to sleep
                        • if interrupt (wake-up) scan the keyboard and get the key
                        • Do whatever you need to do with the key
                        • write the 0x0f
                        • go to sleep
                        • etc...
                        karl261K 1 Reply Last reply
                        0
                        • AWIA AWI

                          @karl261 A lot of thoughts ;-) My idea is:

                          • write the 0x0f
                          • go to sleep
                          • if interrupt (wake-up) scan the keyboard and get the key
                          • Do whatever you need to do with the key
                          • write the 0x0f
                          • go to sleep
                          • etc...
                          karl261K Offline
                          karl261K Offline
                          karl261
                          wrote on last edited by
                          #51

                          @AWI I am trapped between "collect2.exe: error: ld returned 5 exit status" errors and non working sketches. This is the world of pain. I am tempted to give up. It just does not make sense. I like things that do make sense...

                          AWIA 1 Reply Last reply
                          0
                          • karl261K karl261

                            @AWI I am trapped between "collect2.exe: error: ld returned 5 exit status" errors and non working sketches. This is the world of pain. I am tempted to give up. It just does not make sense. I like things that do make sense...

                            AWIA Offline
                            AWIA Offline
                            AWI
                            Hero Member
                            wrote on last edited by
                            #52

                            @karl261 don't give up.. :relaxed: we will get you there. Not much I can do about the 'collect' error but if you post your sketch..

                            karl261K 1 Reply Last reply
                            0
                            • AWIA AWI

                              @karl261 don't give up.. :relaxed: we will get you there. Not much I can do about the 'collect' error but if you post your sketch..

                              karl261K Offline
                              karl261K Offline
                              karl261
                              wrote on last edited by
                              #53

                              @AWI Ok, I got it working somehow, now with the original Keypad_I2C library, because it had the functions ready to write to the pins... But it needs some more tine tuning. And it does not work all the time, sometimes I need to reset the PCF, by disconnecting it from power and then restart the Arduino.

                              In the log below the first try does not work, the second try after reset it works.

                              And after the log the sketch. It sure needs some improvement.

                              Starting sensor (RNNNA-, 2.0.0)
                              TSM:INIT
                              TSM:RADIO:OK
                              TSP:ASSIGNID:OK (ID=8)
                              TSM:FPAR
                              TSP:MSG:SEND 8-8-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=8,pt=1,l=1,sg=0:0
                              TSP:MSG:FPAR RES (ID=0, dist=0)
                              TSP:MSG:PAR OK (ID=0, dist=1)
                              TSP:MSG:READ 99-99-8 s=255,c=3,t=8,pt=1,l=1,sg=0:1
                              TSP:MSG:FPAR RES (ID=99, dist=1)
                              TSM:FPAR:OK
                              TSM:ID
                              TSM:CHKID:OK (ID=8)
                              TSM:UPL
                              TSP:PING:SEND (dest=0)
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=25,pt=1,l=1,sg=0:1
                              TSP:MSG:PONG RECV (hops=1)
                              TSP:CHKUPL:OK
                              TSM:UPL:OK
                              TSM:READY
                              start
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
                              !TSP:MSG:SEND 8-8-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=fail:2.0.0
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=ok:0
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=6,pt=0,l=1,sg=0:M
                              Request registration...
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                              Node registration=1
                              Init complete, id=8, parent=0, distance=1, registration=1
                              Waking up
                              1
                              Good Night
                              Waking up
                              Good Night
                              Waking up
                              Good Night
                              Waking up
                              Good Night
                              Waking up
                              Good Night
                              Waking up
                              Good Night
                              Waking up
                              Starting sensor (RNNNA-, 2.0.0)
                              TSM:INIT
                              TSM:RADIO:OK
                              TSP:ASSIGNID:OK (ID=8)
                              TSM:FPAR
                              TSP:MSG:SEND 8-8-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=8,pt=1,l=1,sg=0:0
                              TSP:MSG:FPAR RES (ID=0, dist=0)
                              TSP:MSG:PAR OK (ID=0, dist=1)
                              TSP:MSG:READ 99-99-8 s=255,c=3,t=8,pt=1,l=1,sg=0:1
                              TSP:MSG:FPAR RES (ID=99, dist=1)
                              TSM:FPAR:OK
                              TSM:ID
                              TSM:CHKID:OK (ID=8)
                              TSM:UPL
                              TSP:PING:SEND (dest=0)
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=25,pt=1,l=1,sg=0:1
                              TSP:MSG:PONG RECV (hops=1)
                              TSP:CHKUPL:OK
                              TSM:UPL:OK
                              TSM:READY
                              start
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
                              !TSP:MSG:SEND 8-8-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=fail:2.0.0
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=ok:0
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=6,pt=0,l=1,sg=0:M
                              Request registration...
                              TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                              TSP:MSG:READ 0-0-8 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                              Node registration=1
                              Init complete, id=8, parent=0, distance=1, registration=1
                              Waking up
                              Good Night
                              Waking up
                              1
                              Good Night
                              Waking up
                              2
                              Good Night
                              Waking up
                              3
                              Good Night
                              Waking up
                              A
                              Good Night
                              Waking up
                              4
                              Good Night
                              Waking up
                              5
                              Good Night
                              Waking up
                              6
                              Good Night
                              Waking up
                              B
                              Good Night
                              Waking up
                              7
                              Good Night
                              Waking up
                              8
                              Good Night
                              Waking up
                              9
                              Good Night
                              Waking up
                              C
                              Good Night
                              Waking up
                              *
                              Good Night
                              Waking up
                              0
                              Good Night
                              Waking up
                              #
                              Good Night
                              Waking up
                              D
                              Good Night
                              
                              #include <Wire.h>
                              #include <Keypad_I2C.h>
                              #include <Keypad.h>
                              #define I2CADDR 0x38
                              
                              #define MY_DEBUG
                              #define MY_RADIO_NRF24
                              #define MY_NODE_ID 8
                              
                              
                              #include <MySensors.h>
                              #include <SPI.h>
                              
                              word temp_pin_state;
                              
                              unsigned long time;
                              
                              
                              unsigned long SLEEP_TIME = 0; // Sleep time between reports (in milliseconds)
                              #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                              #define CHILD_ID 1   // Id of the sensor child
                              
                              const byte ROWS = 4; //four rows
                              const byte COLS = 4; //three columns
                              char keys[ROWS][COLS] = {
                                {'1','2','3','A'},
                                {'4','5','6','B'},
                                {'7','8','9','C'},
                                {'*','0','#','D'}
                              };
                              
                              // Digitran keypad, bit numbers of PCF8574 i/o port
                              byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
                              byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
                              
                              Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574 );
                              
                              void setup(){
                                  Wire.begin( );
                                  kpd.begin( makeKeymap(keys) );
                              //    Serial.begin(9600);
                                  Serial.println( "start" );
                                  pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                                  temp_pin_state = kpd.pinState_set( );
                              }
                              
                              void loop(){
                              
                                  Serial.println("Waking up");
                              
                                  kpd.port_write( temp_pin_state );
                                  wait(100);
                              
                                  time = millis();
                                  while ((millis() - time) < 500) {
                                    char key = kpd.getKey();
                                  
                                    if (key){
                                      Serial.println(key);
                                    }
                                  }
                                  
                              
                                  Serial.println("Good Night");
                                  temp_pin_state = kpd.pinState_set( );
                                  kpd.port_write( 0xf0 );
                                  wait(100);
                                  sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), FALLING, SLEEP_TIME);
                              }
                              
                              1 Reply Last reply
                              0
                              • karl261K Offline
                                karl261K Offline
                                karl261
                                wrote on last edited by
                                #54

                                This sketch works a little bit better... Hm, it sometimes is not reading a key, but it seems to be the loose cable connections?!

                                #include <Wire.h>
                                #include <Keypad_I2C.h>
                                #include <Keypad.h>
                                #define I2CADDR 0x38
                                
                                #define MY_DEBUG
                                #define MY_RADIO_NRF24
                                #define MY_NODE_ID 8
                                
                                
                                #include <MySensors.h>
                                #include <SPI.h>
                                
                                word temp_pin_state;
                                
                                unsigned long time;
                                
                                
                                unsigned long SLEEP_TIME = 0; // Sleep time between reports (in milliseconds)
                                #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                                #define CHILD_ID 1   // Id of the sensor child
                                
                                const byte ROWS = 4; //four rows
                                const byte COLS = 4; //three columns
                                char keys[ROWS][COLS] = {
                                  {'1','2','3','A'},
                                  {'4','5','6','B'},
                                  {'7','8','9','C'},
                                  {'*','0','#','D'}
                                };
                                
                                // Digitran keypad, bit numbers of PCF8574 i/o port
                                byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
                                byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
                                
                                Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574 );
                                
                                void setup(){
                                    Wire.begin( );
                                    kpd.begin( makeKeymap(keys) );
                                //    Serial.begin(9600);
                                    Serial.println( "start" );
                                    pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                                    kpd.port_write( 0xff );
                                    temp_pin_state = kpd.pinState_set( );
                                }
                                
                                void loop(){
                                
                                    Serial.println("Waking up");
                                
                                    kpd.port_write( temp_pin_state );
                                //    wait(100);
                                
                                    time = millis();
                                    while ((millis() - time) < 250) {
                                      char key = kpd.getKey();
                                    
                                      if (key){
                                        Serial.println(key);
                                      }
                                    }
                                    
                                
                                    Serial.println("Good Night");
                                    temp_pin_state = kpd.pinState_set( );
                                    kpd.port_write( 0xf0 );
                                    wait(50);
                                    sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), FALLING, SLEEP_TIME);
                                }
                                
                                Starting sensor (RNNNA-, 2.0.0)
                                TSM:INIT
                                TSM:RADIO:OK
                                TSP:ASSIGNID:OK (ID=8)
                                TSM:FPAR
                                TSP:MSG:SEND 8-8-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                                TSM:FPAR
                                TSP:MSG:SEND 8-8-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                                TSP:MSG:READ 0-0-8 s=255,c=3,t=8,pt=1,l=1,sg=0:0
                                TSP:MSG:FPAR RES (ID=0, dist=0)
                                TSP:MSG:PAR OK (ID=0, dist=1)
                                TSP:MSG:READ 99-99-8 s=255,c=3,t=8,pt=1,l=1,sg=0:1
                                TSP:MSG:FPAR RES (ID=99, dist=1)
                                TSM:FPAR:OK
                                TSM:ID
                                TSM:CHKID:OK (ID=8)
                                TSM:UPL
                                TSP:PING:SEND (dest=0)
                                TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
                                TSP:MSG:READ 0-0-8 s=255,c=3,t=25,pt=1,l=1,sg=0:1
                                TSP:MSG:PONG RECV (hops=1)
                                TSP:CHKUPL:OK
                                TSM:UPL:OK
                                TSM:READY
                                start
                                TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
                                !TSP:MSG:SEND 8-8-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=fail:2.0.0
                                TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=ok:0
                                TSP:MSG:READ 0-0-8 s=255,c=3,t=6,pt=0,l=1,sg=0:M
                                Request registration...
                                TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                                TSP:MSG:READ 0-0-8 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                                Node registration=1
                                Init complete, id=8, parent=0, distance=1, registration=1
                                Waking up
                                Good Night
                                Waking up
                                1
                                Good Night
                                Waking up
                                2
                                Good Night
                                Waking up
                                3
                                Good Night
                                Waking up
                                A
                                Good Night
                                Waking up
                                4
                                Good Night
                                Waking up
                                5
                                Good Night
                                Waking up
                                Good Night
                                Waking up
                                B
                                Good Night
                                Waking up
                                7
                                Good Night
                                Waking up
                                Good Night
                                Waking up
                                9
                                Good Night
                                Waking up
                                C
                                Good Night
                                Waking up
                                *
                                Good Night
                                Waking up
                                0
                                Good Night
                                Waking up
                                #
                                Good Night
                                Waking up
                                D
                                Good Night
                                
                                AWIA 1 Reply Last reply
                                0
                                • karl261K karl261

                                  This sketch works a little bit better... Hm, it sometimes is not reading a key, but it seems to be the loose cable connections?!

                                  #include <Wire.h>
                                  #include <Keypad_I2C.h>
                                  #include <Keypad.h>
                                  #define I2CADDR 0x38
                                  
                                  #define MY_DEBUG
                                  #define MY_RADIO_NRF24
                                  #define MY_NODE_ID 8
                                  
                                  
                                  #include <MySensors.h>
                                  #include <SPI.h>
                                  
                                  word temp_pin_state;
                                  
                                  unsigned long time;
                                  
                                  
                                  unsigned long SLEEP_TIME = 0; // Sleep time between reports (in milliseconds)
                                  #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                                  #define CHILD_ID 1   // Id of the sensor child
                                  
                                  const byte ROWS = 4; //four rows
                                  const byte COLS = 4; //three columns
                                  char keys[ROWS][COLS] = {
                                    {'1','2','3','A'},
                                    {'4','5','6','B'},
                                    {'7','8','9','C'},
                                    {'*','0','#','D'}
                                  };
                                  
                                  // Digitran keypad, bit numbers of PCF8574 i/o port
                                  byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
                                  byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the keypad
                                  
                                  Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574 );
                                  
                                  void setup(){
                                      Wire.begin( );
                                      kpd.begin( makeKeymap(keys) );
                                  //    Serial.begin(9600);
                                      Serial.println( "start" );
                                      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                                      kpd.port_write( 0xff );
                                      temp_pin_state = kpd.pinState_set( );
                                  }
                                  
                                  void loop(){
                                  
                                      Serial.println("Waking up");
                                  
                                      kpd.port_write( temp_pin_state );
                                  //    wait(100);
                                  
                                      time = millis();
                                      while ((millis() - time) < 250) {
                                        char key = kpd.getKey();
                                      
                                        if (key){
                                          Serial.println(key);
                                        }
                                      }
                                      
                                  
                                      Serial.println("Good Night");
                                      temp_pin_state = kpd.pinState_set( );
                                      kpd.port_write( 0xf0 );
                                      wait(50);
                                      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), FALLING, SLEEP_TIME);
                                  }
                                  
                                  Starting sensor (RNNNA-, 2.0.0)
                                  TSM:INIT
                                  TSM:RADIO:OK
                                  TSP:ASSIGNID:OK (ID=8)
                                  TSM:FPAR
                                  TSP:MSG:SEND 8-8-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                                  TSM:FPAR
                                  TSP:MSG:SEND 8-8-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
                                  TSP:MSG:READ 0-0-8 s=255,c=3,t=8,pt=1,l=1,sg=0:0
                                  TSP:MSG:FPAR RES (ID=0, dist=0)
                                  TSP:MSG:PAR OK (ID=0, dist=1)
                                  TSP:MSG:READ 99-99-8 s=255,c=3,t=8,pt=1,l=1,sg=0:1
                                  TSP:MSG:FPAR RES (ID=99, dist=1)
                                  TSM:FPAR:OK
                                  TSM:ID
                                  TSM:CHKID:OK (ID=8)
                                  TSM:UPL
                                  TSP:PING:SEND (dest=0)
                                  TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
                                  TSP:MSG:READ 0-0-8 s=255,c=3,t=25,pt=1,l=1,sg=0:1
                                  TSP:MSG:PONG RECV (hops=1)
                                  TSP:CHKUPL:OK
                                  TSM:UPL:OK
                                  TSM:READY
                                  start
                                  TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
                                  !TSP:MSG:SEND 8-8-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=fail:2.0.0
                                  TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=ok:0
                                  TSP:MSG:READ 0-0-8 s=255,c=3,t=6,pt=0,l=1,sg=0:M
                                  Request registration...
                                  TSP:MSG:SEND 8-8-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                                  TSP:MSG:READ 0-0-8 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                                  Node registration=1
                                  Init complete, id=8, parent=0, distance=1, registration=1
                                  Waking up
                                  Good Night
                                  Waking up
                                  1
                                  Good Night
                                  Waking up
                                  2
                                  Good Night
                                  Waking up
                                  3
                                  Good Night
                                  Waking up
                                  A
                                  Good Night
                                  Waking up
                                  4
                                  Good Night
                                  Waking up
                                  5
                                  Good Night
                                  Waking up
                                  Good Night
                                  Waking up
                                  B
                                  Good Night
                                  Waking up
                                  7
                                  Good Night
                                  Waking up
                                  Good Night
                                  Waking up
                                  9
                                  Good Night
                                  Waking up
                                  C
                                  Good Night
                                  Waking up
                                  *
                                  Good Night
                                  Waking up
                                  0
                                  Good Night
                                  Waking up
                                  #
                                  Good Night
                                  Waking up
                                  D
                                  Good Night
                                  
                                  AWIA Offline
                                  AWIA Offline
                                  AWI
                                  Hero Member
                                  wrote on last edited by
                                  #55

                                  @karl261 it looks good to me. Try to get your connections stable.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  23

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.1k

                                  Posts


                                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • MySensors
                                  • OpenHardware.io
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular