Joystick v1.1

SKU:U024-C

描述

Joystick是一款摇杆控制输入单元,采用I2C通信接口,支持三轴控制信号输入(X/Y轴偏移模拟量输入,Z轴按键数字量输入)。适用于游戏/机器人控制等应用场景。

产品特性

  • 三轴输入:
    • X/Y轴偏移模拟量输入
    • Z轴按键数字量输入
  • 2x LEGO 兼容孔
  • 开发平台: Arduino, UIFlow(Blockly, Python)

包含

  • 1x Joystick Unit
  • 1x HY2.0-4P线缆

应用

  • 游戏控制器
  • 机器人远程控制

规格参数

规格 参数
主控MCU MEGA8A
通讯协议 I2C:0x52
X、Y轴偏移输出值 0-255
Z轴按键输出值 0/1
净重 11g
毛重 27g
产品尺寸 48 * 24 * 32mm
包装尺寸 75 * 45 * 30mm

EasyLoader

EasyLoader是一个简洁快速的程序烧录器,其内置了一个产品相关的案例程序,通过简单步骤将其烧录至主控,即可进行一系列的功能验证.

案例描述:
显示摇杆XY数据及按钮状态.

Download Windows Version Easyloader Download MacOS Version Easyloader

管脚映射

  • JOYSTICK
M5CORE - PORT A G21 G22 5V GND
JOYSTICK SDA SCL VCC GND

原理图

通讯协议

  • 协议类型I2C
  • I2C Address: 0x52

JOYSTICK REG 0x52

REG len description return values
0x52 3 读取摇杆状态 [0] X VALUE
[1] Y VALUE
[2] BTN STATUS

项目案例

Gamepad (prototype) based on M5StickC (ESP32 Pico) with I2C joystick module, dual button unit, and Bluetooth Low Energy connectivity.

案例程序

Arduino


#include <M5Stack.h>

#define JOY_ADDR 0x52 //define Joystick I2C address.  定义摇杆的I2C地址

void setup() {
  M5.begin();
  M5.Power.begin();
  M5.Lcd.setCursor(70, 0, 4);
  M5.Lcd.println(("Joystick Test"));
  dacWrite(25, 0);  //disable the speak noise.  禁用语音噪音
  Wire.begin(21, 22, 400000);
}

char data[100];
void loop() {
  static uint8_t x_data,y_data,button_data;
  Wire.requestFrom(JOY_ADDR, 3);  //Request 3 bytes from the slave device.  向从设备请求3个字节
  if (Wire.available()) { //If data is received.  如果接收到数据
    x_data = Wire.read();
    y_data = Wire.read();
    button_data = Wire.read();
    sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data);
    Serial.print(data);

    M5.Lcd.setCursor(100, 50, 4);
    M5.Lcd.printf("X:%d      ",x_data);
    M5.Lcd.setCursor(100, 80, 4);
    M5.Lcd.printf("Y:%d      ",y_data);
    M5.Lcd.setCursor(100, 110, 4);
    M5.Lcd.printf("B:%d      ",button_data);
  }
  delay(200);
}

UIFlow

功能说明

  • Get X 返回X轴的数据

  • Get Y 返回Y轴的数据

  • Get is pressed 返回按键的值

  • Get Reverse X 返回X轴反向数据

  • Get Reverse Y 返回Y轴反向数据

使用示例: