[I need a node] TF-Luna Lidar Range Finder from Benewake

Hi, I’m new to this software and Arduinos and programming so I was wondering if I could get some help.

Cesar published cesars/tfmini-lidar a while ago. I have a TF-Luna instead of the TFmini and it supposedly is a bit different.

I wrote this in the Arduino IDE software over the last few weeks. It checks if something is in front of the range finder and if it is, it will wait 3 seconds if it still detects in front of the range finder it will play a noise on the speaker. The purpose of this is to warn someone to move if they try parking in front of a radio antenna I have on a mountain top. The end goal is for it to check if there is someone In range. If it is in range, it will wait a bit in case they are just driving past. If they stop it will make a noise.

It has a few minor issues with it. It doesn’t always wait for new information to be sent to the serial log, and it will play the alarm as though the obstruction did not move. After playing the alarm once or twice more than it should, it goes back to normal. I want to make it more reliably reporting information. It seems like it doesn’t wait long enough for the information from the serial to update before it reads the most recent entry, which is sometimes the old entry still so it will just alarm again because of that, and then it will update and stop going off.

I was hoping I could move it to XOD so I could more easily troubleshoot the problem because I am not entirely sure what I’m doing and a visual language may help me.


Here is the code that is working for me right now in Arduino IDE:


This is the example that I’m working from: ArduinoAlarm/Range_Finder.ino at main · MrEndermen/ArduinoAlarm · GitHub


My issue here mainly is I am unsure how to import code directly into XOD, and unsure if that is even possible. I do see that there is a way to make complicated pieces of hardware from scratch by combining different things but I am in the dark on how to do it. I attempted to modify the existing tfmini but it seems to not like what I’m doing. I even tried using the default tfmini stuff that cesar created but it doesn’t seem to work either.

I also tried modifying the content of the “C++ implementation” inside the node by pasting some of my previous projects and the example into it but that seems to be the wrong thing to do.

I was wondering if anyone could help me with this. I am more than happy to put the effort in to learn this myself I just need some guidance as I’m a bit lost at this point and I feel like I’m grasping at straws by just pasting previously functioning work into this currently functioning work and I’m not sure how to move forward.

Any help is greatly appreciated. Thank you very much.

I don’t have a TF-Luna, but it appears that you can communicate with it using both UART and I2C protocols. There is an Arduino library for the TF-Luna which uses the I2C interface:

You could try wrapping this library into a XOD library by following the instructions in the following guides:
https://xod.io/docs/guide/wrapping-arduino-libraries/
https://www.biomaker.org/s/converting-arduino-libraries-to-xod.pdf

Alternatively, you could avoid C++ altogether and use XOD’s I2C nodes to communicate with your TF-Luna, see: I²C Communication Basics — XOD

Thank you very much for these suggestions. I will take a look at this and give it a shot and report my findings.

Thank you for your time.

Ok, so I spent 8 hours on this today and got it working and don’t know how and can’t get it to work again… haha

So there’s a lot to this…
So I needed to know what the name of the hardware was. For that I used this How to Scan I2C Address in Arduino - Arduino Project Hub
It let me know the name of my hardware. From there I put in i2c and a value for the address of the hardware which was 10h. I then set up some stuff like the I²C Communication Basics — XOD guide.

I then found on page 12 of this PDF the Serial port communication protocol data byte format: https://files.seeedstudio.com/wiki/Grove-TF_Mini_LiDAR/res/SJ-PM-TF-Luna-A03-Product-Manual.pdf
From there, I just put in a request for the first 5 bytes, read byte for 1,2,3,4,5. I was able to get it to convert the binary it was receiving into numbers. I wasn’t sure what all the numbers I was getting because there weren’t units by them, and it looked like the temperature readout wasn’t working so I clicked save as and renamed it to "working " and then closed it. I then opened this example to double check the temperature wasn’t damaged because I left it on over the weekend in my office and wasn’t sure if it was busted… ArduinoAlarm/Range_Finder at main · MrEndermen/ArduinoAlarm · GitHub

I then went back into the project and opened it and uploaded it again and it started giving me errors like in this image.

I didn’t record my pin out while I was working on the I2C but I think I had the SDA(RX for UART) pin in 20 and SCL(TX or UART) in 21 on my Elegoo AT2560. I realized that pin 5 needed to be grounded for it to enter i2c mode so I tried that but it doesn’t seem to change. I then added in some “pulse on error” counters and I see it’s erroring on end transmission.

I feel like I was so close and then I lost it… :frowning:
Also, I’m sorry for my multiple posts. I can’t figure out how to share my post with the links without just separating the post into multiple.
Any idea what I did wrong?

I’m not sure, but it looks like your code is “working”, but there is an error when trying to communicate with the temperature sensor. If sending data to sensor fails, it is not too surprising that reading from the sensor will also fail (if it didn’t read the data, it won’t know what data to send). Do you have a spare sensor you can test with? Did you double-check your wiring to make sure nothing has come loose?

I just double-checked with the test code and it looks like it is reading range and flux and temp correctly. I put my hand on its face and it acted as a heat sink and dropped in temp and then when I removed my hand it went back up to 52.

Success of some sort!
@gweimer I checked all my cabling and didn’t see any issues so I disconnected everything and then unplugged the Arduino and plugged it all back together and I finally got it working again! Thanks for that tip.

I’m still not sure what all the numbers mean that I’m getting, but I think I should be able to figure them out after playing around and reading more to understand this part.

I’m fairly certain the first byte is the distance in CM and it looks like the 3rd and maybe 4th bytes are flux or something because that shifts around a ton? I have no idea… haha.

I guess I just have to keep fiddling around with it until I find out what I’m exactly looking at but I think I’m very close.

Don’t know if this will help anyone but this is what I have so far.

From https://s3-us-west-2.amazonaws.com/files.seeedstudio.com/products/101990656/res/SJ-PM-TF-Luna+A01+Product+Manual.pdf:

Byte0 0x59, frame header, same for each frame
Byte1 0x59, frame header, same for each frame
Byte2 Dist_L distance value low 8 bits
Byte3 Dist_H distance value high 8 bits
Byte4 Strength_L low 8 bits
Byte5 Strength_H high 8 bits
Byte6 Temp_L low 8 bits
Byte7 Temp_H high 8 bits
Byte8 Checksum is the lower 8 bits of the cumulative sum of the numbers of the first 8 b