Grove2Grove Unit

UNIT-GROVE2GROVE is a Grove expansion Unit with On/Off Control + Current Meter functions. On/Off control adopts switch value, Current meter is 0 - 3.3V analog signal.

Support the following products:

Grove2GroveUnit

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 unit import Grove2GroveUnit
 9
10
11label0 = None
12label1 = None
13grove2grove_0 = None
14
15
16def setup():
17    global label0, label1, grove2grove_0
18
19    M5.begin()
20    Widgets.fillScreen(0x222222)
21    label0 = Widgets.Label("current:", 50, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
22    label1 = Widgets.Label("label1", 150, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
23
24    grove2grove_0 = Grove2GroveUnit((8, 9))
25    grove2grove_0.on()
26
27
28def loop():
29    global label0, label1, grove2grove_0
30    M5.update()
31    label1.setText(str(grove2grove_0.get_current()))
32
33
34if __name__ == "__main__":
35    try:
36        setup()
37        while True:
38            loop()
39    except (Exception, KeyboardInterrupt) as e:
40        try:
41            from utility import print_error_msg
42
43            print_error_msg(e)
44        except ImportError:
45            print("please update to latest firmware")

UIFLOW2 Example:

example.png

cores3_grove2_grove_example.m5f2

class Grove2GroveUnit

Constructors

class Grove2GroveUnit(port: tuple)

Initialize the Grove2GroveUnit.

参数:

port (tuple) – The port to which the Grove2GroveUnit is connected. port[0]: adc pin, port[1]: grove pin.

UIFLOW2:

init.png

Methods

Grove2GroveUnit.get_current() float

Get the current of the sensor.

返回:

The current of the sensor.

UIFLOW2:

get_current.png

Grove2GroveUnit.on() None

Turn on the grove.

UIFLOW2:

on.png

Grove2GroveUnit.off() None

Turn off the grove.

UIFLOW2:

off.png

Grove2GroveUnit.set_en(state: int) None

Set the state of the grove.

参数:

state (int) – The state of the grove.

UIFLOW2:

set_en.png