Parsing serial data from WT61PC to ESP32

Hi everyone,
I’m trying to integrate a WT61PC sensor (from DFrobot: https://wiki.dfrobot.com/Serial_6_Axis_Accelerometer_SKU_SEN0386) into my ESPHome setup. The sensor communicates via serial, and I’m facing some challenges parsing the data to extract the relevant information as decimal values (logging of hex-values already worked).

I’ve tried (unsuccessfully) using the UART component and custom components, but I’m still struggling to get the desired results (guess my experience with ESPhome isn’t enough yet). I’m looking for guidance on how to effectively and reliably parse the serial data and create sensors for the different parameters.

Here’s some information about the sensor and the data format:
Sensor: WT61PC (at DFrobot also called SEN0368)
Required data: acceleration, angular velocity, angle (each on 3 axes)

  1. to be called from a Script Component on the same controller
  2. ideally also callable from another ESPHome controller (via HA?)
  3. displayed at HA

My current setup:
ESP board: Arduino Nano ESP32 (Arduino® Nano ESP32 — Arduino Official Store)

Code examples for Arduino Uno can be found here:
https://github.com/DFRobotdl/DFRobot_WT61PC/tree/master/example/DFRobot_WT61PC, https://github.com/DFRobot/DFRobot_WT61PC/tree/master

I would greatly appreciate any help or suggestions on how to proceed.

Thanks in advance for your support!

Could you post some samples of the logged hex-values?

It looks like processing the data in the UART debug approach will work (link below). The hex values should contain the below “headers” to make sure the input stream is synced up.

Then the bytes[] array returned in the uart debug would need to be processed similar to the library:

so you would have something like this in your lambda:

            if(bytes[7]==0x51)  //check header value
              id(accX_Data).publish_state( ( (bytes[8] << 8) | bytes[9]  ) /32768.0 * 16.0 * 9.8);
              id(accY_Data).publish_state( ( (bytes[10] << 8) | bytes[11]  ) /32768.0 * 16.0 * 9.8);

The array index 7, 8, 9 10, and 11 above are just an example. The actual index would need to be figured out manually from sample data.

1 Like

@mulcmu: Thank you very much. Your info and links were the right starting points!

1 Like