Tf mini LIDAR Arduino problem

HI, I am a beginner with the whole LIDAR sensing technology and software serial on Arduino. Essentially I hooked up one tf mini to my Arduino using a logic level converter, and it worked splendidly. I then attempted to add a second sensor. But when I tried to get a reading from either of the sensors only one showed up in the serial monitor. Through testing I relized whatever LIDAR sensor serial begin went last gave readings. I am using an Arduino Uno, 5v 3.3v bidirectional logic level converter. This is the original code with one LIDAR:

#include <SoftwareSerial.h>
#include “TFMini.h”

// Setup software serial port
SoftwareSerial mySerial(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TFMini tfmini;

void setup() {
// Step 1: Initialize hardware serial port (serial debug port)
Serial.begin(115200);
// wait for serial port to connect. Needed for native USB port only
while (!Serial);

Serial.println (“Initializing…”);

// Step 2: Initialize the data rate for the SoftwareSerial port
mySerial.begin(TFMINI_BAUDRATE);

// Step 3: Initialize the TF Mini sensor
tfmini.begin(&mySerial);
}

void loop() {
// Take one TF Mini distance measurement
uint16_t dist = tfmini.getDistance();
uint16_t strength = tfmini.getRecentSignalStrength();

// Display the measurement
Serial.print(dist);
Serial.print(" cm sigstr: ");
Serial.println(strength);

// Wait some short time before taking the next measurement
delay(25);
}

I then tried to modify for 2 LIDAR. This is my Code:

#include <SoftwareSerial.h>
#include “TFMini.h”

// Setup software serial port
SoftwareSerial mySerial(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
SoftwareSerial mySerial2(12, 13);
TFMini tfmini;
TFMini tfmini2;
void setup() {
// Step 1: Initialize hardware serial port (serial debug port)
Serial.begin(115200);
// wait for serial port to connect. Needed for native USB port only
while (!Serial);

Serial.println (“Initializing…”);

// Step 2: Initialize the data rate for the SoftwareSerial port
mySerial2.begin(TFMINI_BAUDRATE);
mySerial.begin(TFMINI_BAUDRATE);
// Step 3: Initialize the TF Mini sensor
tfmini2.begin(&mySerial);
tfmini.begin(&mySerial);

}

void loop() {
// Take one TF Mini distance measurement
uint16_t dist = tfmini.getDistance();
uint16_t strength = tfmini.getRecentSignalStrength();

// Display the measurement
Serial.print(dist);
Serial.print(" cm sigstr: ");
Serial.println(strength);

// Wait some short time before taking the next measurement
delay(5000);

uint16_t dist2 = tfmini2.getDistance();
uint16_t strength2 = tfmini2.getRecentSignalStrength();

// Display the measurement
Serial.print(dist2);
Serial.print(" cm sigstr: ");
Serial.println(strength2);
delay(5000);
}

Can anyone help with this problem.
Thanks!

// Step 3: Initialize the TF Mini sensor
tfmini2.begin(&mySerial);
tfmini.begin(&mySerial);

should that not be

// Step 3: Initialize the TF Mini sensor
tfmini2.begin(&mySerial2);
tfmini.begin(&mySerial);

on a side note if you plan to add even more sensors, I would consider using a board with more that one Hardware Serial like a Mega for example. Personally, I would not use softwareserial to create more than one addtional port

Only one instance of SoftwareSerial can listen at a time. Whatever is connected to the pins that the deaf instances are supposed to listen to can blab away, and the Arduino won't know.

In your case, that doesn't really matter. Just make sure you call the listen() method of the appropriate software serial instance before you try to talk to each lidar, AND to listen for output for a while before switching instances/lidars.

mySerial and mySerial2 are absolutely stupid names for the instances. mySerial1 and mySerial2 are only marginally any better. You don't count "uh-huh, two, three...", so don't number some variables that appear to be related without numbering ALL of them.

Hi I am trying to reproduce what you are doing (just with one TF MINI) but in my case the code "hangs" when trying to read the first time.
Can you suggest any "debugging" to figure out what is going on ?
I've already tried

  • switching ports on the LLC
  • using different ports on the LLC

I am using an Arduino MEGA 2560, which Arduino version are you using ?