SEN0524 ToF Sensor. Can't read the sensor results!

userHead KostasGeo 2022-10-11 21:18:56 1383 Views4 Replies

Hi, I am relatively new to using microcontrollers and I have been struggling for quite a while now to get the sensor to output even the slightest of data. After some debugging, i found out, that the code fails to verify the headers in the data, as represented below:


if(dat[i]==0x57&&dat[i+1]==0&&dat[i+2]==0xff&&dat[i+3]==0) {…}  (this if-check does not pass)


This piece of code is taken from the example at the wiki here.


I am using the ESP32-WROOM-32D, of which the pinout sheet can be found here (pages 8,9). I am sure i have connected the RX,TX pins at the right places and i can read through Serial2.available() (I am using U2RXD, U2TXD), 256 bytes of data transmitted. Besides that, i think it may be important to include that, after monitoring Serial2.available() I'm seeing that after a while it gets stuck to 31 bytes and so, the program now refuses to pass the first check:


if(mySerial.available()>=32), where MySerial=Serial2


Any help would be greatly appreciated.



2022-10-29 18:28:50

Hi and sorry for the late reply. I've been chatting with Waveshare directly through email and still could not find the issue; they told me to message their Sales team for a replacement…which is a tedious process, since they reply after about 3-4 days per email. I have ditched the esp for now and i have had problems with their software. The device still connects and the software receives data, but no matter what i try, the device always refuses to be recognized(which can be done though a button) and the data itself(as the waveshare assistant referred as) is “strange”. Here are the last logs i got from the software and sent through email.


The first log file referres to the attemps of me pressing the recognize button. “Changing the baudrate from 2000000 to <number>”, still have no idea why happens, since the baudrate is correctly set in the software. Funny thing is, when trying to match the requested baudrate(like 921600 written in the log), this happens.



[10.29 13:22:10.704]  90 ms elapsed after open serialport[10.29 13:22:14.425]  serialport error occurred: UnsupportedOperationError[10.29 13:22:14.425]  try change baudrate from  2000000  to  3000000 ,error occured: "UnsupportedOperationError"[10.29 13:22:14.526]  "in NSerialPort::write ,error occured:UnsupportedOperationError"[10.29 13:22:14.841]  try change baudrate from  2000000  to  921600 ,error occured: "UnsupportedOperationError"


…exactly the same thing. 



userHeadPic KostasGeo
2022-10-24 21:47:40

Hey,I had the same issue. You just need to change the baud rate of the sensor too to 115200 because it is much bigger when default. I used the waveshare's range finder assistant to change it but maybe any serial to usb program could do it. I now have the same issue with SEN0336.

userHeadPic NikosMavrikis
2022-10-18 16:45:41

Hi! Could you please provide the dat array read by the esp32 serial port?

userHeadPic jenna
2022-10-11 21:38:42

Sorry, the pinout sheet is here

userHeadPic KostasGeo