PaHub: Arduino code for setting port HIGH or LOW



  • Hello,

    I'm new to arduino, not new to programming. I have the M5stack, Pa.Hub and a Grove Relay connected together.

    The example provided on PaHUB is not very clear to me. It shows how to read values but there are no examples for writing values on a specific port of the hub, I can write directly through the I/O pins. However, grove is something new to me.

    Was looking and looking but could not find a syntax example, the closest that I could find was this one: https://forum.m5stack.com/topic/1701/solved-connecting-3-env-units-via-1-to-3-hub-to-m5-stack/8

    Question:
    How are you connecting to the Pa.HUB and accessing your grove extensions from there?

    I just need to turn the voltage HIGH and LOW.

    Many thanks in advance!



  • @maxbrito PaHub Unit is for using multiple I2C Units with identical addresses. You should be aware that not every I2C unit is a simple array of pins (port) which you can set High or Low. For example, the link you mentioned is ENV units and of course, there is no way to treat them as a port where you can set High or Low. You just get the temperature etc values from them.

    Consider using PbHub. However, if your relay unit is ONLY one then you do not need PbHub (and PaHub), just connect your relay unit (grove) to Port B of your M5Stack.



  • @liemph said in PaHub: Arduino code for setting port HIGH or LOW:

    Port B of your M5Stack.

    Thank you so much for explaining. It worked, hooray!! :-)

    Just to help other newbies reading this topic in the future, Port B of the M5Stack is the black port on the device and is only available when you get the base with the battery (Plus). On previous devices this was clearly marked, but it is not the case on this model.

    Then, all you need to do is to use I/O pin 26 on your code. The syntax code provided on "Examples -> M5Stack -> Unit -> Relay" has worked perfectly without modification.

    #include <M5Stack.h>
    
    void setup() {
      M5.begin();
      M5.Power.begin();
      M5.Lcd.clear(BLACK);
      M5.Lcd.setTextFont(4);
      M5.Lcd.setTextColor(YELLOW, BLACK);
      M5.Lcd.setCursor(50, 0, 4);
      M5.Lcd.println(("Relay Example"));
      //disable the speak noise
      dacWrite(25, 0);
      pinMode(26, OUTPUT);
    }
    
    void loop(void) {
      digitalWrite(26, HIGH);
      delay(2500);
      digitalWrite(26, LOW);
      delay(2500);
    }
    

    Again, thank you.



  • @maxbrito Glad to hear that. Yes, sometimes the documentations are not enough especially for people new to M5.