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

    Assistance Request: M5Core2 and 4-Relay Unit

    Scheduled Pinned Locked Moved General
    3 Posts 2 Posters 1.6k Views
    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.
    • W Offline
      wanderingchimp
      last edited by

      Good morning! I am trying to perform a simple test by flashing the LEDs and cycling the relays on a 4-relay unit board, and for some reason, the magic isn't happening, below is my code:

      #include <M5Core2.h>
      #include "Unit_4RELAY.h"
      
      
      UNIT_4RELAY relay;
      
      void setup() {
      
        // Init M5Core2 And the I2C port(21,22).
        M5.begin(true,false,true,true);             
      
       // Draw screen
        M5.Lcd.setCursor(0, 10);
        M5.lcd.setTextSize(2);
        M5.lcd.setTextColor(GREEN);
        M5.Lcd.printf("Hello World!");
      
        // Relay
        relay.Init(1);
      
            
        
        
      }
      
      void loop() {
      
      
           relay.relayAll(1);
           relay.ledAll(1);
      
           delay(2500);
      
           relay.relayAll(0);
           relay.ledAll(0);
      }
      

      Any reason as to why this wouldn't work? The device is plugged into Port A on the M5Core2. Additionally, using wire scan, I am able to detect the device successfully on the I2C bus. I based my code off of this:

      https://github.com/m5stack/M5Unit-RELAY/blob/master/examples/Unit_4RELAY_M5Core2/Unit_4RELAY_M5Core2.ino

      Additionally, this is the specific module I am using:

      https://shop.m5stack.com/products/4-relay-unit

      Thanks in advance!

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

        Hello @wanderingchimp

        the example is missing a relay.begin() call before the relay.init(). I've created a PR for that.

        Also for me it only works if I call relayAll() only. If I call both relayAll() and ledAll() as in your example it doesn't work for me.

        Thanks
        Felix

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

        W 1 Reply Last reply Reply Quote 0
        • W Offline
          wanderingchimp @felmue
          last edited by

          @felmue

          Thanks for the help! I've got it working now :)

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post