Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Amaan Javed
Published

M5Stack Video controller with Nodemcu and Python

Using M5Stack and Nodemcu with python to control Youtube vids remotely from a distance.

IntermediateFull instructions provided1 hour1,144
M5Stack Video controller with Nodemcu and Python

Things used in this project

Hardware components

ESP32 Basic Core IoT Development Kit
M5Stack ESP32 Basic Core IoT Development Kit
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
High Brightness LED, White
High Brightness LED, White
×1
Female Header 8 Position 1 Row (0.1")
Female Header 8 Position 1 Row (0.1")
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

M5STACK CODE

Arduino
//////////////////AMAAN JAVED////////////////////
#include <M5Stack.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid ="ESPremote";
const char* password ="12345678";
void setup(){
  M5.begin();  
  for(uint8_t t = 4; t > 0; t--) {
        Serial.printf("[SETUP] WAIT %d...\n", t);
        Serial.flush();
        delay(1000);
    }
      WiFi.mode(WIFI_STA);
      WiFi.disconnect(true);
    WiFi.begin(ssid,password);
    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    M5.Lcd.print(".");
 
    delay(15000);
    M5.Lcd.println("Connected to Server");
    delay(100);
    M5.Lcd.fillScreen(BLUE);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.setTextSize(3);
    M5.Lcd.setCursor(55, 10);
    M5.Lcd.print("M5Stack Remote");
    M5.Lcd.setCursor(3, 35);
    M5.Lcd.println("A CLK 10BACK");
    M5.Lcd.println("B CLK PL/PS");
    M5.Lcd.println("C CLK 10FOR");
    M5.Lcd.println("A 700ms -5VOL");
    M5.Lcd.println("C 700ms +5VOL");      
  }
}
void loop() {
  M5.update();
  if((WiFi.status() == WL_CONNECTED)) {

        HTTPClient http;      
  
  if (M5.BtnA.wasReleased()) {
      http.begin("http://192.168.4.1/A");      
        int httpCode = http.GET();
        M5.Lcd.fillScreen(BLUE);
        M5.Lcd.setTextColor(WHITE);
        M5.Lcd.setTextSize(3);
        M5.Lcd.setCursor(65, 10);
        M5.Lcd.print("10BACK"); 
        http.end();
    } 
    else if (M5.BtnC.wasReleased()) {
      http.begin("http://192.168.4.1/B");      
        int httpCode = http.GET();
        M5.Lcd.fillScreen(BLUE);
        M5.Lcd.setTextColor(WHITE);
        M5.Lcd.setTextSize(3);
        M5.Lcd.setCursor(65, 10);
        M5.Lcd.print("10FOR");
        http.end();
    } 
    else if (M5.BtnB.wasReleased()) {
      http.begin("http://192.168.4.1/C");      
        int httpCode = http.GET();
        M5.Lcd.fillScreen(RED);
        M5.Lcd.setTextColor(WHITE);
        M5.Lcd.setTextSize(3);
        M5.Lcd.setCursor(65, 10);
        M5.Lcd.print("PL/PS");
        http.end();
    } else if (M5.BtnA.wasReleasefor(700)) {
      http.begin("http://192.168.4.1/D");      
        int httpCode = http.GET();
        M5.Lcd.fillScreen(BLUE);
        M5.Lcd.setTextColor(WHITE);
        M5.Lcd.setTextSize(3);
        M5.Lcd.setCursor(65, 10);
        M5.Lcd.print("+5VOL");
        http.end();
    } 
    else if (M5.BtnC.wasReleasefor(700)) {
      http.begin("http://192.168.4.1/E");      
        int httpCode = http.GET();
        M5.Lcd.fillScreen(BLUE);
        M5.Lcd.setTextColor(WHITE);
        M5.Lcd.setTextSize(3);
        M5.Lcd.setCursor(65, 10);
        M5.Lcd.print("-5VOL");
        http.end();
    } 
  } 
}//////AMAAN JAVED/////////////

Nodemcu CODE

Arduino
//////////////////AMAAN JAVED////////////////////
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char *ssid = "ESPremote";
const char *password = "12345678";

ESP8266WebServer server(80);

void handleRoot() {
  server.send(200, "text/html", "<h1>SYSTEM IS WORKING</h1>");
}

void A(){
  Serial.println("A");
  digitalWrite(4,1);
  delay(500);
  digitalWrite(4,0);
}
void B(){
  Serial.println("B");
  digitalWrite(4,1);
  delay(500);
  digitalWrite(4,0);
}
void C(){
  Serial.println("C");
  digitalWrite(4,1);
  delay(500);
  digitalWrite(4,0);
}
void D(){
  Serial.println("D");
  digitalWrite(4,1);
  delay(500);
  digitalWrite(4,0);
}
void E(){
  Serial.println("E");
  digitalWrite(4,1);
  delay(500);
  digitalWrite(4,0);
}
void setup() {
  delay(1000);
  pinMode(4,OUTPUT);
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  server.on("/", handleRoot);
  server.on("/A", A);
  server.on("/", handleRoot);
  server.on("/B", B);
  server.on("/", handleRoot);
  server.on("/C", C);
  server.on("/", handleRoot);
  server.on("/D", D);
  server.on("/", handleRoot);
  server.on("/E", E);
  server.begin();
  digitalWrite(4,1);
  delay(500);
  digitalWrite(4,0);
}
void loop() {
  server.handleClient();
}

PYTHON PROGRAM

Python
import serial
import pyautogui
m5 = serial.Serial('COM5', 115200, timeout=.1)# change port as per your Nodemcu Port
while True:
	da = m5.readline()[:-2]
	if da==b'A'
		pyautogui.press('j')
	if da==b'B'
		pyautogui.press('L')
	if da==b'C'
		pyautogui.press('k')
	if da==b'D'
		pyautogui.press('volumedown')
	if da==b'E'
		pyautogui.press('volumeup')

Credits

Amaan Javed

Amaan Javed

19 projects • 4 followers
Student

Comments