PWR485

The PWR485 is a RS485 interface that can be used to communicate with other devices.

The following are the host’s support for PWR485:

Controller

Status

StampPLC

UiFlow2 Example

Echo

Open the stamplc_ehco_example.m5f2 project in UiFlow2.

This example demonstrates how to utilize PWR485 interfaces by echoing back to the sender any data received on configured PWR485.

By pressing different keys, different characters are sent.

UiFlow2 Code Block:

stamplc_ehco_example.png

Example output:

None

MicroPython Example

Echo

This example demonstrates how to utilize PWR485 interfaces by echoing back to the sender any data received on configured PWR485.

By pressing different keys, different characters are sent.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import PWR485
 9from unit import ISO485Unit
10
11
12label0 = None
13pwr485_0 = None
14iso485_0 = None
15
16
17def btnA_wasClicked_event(state):  # noqa: N802
18    global label0, pwr485_0, iso485_0
19    pwr485_0.write("A")
20
21
22def btnB_wasClicked_event(state):  # noqa: N802
23    global label0, pwr485_0, iso485_0
24    pwr485_0.write("B")
25
26
27def btnC_wasClicked_event(state):  # noqa: N802
28    global label0, pwr485_0, iso485_0
29    pwr485_0.write("C")
30
31
32def setup():
33    global label0, pwr485_0, iso485_0
34
35    M5.begin()
36    label0 = Widgets.Label("label0", 69, 61, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
37
38    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
39    BtnB.setCallback(type=BtnB.CB_TYPE.WAS_CLICKED, cb=btnB_wasClicked_event)
40    BtnC.setCallback(type=BtnC.CB_TYPE.WAS_CLICKED, cb=btnC_wasClicked_event)
41
42    pwr485_0 = PWR485(
43        2,
44        baudrate=115200,
45        bits=8,
46        parity=None,
47        stop=1,
48        tx=0,
49        rx=39,
50        rts=46,
51        mode=PWR485.MODE_RS485_HALF_DUPLEX,
52    )
53    iso485_0 = ISO485Unit(
54        1,
55        port=(4, 5),
56        baudrate=115200,
57        bits=8,
58        parity=None,
59        stop=1,
60        txbuf=256,
61        rxbuf=256,
62        timeout=0,
63        timeout_char=0,
64        invert=0,
65        flow=0,
66    )
67
68
69def loop():
70    global label0, pwr485_0, iso485_0
71    M5.update()
72    if iso485_0.any():
73        label0.setText(str(iso485_0.read()))
74
75
76if __name__ == "__main__":
77    try:
78        setup()
79        while True:
80            loop()
81    except (Exception, KeyboardInterrupt) as e:
82        try:
83            from utility import print_error_msg
84
85            print_error_msg(e)
86        except ImportError:
87            print("please update to latest firmware")

Example output:

None

MicroPython Example

API

class PWR485

class hardware.pwr485.PWR485(id, **kwargs)

Bases: object

Construct a PWR485 object of the given id.

PWR485 class inherits UART class, See hardware.UART for more details.

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from hadrware import PWR485

pwr485_0 = PWR485(2, baudrate=115200, bits=8, parity=None, stop=1, tx=0, rx=39, rts=46, mode=PWR485.MODE_RS485_HALF_DUPLEX)