One issue is that software serial does not work at 115200 which is the TFMini's xmission rate. Software serial works up to 38400. You can see if that will work.
Here is the code I use to test a TFMini:
#include <HardwareSerial.h>
HardwareSerial SerialTFMini( 2 );
// serial(1) = pin27=RX, pin26=TX
// serial(2) = pin16=RX green, pin17=TX white
void getTFminiData(int* distance, int* strength) {
static char i = 0;
char j = 0;
int checksum = 0;
static int rx[9];
if(SerialTFMini.available())
{
// Serial.println( "tfmini serial available" );
rx[i] = SerialTFMini.read();
if(rx[0] != 0x59) {
i = 0;
} else if(i == 1 && rx…
I have used the following code, for a TFmini on a UNO, Mini Pro, Mega, Due, STM32, and ESP32. I use hardware serial:
TFmini.h file
/*
Arduino driver for Benewake TFMini time-of-flight distance sensor.
by Peter Jansen (December 11/2017)
This code is open source software in the public domain.
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN N…