CardKB Hat

The following products are supported:

CardKB Hat

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 hat import CardKBHat
 9from hardware import *
10
11
12label0 = None
13i2c0 = None
14hat_cardkb_0 = None
15
16
17def hat_cardkb_0_pressed_event(kb):
18    global label0, i2c0, hat_cardkb_0
19    label0.setText(str(hat_cardkb_0.get_string()))
20
21
22def setup():
23    global label0, i2c0, hat_cardkb_0
24
25    M5.begin()
26    label0 = Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
27
28    i2c0 = I2C(0, scl=Pin(26), sda=Pin(0), freq=100000)
29    hat_cardkb_0 = CardKBHat(i2c0, 0x5F)
30    hat_cardkb_0.set_callback(hat_cardkb_0_pressed_event)
31
32
33def loop():
34    global label0, i2c0, hat_cardkb_0
35    M5.update()
36    hat_cardkb_0.tick()
37
38
39if __name__ == "__main__":
40    try:
41        setup()
42        while True:
43            loop()
44    except (Exception, KeyboardInterrupt) as e:
45        try:
46            from utility import print_error_msg
47
48            print_error_msg(e)
49        except ImportError:
50            print("please update to latest firmware")

UIFLOW2 Example:

example.svg

stickc_plus2_cardkb_example.m5f2

class CardKBHat

Constructors

class CardKBHat(i2c: I2C, address: int | list | tuple = 0x5F)

Create a CardKBHat object.

Parameters:
  • i2c – I2C object

  • address – the I2C address of the device. Default is 0x5F.

UIFLOW2:

init.png

CardKBHat class inherits CardKBUnit class, See unit.CardKBUnit.Methods for more details.