How to make the TFMINI rangefinder talk I2C

PixHawk ok
PixRacer No
Recommand using UBEC

Working.
First the cable.
Then the right config…Pix Mode. Finally
Lastly the port was wrong. Pixracer documentation is a little thin on serial ports.

Works ever so good

1 Like

I am using a pixhawk mini, px4flow, tfmini, and arduino pro mini as well as an I2C splitter for a position control system on my drone. The arduino and tfmini are both powered by UBEC. I have isolated the problem to the arduino board (tfmini parameters are correct and runs on Benewake in standard mode, also px4flow logs are fine). Despite uploading the given INO to the board… In MP the sonarvoltage and sonardistance both show “0” as well as a voltmeter reading of “~0V” at the AD4 and AD5 pinouts on the arduino. I have run other sketches on the arduino and have proven that it is in fact functional. Any tips on where to go from here would be greatly appreciated!

Hello Grant, First , just to make sure;
You have the TFMINI RX-TX connected to Arduino TXD-RXD ?
And the I2C SDA (A4) is connected to Flight Controler SDA an the SCL(A5) to FC SCL ?

1 Like

Please note that I added a new sketch on gitter its called:
BeneWake_TFMINI_I2C_ProMini_Maxbotic_Fast_Blink.ino

Basically it toggle the LED (13) on evry successful TFMINI readings, it is quite fast blinking, so its shows solid red but in the case there is no reading at startup it stays off.

1 Like

Thanks for the reply! I have double and triple checked the connections on the Arduino and FC… I also ran Fast_Blink.ino, which resulted the red light staying off. But, the code on gitter did not compile so I changed the last few lines from this:
void loop() {

readlaser();
for (int i=0; i<100; i++){

}

to this:
void loop() {

readlaser();
for (int i=0; i<100; i++){
}
}

before running.

Considering this alteration did not change the output of the code, what does this tell you about where my problem is?

Oups… sorry, this timing loop was not meant to be there… I just removed it

But once this removed, does it get red ?

1 Like

Thanks. Removed the loop and still no red

Then it looks like TFMINI is not set to proper mode

1 Like

Then it looks like TFMINI is not set to proper mode

1 Like

I have connected my TFMINI to benewake tf, received output that made since, and sent “42 57 02 00 00 00 01 06”.
This is how the benewake window looks after a reboot…

I have also ran a test in which I hard coded a non variable distance measurement into the Arduino sketch. I was able to read my entered value in qgroundcontrol’s analyze widget. The problem is cornered to the output of the TFMINI, but it is almost as if the mode change will not stick. Thanks for your help.

Ok I see you send in cm , try switching to mm

Modify output unit to mm output: 42 57 02 00 00 00 00 1A
Modify output unit to cm output: 42 57 02 00 00 00 01 1A

2 Likes

I changed to mm… still no readings.


I went through the code and added the blink command after condition tests. I indicated which blink tests worked and which didn’t. Any thoughts??

It shows that you are not reading TFMINI serial stream or its not in right format.
I asked before but are you 100% certain that you connect TFMINI TX to Arduino RX ?

Yes I am 100% sure the TFMINI’s TX is connected to the Arduino’s RX

I solved the problem. I substituted my Arducam PRO Mini Atmega328 Development Board with an Arduino Uno and the program emulated correctly. It looks like it was a hardware compatibility problem. Thanks for your patience

1 Like

thanks @ppoirier, now migrated from serial to I2C, a summary of the procedure find on this blog:

Load the sketch BeneWake_TFMINI_I2C_Maxbotic_Outdoor_Limit (for me)
Upload it to the Arduino Pro board (FTDI connected)
A4 is SDA A5 is SCL
Open TF GUI connect TFMINI via FTDI
The command of standard output is 42 57 02 00 00 00 01 06 Arduino Compatible
Modify output unit to mm output: 42 57 02 00 00 00 00 1A
Connect to MP and apply the following settings:
RNGFND_TYPE 7 (LightWare)
RNGFND_ADDR 112 (70 Hex is 112 Dec)
Reboot the FC and it works perfectly

3 Likes

did you try your code with a Pico?

No, does the Pico expose bothe the Serial and the I2C ?

Do not know, just seen this and was impressed by the very small size: https://create.arduino.cc/projecthub/mellbell-electronics/arduino-pico-the-world-s-smallest-arduino-board-24ee0e