TFmini Room Scan HELP PLEASE

Hi

I am trying to make a 3D room scanner as a project with a recent purchase of my TFmini UART edition and have kinda hit a brick wall with it. I am using processing to plot the 3D coordinates that I have created by converting for spherical to cartesian on the Arduino then sending this over using a serial connection to processing to visualize this point cloud. The main problem is that I can't get a stable enough connection with the TFmini to scan only a few scans before reading a constant reading of either -3 or 65335 which I have seen as an error online but now solution to yet.

I plan to use a ESP32 later on but I thought it may be easier to do it on the mega as a first prototype.

Im currently using:
TFmini
Arduino mega 2560
2 x SG 90 Servo motor
3D printed tilt scan (of Thingiverse)
Logic level converter

My questions
[1] Will this idea work with the existing setup or should I start a new?
[2] Why does the code consistently show -3 which only resets after rebooting the Arduino mega.

My code:

#include <Servo.h> // Library used for servo motors with predefined functions and methods
#include <SoftwareSerial.h>
#include "TFMini.h"

Servo tiltServo; // Connceting Servos to libary
Servo panServo;

//Variables initialised here so that they can be used later on.
int tiltPos = 0; 
int panPos = 0;

int distance;
long duration;

int x,y,z;
float deg2rad = 3.14159265 / 180.0;


SoftwareSerial mySerial(10,11);
TFMini tfmini;

void setup() {

//Serial Connection started for communcation with processing
Serial.begin(115200);



mySerial.begin(TFMINI_BAUDRATE);
tfmini.begin(&mySerial); 



//Defining the pins of the two servos in use 
tiltServo.attach(9);
panServo.attach(6);





/* For loops used to tilt from 90(down) degrees to 0(up).
*  For each tilt degree the other servo pans from 0 to 180 degrees getting a distance value for each degree.
*  Every value is turned into Cartesian values from spherical.
*   Then transmitted through the serial USB connection then into processing.
*/
for(tiltPos = 45; tiltPos>=0; tiltPos--){
 for(panPos = 0; panPos <=180; panPos++){
   panServo.write(panPos);

   float dist = get_DISTANCE();
   float theta = deg2rad * (panPos);
   float phi = deg2rad * (tiltPos) ;
   double x = dist*sin(phi)*cos(theta);
   double y = dist*sin(phi)*sin(theta);
   double z = dist*cos(phi);

   
   Serial.println(String(x, 5) + " " + String(y, 5) + " " + String(-z, 5));
   Serial.println(dist);
   
   delay(25);
 }
 tiltServo.write(tiltPos);
 delay(25);
}


}

/*
* Function has a intger ouput that will go into the dist variable above.
* Sends out ultrasonic waves (so we can’t hear them) and then times how long it takes to read it again.
*  Then using distance = speed * time then divding by 2 as it has travelled from the sensor and back again a reading is observed.
*/

int get_DISTANCE(){
uint16_t distance = int(tfmini.getDistance());
//Serial.println(distance);

return distance;
}

void loop() {
// put your main code here, to run repeatedly:

}

Picture

Related? Or at least remarkably similar! Two threads about the same problem of a sensor I've not even heard of is very unusual to say the least.

Please edit your post to add code tags ("</>" button), as described in "How to use this forum".

Software serial doesn't work well. Since you have a Mega, use one of the other hardware serial ports instead.

wvmarle:
Related? Or at least remarkably similar! Two threads about the same problem of a sensor I've not even heard of is very unusual to say the least.

I was the guy who posted this other thread, and this is super weird as I could barely find anything related to this sensor anywhere.

I can probably help you with getting consistent readings out of your TFMini. If you haven't already, I would use the example code "BasicReading". In Arduino IDE, go to Tools>Manage Libraries>search for "tfmini"
and download the one by Peter Jansen. Then go to your example sketches and use BasicReading. If you still get errors, it may be because these sensors are picky about connections, and you should try soldering directly to the board.

Post your updates!

Hi, thanks for the quick responses.
I have played around with using different power sources with the basic read sketch in the TFmini library and while the Arduino mega is connected to a wall power supply it's a lot more stable with less 65k error coming up, I'm assuming from what I read from the manual this is due to the USB power not giving enough amperage for the device to work properly, but it does still happen while connected to the wall if I prod the wire a bit. I will try to solder the pins and logic level converter tomorrow. Do you think a battery will provide sufficient current later on if I plan to use an ESP32 later on?

Hi, sorry for replying to such an old post.
The thing is, I'm doing almost exactly the same project, just on one axis, and am having the same problems. Or rather just to clarify, it's not that some of the received distances are 65k, it's that it switches over at some point to just displaying the error and never goes back. I'm not sure if this is what you have been experiencing. I've been searching around and trying fixes, but haven't been able to get any improvements.

Have you been able to get it working, and if so, might you be able to describe how? Also at an impasse here.

Hi Aton_freson,
I am currently working on a 3D LIDAR Scanning project with the tfmini and had the same problem as you (stuck with 65k measurements).
I pretty much did what was already proposed and connected both, the 3.3 V going to the logic converter and the 5 V for the power supply to external power supplies (so not directly to the Arduino board). Before approx 10% of the measurements resulted in 65k. Now I did not get a single 65k error in the last 100.000 measurements.

I have found that the TFMini is very sensitive to its connections being disturbed. Such as connection the TFMini to a breadboard and having its wires moved around.