M5stickC Trigger relay on GPIO 26

M5stickC Trigger relay on GPIO 26

Imaginative title right!  Well what else can you say I was asked to “show my workings” for some simple code to switch a relay board on and off using Arduino IDE code and the M5StickC Device.

Now I really dig the M5Stack and all of its offsprings

I  just got hold of the HAT 18650C 

And it’s worth every penny.

Oh, by the way, I don’t have any affiliation  with the company. 

Now back to the story.

It’s quite simple connect up as per the following image 

Setup your Arduino IDE 

Type in the following code

#include <M5StickC.h>

void setup() {
  M5.begin();
    M5.Lcd.setTextFont(4);
  M5.Lcd.setTextColor(YELLOW, BLACK);
  pinMode(26, OUTPUT);
}

void loop(void) {
  digitalWrite(26, HIGH);
  M5.Lcd.setTextFont(5);
  M5.Lcd.setTextColor(YELLOW, BLACK);
  M5.Lcd.drawString("    ", (int)(M5.Lcd.width()/2), (int)(M5.Lcd.height()/2), 2);
  M5.Lcd.drawString("OFF ", (int)(M5.Lcd.width()/2), (int)(M5.Lcd.height()/2), 2);
  delay(2500);
  digitalWrite(26, LOW);
 M5.Lcd.setTextFont(5);
 M5.Lcd.setTextColor(YELLOW, BLACK);
  M5.Lcd.drawString("    ", (int)(M5.Lcd.width()/2), (int)(M5.Lcd.height()/2), 2);
 M5.Lcd.drawString("ON  ", (int)(M5.Lcd.width()/2), (int)(M5.Lcd.height()/2), 2);
  delay(2500);
}

Load and flash the code.

And it should work

If it doesn’t, don’t call me I have moved 🙂 No really just check your typing and wiring not a lot can go wrong. 

 Done

Cheer’s AL