LaserRX Unit
LASER.RX is one of the communication devices among M5Units, a Laser receiver. It is mainly built with a laser transistor. 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. Laser communications systems can be easily deployed since they are inexpensive, small, low power and do not require any radio interference studies. Two parallel beams are needed, one for transmission and one for reception. Therefore we have a LASER.TX in parallel.
Support the following products:
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:
LaserRX UIFLOW2 Example:
class LaserRXUnit
Constructors
Methods
- LaserRXUnit.init_uart(baudrate, bits, parity, stop)
Initialize UART communication with specified parameters.
- Parameters:
UIFLOW2:
- LaserRXUnit.read(byte)
Read data from UART. Optionally specify the number of bytes to read.
- Parameters:
byte – The number of bytes to read. If None, reads all available data.
- Returns:
The data read from UART or None if no data is available.
UIFLOW2:
- LaserRXUnit.readline()
Read a single line of data from UART.
- Returns:
The line read from UART or None if no data is available.
- LaserRXUnit.any()
Check if there is any data available in UART buffer.
- Returns:
True if data is available; otherwise, False.
UIFLOW2:
- LaserRXUnit.value()
Get the current value of the input pin when using PIN_MODE.
- Returns:
The value of the pin (0 or 1).