LaserTX Unit

LASER.TX is one of the communication devices among the M5Units family - a Laser emitter with adjustable focal length.It is mainly built with a laser diode Laser communications devices are wireless connections through the atmosphere. They work similarly to fiber-optic links, except the beam is transmitted through free space. While the transmitter and receiver must require line-of-sight conditions, they have the benefit of eliminating the need for broadcast rights and buried cables.

Support the following products:

LaserTXUnit

LaserTX 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 LaserTXUnit
 9import time
10
11
12title1 = None
13label0 = None
14laser_tx_0 = None
15
16
17def setup():
18    global title1, label0, laser_tx_0
19
20    M5.begin()
21    Widgets.fillScreen(0x222222)
22    title1 = Widgets.Title(
23        "LaserTXUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
24    )
25    label0 = Widgets.Label("label0", 2, 116, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
26
27    laser_tx_0 = LaserTXUnit((1, 2), mode=2, id=1)
28    laser_tx_0.init_uart(9600, 8, None, 1)
29
30
31def loop():
32    global title1, label0, laser_tx_0
33    M5.update()
34    if M5.Touch.getCount():
35        laser_tx_0.write("Hello")
36        label0.setText(str("Write Message"))
37        time.sleep(1)
38    else:
39        label0.setText(str("Wait to write Message"))
40
41
42if __name__ == "__main__":
43    try:
44        setup()
45        while True:
46            loop()
47    except (Exception, KeyboardInterrupt) as e:
48        try:
49            from utility import print_error_msg
50
51            print_error_msg(e)
52        except ImportError:
53            print("please update to latest firmware")

LaserRX 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 LaserRXUnit
 9
10
11title0 = None
12laser_rx_0 = None
13
14
15def setup():
16    global title0, laser_rx_0
17
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20    title0 = Widgets.Title(
21        "LaserRXUnit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
22    )
23
24    laser_rx_0 = LaserRXUnit((33, 32), mode=2, id=1)
25    laser_rx_0.init_uart(9600, 8, None, 1)
26
27
28def loop():
29    global title0, laser_rx_0
30    M5.update()
31    if laser_rx_0.any():
32        print(laser_rx_0.read())
33
34
35if __name__ == "__main__":
36    try:
37        setup()
38        while True:
39            loop()
40    except (Exception, KeyboardInterrupt) as e:
41        try:
42            from utility import print_error_msg
43
44            print_error_msg(e)
45        except ImportError:
46            print("please update to latest firmware")

LaserTX UIFLOW2 Example:

example_tx.png

LaserRX UIFLOW2 Example:

example_rx.png

laserrx_core2_example.m5f2

lasertx_cores3_example.m5f2

class LaserTXUnit

Constructors

class LaserTXUnit(port, mode, id)

Initialize the LaserTXUnit with the specified port, communication mode, and UART ID.

Parameters:
  • port (tuple) – A tuple containing pin numbers for TX and RX.

  • mode (int) – Communication mode; use PIN_MODE or UART_MODE.

  • id (int) – UART ID, either 1 or 2.

UIFLOW2:

init.png

Methods

LaserTXUnit.init_uart(baudrate, bits, parity, stop)

Initialize UART communication with specified parameters.

Parameters:
  • baudrate (int) – The baud rate for UART communication. Default is 115200.

  • bits (int) – The number of data bits; 7, 8, or 9. Default is 8.

  • parity (int) – Parity setting; None, 0, or 1. Default is 8.

  • stop (int) – The number of stop bits; 1 or 2. Default is 1.

UIFLOW2:

init_uart.png

LaserTXUnit.write(payload)

Transmit data through UART.

Parameters:

payload – The data to be transmitted via UART.

UIFLOW2:

write.png

LaserTXUnit.on()

Turn on the laser when using PIN_MODE.

UIFLOW2:

on.png

LaserTXUnit.off()

Turn off the laser when using PIN_MODE.

UIFLOW2:

off.png

LaserTXUnit.value(x)

Set the laser state to either on or off using PIN_MODE.

Parameters:

x (bool) – A boolean value; True turns the laser on, False turns it off.