GoPlus2Module

Support the following products:

GoPlus2Module

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from module import GoPlus2Module
 9import time
10
11
12title0 = None
13label0 = None
14label1 = None
15goplus20 = None
16
17
18def setup():
19    global title0, label0, label1, goplus20
20
21    M5.begin()
22    Widgets.fillScreen(0x222222)
23    title0 = Widgets.Title("GoPlus2 Module Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
24    label0 = Widgets.Label("Motor Speed:", 2, 72, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
25    label1 = Widgets.Label("Servo Angle:", 2, 116, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
26
27    goplus20 = GoPlus2Module(0x38)
28    goplus20.set_digital_output(1, 1)
29    goplus20.set_digital_output(2, 1)
30    goplus20.set_digital_output(3, 1)
31
32
33def loop():
34    global title0, label0, label1, goplus20
35    M5.update()
36    label0.setText(str((str("Motor Speed:") + str("180"))))
37    label1.setText(str((str("Servo Angle:") + str("-127"))))
38    goplus20.set_servo_angle(1, 180)
39    goplus20.set_servo_angle(2, 180)
40    goplus20.set_servo_angle(3, 180)
41    goplus20.set_servo_angle(4, 180)
42    goplus20.set_motor_speed(1, -127)
43    goplus20.set_motor_speed(2, -127)
44    time.sleep(4)
45    label0.setText(str((str("Motor Speed:") + str("-180"))))
46    label1.setText(str((str("Servo Angle:") + str("127"))))
47    goplus20.set_servo_angle(1, 0)
48    goplus20.set_servo_angle(2, 0)
49    goplus20.set_servo_angle(3, 0)
50    goplus20.set_servo_angle(4, 127)
51    goplus20.set_motor_speed(1, 127)
52    time.sleep(4)
53
54
55if __name__ == "__main__":
56    try:
57        setup()
58        while True:
59            loop()
60    except (Exception, KeyboardInterrupt) as e:
61        try:
62            from utility import print_error_msg
63
64            print_error_msg(e)
65        except ImportError:
66            print("please update to latest firmware")

UIFLOW2 Example:

example.png

goplus2_core2_example.m5f2

class GoPlus2Module

Constructors

class GoPlus2Module(address)

Initialize the GoPlus2Module.

Parameters:

address (int|list|tuple) – The I2C address of the GoPlus2 module (default is 0x38).

UIFLOW2:

init.png

Methods

GoPlus2Module.set_servo_angle(servo_num, angle) None

Set the angle of the specified servo.

Parameters:
  • servo_num (int) – The number of the servo (1 to 4).

  • angle (int) – The angle to set the servo to (0 to 180 degrees).

UIFLOW2:

set_servo_angle.png

GoPlus2Module.set_servo_pulse_width(servo_num, pulse_width) None

Set the pulse width for the specified servo.

Parameters:
  • servo_num (int) – The number of the servo (1 to 4).

  • pulse_width (int) – The pulse width to set (in microseconds).

UIFLOW2:

set_servo_pulse_width.png

GoPlus2Module.set_motor_speed(motor_num, speed) None

Set the speed of the specified motor.

Parameters:
  • motor_num (int) – The number of the motor (1 or 2).

  • speed (int) – The speed to set (negative for reverse).

UIFLOW2:

set_motor_speed.png

GoPlus2Module.set_digital_output(pin_num, value) None

Set the digital output for the specified pin.

Parameters:
  • pin_num (int) – The number of the pin (1 to 3).

  • value (int) – The value to set (0 or 1).

UIFLOW2:

set_digital_output.png

GoPlus2Module.get_digital_input(pin_num) int

Get the digital input value of the specified pin.

Parameters:

pin_num (int) – The number of the pin (1 to 3).

UIFLOW2:

get_digital_input.png

GoPlus2Module.get_analog_input(pin_num) int

Get the analog input value of the specified pin.

Parameters:

pin_num (int) – The number of the pin (1 to 3).

UIFLOW2:

get_analog_input.png