How to connect ESP32 with Laser meter TW10S-UART

chailuz
Posts: 1
Joined: Wed Aug 07, 2024 3:13 pm

How to connect ESP32 with Laser meter TW10S-UART

Postby chailuz » Wed Aug 07, 2024 8:28 pm

Hello, recently I bought this laser meter: https://es.aliexpress.com/item/10050059 ... pt=glo2esp, and I'm using it with a esp32 WROOM.

I tried hard to get a measurement but I couldn't.

The code that i was trying is something like this:

Code: Select all

from machine import UART, Pin
import time

uart1 = UART(1, baudrate=38400, tx=10, rx=9) 
uart1.init(38400, bits=8, parity=None, stop=1)

en_pwr = Pin(22, Pin.OUT)

def get_distance():
    en_pwr.on() 
    time.sleep(1.1) 
    
    command = bytearray([0x01, 0x03, 0x00, 0x0F, 0x00, 0x02, 0xF4, 0x08])
    uart1.write(command)

    time.sleep(0.1)

    response = uart1.read(9)
    print("Sensor response:", response)
    
    en_pwr.off()
    
    if response and len(response) == 9:
        if response[0] == 0x01 and response[1] == 0x03:
            distance = (response[3] << 24) | (response[4] << 16) | (response[5] << 8) | response[6]
            print("Distance (mm):", distance)
            return distance
        else:
            print("Invalid response format")
    else:
        print("Invalid or no response")
    return None

distance = get_distance()
Does anyone have experience with this device? or maybe you know a guide, course, etc. I would really be very grateful.

AK_Vinni
Posts: 1
Joined: Wed Oct 09, 2024 12:44 pm

Re: How to connect ESP32 with Laser meter TW10S-UART

Postby AK_Vinni » Wed Oct 09, 2024 12:46 pm

In my module, the default UART frequency is 9600 bod

Who is online

Users browsing this forum: No registered users and 81 guests