Hi all,
I am trying to use lidar (tfmini) and gps sensor GPS6MV2), both working the same time. I leave everything connected in the adruino, and with the following code
#include <SoftwareSerial.h>
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
*/
#include "TinyGPS++.h"
/*
Example code for Benewake TFMini time-of-flight distance sensor.
by Peter Jansen (December 11/2017)
This example code is in the public domain.
This example communicates to the TFMini using a SoftwareSerial port at 115200,
while communicating the distance results through the default Arduino hardware
Serial debug port.
SoftwareSerial for some boards can be unreliable at high speeds (such as 115200).
The driver includes some limited error detection and automatic retries, that
means it can generally work with SoftwareSerial on (for example) an UNO without
the end-user noticing many communications glitches, as long as a constant refresh
rate is not required.
The (UNO) circuit:
* Uno RX is digital pin 10 (connect to TX of TF Mini)
* Uno TX is digital pin 11 (connect to RX of TF Mini)
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 NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "TFMini.h"
#include <SD.h>
#include <SPI.h>
SoftwareSerial gps(4, 3);
TinyGPSPlus ttt;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
SoftwareSerial lidar(5, 6); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TFMini tfmini; // This is a lidar object that takes cares the lidar data
int CS_PIN = 5;
void setup()
{
// GPS stuff
Serial.begin(9600);
while(!Serial);
gps.begin(9600);
//LIDAR Stuff
//Serial1.begin(115200);
//while (!Serial1);
Serial.println ("Initializing...");
// Step 2: Initialize the data rate for the SoftwareSerial port
lidar.begin(TFMINI_BAUDRATE);
// Step 3: Initialize the TF Mini sensor
tfmini.begin(&lidar);
}
void loop()
{
// Take one TF Mini distance measurement
uint16_t dist = tfmini.getDistance();
uint16_t strength = tfmini.getRecentSignalStrength();
while(gps.available())//While there are characters to come from the GPS
{
ttt.encode(gps.read());//This feeds the serial NMEA data into the library one char at a time
}
/// if(ttt.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
// {
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
Serial.print("Satellite Count:");
Serial.print(ttt.satellites.value());
Serial.print(",Latitude:");
Serial.print(ttt.location.lat(), 6);
Serial.print(",Longitude:");
Serial.print(ttt.location.lng(), 6);
Serial.print(",Speed KMH:");
Serial.print(ttt.speed.kmph());
Serial.print(",Altitude meter:");
Serial.print(ttt.altitude.meters());
Serial.print(",Date");
Serial.print(ttt.date.value());
Serial.print(",Time");
Serial.print(ttt.time.value());
Serial.println("");
Serial.print(dist);
Serial.print(" cm sigstr: ");
Serial.println(strength);
delay(500);
// }
}
I can get information all lines related to the lidar, then the gps is not working (lat,lon=0).
If I comment the lidar lines (see below) then I get gps signal.
#include <SoftwareSerial.h>
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
*/
#include "TinyGPS++.h"
/*
Example code for Benewake TFMini time-of-flight distance sensor.
by Peter Jansen (December 11/2017)
This example code is in the public domain.
This example communicates to the TFMini using a SoftwareSerial port at 115200,
while communicating the distance results through the default Arduino hardware
Serial debug port.
SoftwareSerial for some boards can be unreliable at high speeds (such as 115200).
The driver includes some limited error detection and automatic retries, that
means it can generally work with SoftwareSerial on (for example) an UNO without
the end-user noticing many communications glitches, as long as a constant refresh
rate is not required.
The (UNO) circuit:
* Uno RX is digital pin 10 (connect to TX of TF Mini)
* Uno TX is digital pin 11 (connect to RX of TF Mini)
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 NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "TFMini.h"
#include <SD.h>
#include <SPI.h>
SoftwareSerial gps(4, 3);
TinyGPSPlus ttt;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
SoftwareSerial lidar(5, 6); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TFMini tfmini; // This is a lidar object that takes cares the lidar data
int CS_PIN = 5;
void setup()
{
// GPS stuff
Serial.begin(9600);
while(!Serial);
gps.begin(9600);
//LIDAR Stuff
//Serial1.begin(115200);
//while (!Serial1);
Serial.println ("Initializing...");
// Step 2: Initialize the data rate for the SoftwareSerial port
// lidar.begin(TFMINI_BAUDRATE);
// Step 3: Initialize the TF Mini sensor
//tfmini.begin(&lidar);
}
void loop()
{
// Take one TF Mini distance measurement
// uint16_t dist = tfmini.getDistance();
// uint16_t strength = tfmini.getRecentSignalStrength();
while(gps.available())//While there are characters to come from the GPS
{
ttt.encode(gps.read());//This feeds the serial NMEA data into the library one char at a time
}
/// if(ttt.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
// {
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
Serial.print("Satellite Count:");
Serial.print(ttt.satellites.value());
Serial.print(",Latitude:");
Serial.print(ttt.location.lat(), 6);
Serial.print(",Longitude:");
Serial.print(ttt.location.lng(), 6);
Serial.print(",Speed KMH:");
Serial.print(ttt.speed.kmph());
Serial.print(",Altitude meter:");
Serial.print(ttt.altitude.meters());
Serial.print(",Date");
Serial.print(ttt.date.value());
Serial.print(",Time");
Serial.print(ttt.time.value());
Serial.println("");
// Serial.print(dist);
// Serial.print(" cm sigstr: ");
// Serial.println(strength);
delay(500);
// }
}
Could you please help what am I doing wrong?