Amaan Javed
Published

M5Stack PC Mouse

M5Stack works as a pc mouse with the help of pyautogui.

IntermediateFull instructions provided1 hour2,368
M5Stack PC Mouse

Things used in this project

Hardware components

ESP32 Basic Core IoT Development Kit
M5Stack ESP32 Basic Core IoT Development Kit
×1
6 DOF Sensor - MPU6050
DFRobot 6 DOF Sensor - MPU6050
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

M5Stack arduino code

Arduino
///////////////////////AMAAN JAVED///////////////////////
#define M5STACK_MPU6050 
#include <M5Stack.h>
float pitch = 0.0F;
float roll  = 0.0F;
float yaw   = 0.0F;
void setup(){
  Serial.begin(115200);
  M5.begin();
  M5.Power.begin();
  M5.IMU.Init();
}
void loop(){
   M5.update();
  M5.IMU.getAhrsData(&pitch,&roll,&yaw);
 if(roll >= 40){
    M5.Lcd.fillScreen(GREEN);
    Serial.println('H');
  }
  if(roll <= -40){
    M5.Lcd.fillScreen(GREEN);
    Serial.println('B');
  }
  if(pitch >= 40){
    M5.Lcd.fillScreen(BLUE);
    Serial.println('L');
  }
  if(pitch <= -40){
    M5.Lcd.fillScreen(BLUE);
    Serial.println('P');
  }
  if(M5.BtnB.wasReleased()){
    Serial.println('C');
  }
  else{
    M5.Lcd.fillScreen(RED);
  }
  delay(1);
}
///////////////////////AMAAN JAVED///////////////////////

PYTHON PROGRAM

Python
#AMAANJAVED
import serial
import pyautogui

m5 = serial.Serial('COM8', 115200, timeout=.1)
x = 0
y = 0
while True:
	da = m5.readline()[:-2]
	if da==b'H':
		x = x + 5
		pyautogui.moveTo(x,y)
	elif da==b'P':
		y = y + 5
		pyautogui.moveTo(x,y)
	elif da==b'B':
		x = x - 5
		pyautogui.moveTo(x,y)
	elif da==b'L':
		y = y - 5
		pyautogui.moveTo(x,y)
	elif da==b'C':
		pyautogui.click(
#AMAANJAVED		

Credits

Amaan Javed

Amaan Javed

19 projects • 4 followers
Student

Comments