-
Notifications
You must be signed in to change notification settings - Fork 20
Description
I am facing error when i connect 2 tf mini lidar to arduino the output gets stuck and it doesn't work. I am attaching the code below.
Thank you
/*
The (UNO) circuit:
Green TX
White RX
Red +5V
Black Gnd
- Uno RX is digital pin 10 (connect to TX of TF Mini)
- Uno TX is digital pin 11 (connect to RX of TF Mini)
*/
#include <SoftwareSerial.h>
#include "TFMini.h"
#include <NewTone.h>
// Setup software serial port
SoftwareSerial mySerialone(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
SoftwareSerial mySerialtwo(15,14); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TFMini tfmini1;
TFMini tfmini2;
void setup() {
// Step 1: Initialize hardware serial port (serial debug port)
Serial.begin(9600);
// wait for serial port to connect. Needed for native USB port only
while (!Serial);
Serial.println ("Initializing...");
}
void loop() {
// Take one TF Mini distance measurement
mySerialone.begin(115200);
tfmini1.begin(&mySerialone);
uint16_t dist1 = tfmini1.getDistance();
uint16_t strength1 = tfmini1.getRecentSignalStrength();
// Display the measurement
Serial.print(dist1);
Serial.print(" cm sigstr: ");
Serial.println(strength1);
mySerialone.end();
delay(500);
// Take one TF Mini distance measurement
mySerialtwo.begin(115200);
tfmini2.begin(&mySerialtwo);
uint16_t dist2 = tfmini2.getDistance();
uint16_t strength2 = tfmini2.getRecentSignalStrength();
// Display the measurement
Serial.print(dist2);
Serial.print(" cm sigstr: ");
Serial.println(strength2);
mySerialtwo.end();
// Wait some short time before taking the next measurement
delay(500);
if (dist1<100 || dist2<100)
{
Serial.println("**************************************************");
NewTone(3,50,100);
}
}