🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Extend I/O (EXT_IO) how to read inputs? (arduino)

    Units
    5
    17
    14.1k
    Loading More Posts
    • 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.
    • Marelli7M
      Marelli7
      last edited by

      the example 'EXT_IO_PCA9554PW.ino' only explains the Output mode (ioCon1.digitalWrite(i, LOW);) and works OK!
      But ... I need the unit as additional INput for my Core2.

      I'm using the 5V port with 470 Ohm and a push button connected to input pin 0

      My code doesn't work: the output is allways "HIGH" , even when nothing is connected to the input pins)
      code:
      #include "PCA9554.h"
      ...
      unsigned char in0 = 0; //byte in0 = 0;
      bool status0;
      ...
      void loop() {
      status0 = ioCon1.digitalRead(in0);
      if (status0) Serial.println("HIGH"); else Serial.println("LOW");
      delay(500);
      }

      Could someone please explain what I'm doing wrong here?

      The included code returns TRUE or FALSE when reading &pinNumber
      #define PCA9554_h
      ...
      bool digitalRead(byte &pinNumber);

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by

        Hello @Marelli7

        I think you need to switch the mode to all input before trying to read anything.

        ioCon1.portMode0(ALLINPUT);
        

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • Marelli7M
          Marelli7
          last edited by Marelli7

          That was already in the setup:
          ioCon1.twiWrite(21, 22);
          ioCon1.portMode(ALLINPUT);

          I assume the 0 is not required as ioCon1.portMode(ALLOUTPUT); did work without portMode0()

          1 Reply Last reply Reply Quote 0
          • felmueF
            felmue
            last edited by

            Hello @Marelli7

            my bad. I was looking at this example.

            Have you tried to connect the push button to GND and the input pin?

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            1 Reply Last reply Reply Quote 0
            • Marelli7M
              Marelli7
              last edited by

              Yes I did, and all other pins. The input requires a positive DC voltage, connecting to GND won't help.

              There must be something wrong adressing the input port, even without any wire connected to any port the program reports an input.

              I'll try some other values for in0 in ioCon1.digitalRead(in0);

              I admit that I'm not familiar with (byte &pinNumber). Byte is equal to unsigned char (byte in0=0) didn't work either.
              Using digitalRead(&in0) gives a compile error.

              What value is required for &pinNumber?

              Would be nice to find someone who got this unit working. I can't be the first trying this....

              1 Reply Last reply Reply Quote 0
              • Marelli7M
                Marelli7
                last edited by

                The command portMode(ALLINPUT) doesn't seem to do what is expected.
                All pins are giving 3.3V. Pulling this to GND does not change the status of that portreading

                I wonder if this will work in UIFlow (the UIFlow example indicates that each port can be set to Read or Write individual)

                teastainT 1 Reply Last reply Reply Quote 0
                • teastainT
                  teastain @Marelli7
                  last edited by

                  @marelli7 Hi! Just curious if you have the EXT.IO (Pno. U011 using the PCA9554PW chip) or the newer EXT.IO-2 (Pno. U011-B using the STM32F030 chip) ?
                  Obviously the chips are different! But is would be easy to confuse.
                  I have the Stamp IO with the STM chip and am familiar with only that one.
                  Just trying to help!

                  Cheers, Terry!

                  100% M5Stack addict with several drawers full of product!

                  1 Reply Last reply Reply Quote 0
                  • Marelli7M
                    Marelli7
                    last edited by

                    Terry, thanks !!

                    I'm using the EXT.IO PCA. The IO2 with the STM seems not (yet) available in the Netherlands.
                    I decided to focus on some other units rather then spending frustrating hours with this ....

                    And Yes, I also do have the Stamp I/O with the STM chip. So it would be very helpful to point me to some arduino sketches. I'll check the examples codes also.

                    Do you have, by any chance, a working sketch for the rotary encoder (UNIT Encoder) for the Core2 -also with the STM-chip?
                    I couldn't get this encoder working on my Core2 and that's why I/m trying to read the encoder using External IO. But would be nice to get both (stamp & encoder) working

                    (I'm a newbe to M5Stack but quite familiar with the ESP32)

                    teastainT 1 Reply Last reply Reply Quote 0
                    • teastainT
                      teastain @Marelli7
                      last edited by teastain

                      @marelli7 When I got the StampIO with STM I was disappointed that each chip could only be used in one mode, "All Pin Mode". user felmue made a brilliant but astonishingly simple edit to the actual M5Stack StampIO library which was approved by M5Stack. It allows each pin to be a different mode, such as Pin1 Input, Pin2 Output, etc.
                      https://imgur.com/EduKPmV

                      #include <M5Stack.h>
                      #include <M5_EXTIO2.h>
                      M5_EXTIO2 extio;
                      void setup() {
                      M5.begin();
                      while (!extio.begin(&Wire, 21, 22, 0x45)) {
                      Serial.println("extio Connect Error");
                      delay(100);
                      }
                      extio.setPinMode(1, RGB_LED_MODE);
                      extio.setPinMode(0, DIGITAL_OUTPUT_MODE);
                      }

                      void loop() {
                      extio.setLEDColor(1, 0x0f << (8)); //RGB sk6812 type
                      delay(1000);
                      extio.setLEDColor(1, 0x0f << (16));
                      extio.setDigitalOutput(0, HIGH); // standard mini LED with resistor
                      delay(1000);
                      extio.setDigitalOutput(0, LOW);
                      delay(1000);
                      }

                      Otherwise, sorry, I don't have any Encoder code!
                      Neat profile picture, tho' !

                      Cheers, Terry!

                      100% M5Stack addict with several drawers full of product!

                      1 Reply Last reply Reply Quote 0
                      • F
                        frexetat
                        last edited by

                        @teastain said in Extend I/O (EXT_IO) how to read inputs? (arduino):

                        @marelli7
                        Hello,
                        did you ever figured it out, I am trying to do the same thing but no luck.
                        It's quite crazy I couldn't find anyone talking about this online !!

                        thanks

                        teastainT 1 Reply Last reply Reply Quote 0
                        • Marelli7M
                          Marelli7
                          last edited by

                          @frexeta I don't think so. It's 5 months ago and skipped the 'project'

                          1 Reply Last reply Reply Quote 0
                          • teastainT
                            teastain @frexetat
                            last edited by

                            @frexetat I do not have a EXT.IO PCA type, only EXTIO2 with STM, but...could I add: the demo program does not seem to have a "read" in the loop and you must select all pin mode input OR output, which is inconvenient.
                            these two links from M5Stack use different sketches!

                            https://github.com/m5stack/M5-ProductExampleCodes/blob/master/Unit/EXTIO/Arduino/EXT_IO/EXT_IO.ino

                            https://github.com/m5stack/M5Stack/blob/master/examples/Unit/EXT_IO_PCA9554PW/EXT_IO_PCA9554PW.ino

                            Also It is common in controls to use a pull up resistor on the input, maybe 1000 ohms? and connect the switch from the input to ground. Pressing the switch drags the input low, called active low and the signal name is usually "overscored" or preceded with a / symbol: "/sw1".
                            As I said last year I do not have the PCA type to test!

                            ioCon1.portMode0(ALLOUTPUT); //Set the port as all output in the sketch...maybe set ioCon1.portMode0(ALLINPUT); //Set the port as all input ?

                            Cheers, Terry!

                            100% M5Stack addict with several drawers full of product!

                            F 1 Reply Last reply Reply Quote 0
                            • F
                              frexetat
                              last edited by

                              Hey guys thanks for your reply.
                              I ended up not using this library at all.
                              In my case I need all the pins to be inputs which is convenient.

                              here is my code if its helpful for anyone ( what I get is one binary number containing all the pins , which I turn into a decimal (0-255) and then use masking (& 128, & 64 ..etc to get all separate button's values):

                              #include <Wire.h>
                              #include <M5StickCPlus.h>

                              #define IOEXT_addr 0x27
                              #define CONFIGPORT0 0x03
                              #define ALLINPUT 0xFF

                              byte rdata = 0xFF;

                              void setup() {
                              M5.begin();
                              Wire.begin();

                              Wire.beginTransmission(IOEXT_addr);

                              Wire.write(CONFIGPORT0);
                              Wire.write(ALLINPUT);
                              Wire.endTransmission();

                              delay (50);

                              Wire.beginTransmission(IOEXT_addr);
                              Wire.write((uint8_t)0);
                              Wire.endTransmission();
                              }

                              void loop() {

                              Wire.requestFrom(IOEXT_addr,1);

                              if (Wire.available()) rdata = Wire.read();

                              Serial.println (String(rdata, DEC));

                              }

                              1 Reply Last reply Reply Quote 0
                              • F
                                frexetat @teastain
                                last edited by

                                @teastain it happens that calling the function to read just would give always 1 no matter what. Didn't matter if it was in output / INPUTALL or anything.
                                I believe there is something wrong with the read function in this library.

                                The code I shared works without any issues.
                                Pull up resistors are not needed, I don't have any and it works just fine ::)

                                1 Reply Last reply Reply Quote 0
                                • F
                                  frexetat
                                  last edited by

                                  adding a little note :
                                  the command for ALLINPUTS is hex 0xFF which is 0b11111111 in binaries
                                  I am quite sure all the 1 are the pins (pin0 being on the right). with 1 being input and 0 being output.
                                  So 0b11111110 ( hex 0xFE) would probably be all inputs except pin 0 as output etc
                                  and hex (0x0) is 0b00000000 and actually correspong to the value of ALLOUTPUTS in the other library ...

                                  teastainT 1 Reply Last reply Reply Quote 1
                                  • teastainT
                                    teastain @frexetat
                                    last edited by

                                    @frexetat Screw the library, we'll just put the raw code in-line!
                                    Hardcore, love it.
                                    Terry

                                    Cheers, Terry!

                                    100% M5Stack addict with several drawers full of product!

                                    1 Reply Last reply Reply Quote 1
                                    • ajb2k3A
                                      ajb2k3
                                      last edited by

                                      I've been working in raw I2C write and M5Stack have told me that there is an issue with digital read functions with the EXTIO2 and the Stamp EXTI/O but won't tell me where the error is?
                                      Be careful when reading and writing to the EXT2 StampEXT as it is very easy to corrupt the I2C address register.

                                      UIFlow, so easy an adult can learn it!
                                      If I don't know it, be patient!
                                      I've ether not learned it or am too drunk to remember it!
                                      Author of the WIP UIFlow Handbook!
                                      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                                      1 Reply Last reply Reply Quote 1
                                      • First post
                                        Last post