M5 Stack Catch Unit (SG92R) Documentation
The M5 Stack Catch Unit (SG92R) is a robotic servo controller module designed for the M5 Stack ecosystem. It integrates a high-torque SG92R servo motor and a built-in switching circuit, allowing for precise control and monitoring of robotic mechanisms. This module is ideal for IoT projects that require precise motion control, such as robotics, automation, and robotic arms.
Servo Motor: SG92R
Operating Voltage: 3.3V - 6V
Torque: 1.2 kgcm
Speed: 0.12 sec/60
Communication Protocol: I2C
Dimensions: 54.2 x 25.4 x 12.8 mm
The M5 Stack Catch Unit (SG92R) can be controlled using the M5 Stack's UIFlow or Arduino IDE. The module communicates with the microcontroller using the I2C protocol.
### Example 1: Basic Servo Control using UIFlow
This example demonstrates how to control the servo motor using UIFlow.
```python
import m5
# Initialize the Catch Unit module
catch_unit = m5.CatchUnit(0x1E)
# Set the servo motor to 0
catch_unit.servo_write(0)
# Wait for 1 second
m5.delay(1000)
# Set the servo motor to 90
catch_unit.servo_write(90)
# Wait for 1 second
m5.delay(1000)
# Set the servo motor to 180
catch_unit.servo_write(180)
```
### Example 2: Servo Control with Arduino IDE
This example demonstrates how to control the servo motor using the Arduino IDE.
```cpp
#include <M5 CatchUnit.h>
// Define the Catch Unit module
M5_CatchUnit catchUnit;
void setup() {
// Initialize the Catch Unit module
catchUnit.begin();
}
void loop() {
// Set the servo motor to 0
catchUnit.servoWrite(0);
delay(1000);
// Set the servo motor to 90
catchUnit.servoWrite(90);
delay(1000);
// Set the servo motor to 180
catchUnit.servoWrite(180);
delay(1000);
}
```
### Example 3: Advanced Servo Control using MicroPython
This example demonstrates how to control the servo motor using MicroPython and implement a more complex motion sequence.
```python
import machine
import utime
# Initialize the Catch Unit module
catch_unit = machine.I2C(sda=machine.Pin(21), scl=machine.Pin(22), freq=400000)
catch_unit addr = 0x1E
# Define a function to set the servo motor position
def set_servo_position(pos):
catch_unit.writeto(0x1E, b'x00' + bytes([pos]))
# Define a motion sequence
motion_sequence = [
(0, 1000), # 0, 1 second
(90, 500), # 90, 0.5 seconds
(180, 1000), # 180, 1 second
(0, 500) # 0, 0.5 seconds
]
# Run the motion sequence
for pos, delay_ms in motion_sequence:
set_servo_position(pos)
utime.sleep_ms(delay_ms)
```
These code examples demonstrate the basic usage of the M5 Stack Catch Unit (SG92R) module in various programming environments. The module can be used in more complex IoT projects, such as robotic arms, robotic grippers, and automation systems.