Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong results #9

Closed
TrombiA opened this issue Feb 23, 2020 · 3 comments
Closed

Wrong results #9

TrombiA opened this issue Feb 23, 2020 · 3 comments

Comments

@TrombiA
Copy link

TrombiA commented Feb 23, 2020

Hello

Thank you for this library. I managed to make test program for Node MCU with Basic reading code and library. I can look distance results from serialmonitor and It gives mainly right results. However there are also few wrong results as you can see at picture. Where do you think those comes from and can I avoid somehow those wrong measurements?
Measurements

@budryerson
Copy link
Owner

budryerson commented Feb 24, 2020 via email

@TrombiA
Copy link
Author

TrombiA commented Feb 25, 2020

Hello

I use default frame data rate 100hz and default serial baud rate 115200

I tried to change delay to 3ms and those wrong measurement values comes more rarely, something like once in a two minutes. So it looks like that buffer was overrunning like you guessed. Maybe my Node MCU board can't handle that speed either.

I read TFMPlus library text and noticed that there is commands which can be used for change default frame data rate. So can I just put that "define FRAME_1" to my code beginning when I want to change that frame data rate to 1Hz? Or do I have to put some send command definition to code?

Like this (my code which I use for testing):


#include <SoftwareSerial.h>
#include "TFMini.h"
#define FRAME_1 //new line for change default frame rate to 1Hz??

// Setup software serial port
SoftwareSerial mySerial(D2, D1); // Node MCU RX (TFMINI TX), Node MCU 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(200);
}


I use Node MCU board (Lolin 0.1) and here is picture from my setup:

NodeMCU_Setup

I also tryed this setup to use it with blynk app. Here is code for that:


#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SoftwareSerial.h> //Lisatty.22.2.-20
#include "TFMini.h" //Lisattu.22.2.-20

// Setup software serial port alla olevat lisatty 22.2.-20
SoftwareSerial mySerial(D2, D1); // Node MCU RX (TFMINI TX), Node MCU TX (TFMINI RX)
TFMini tfmini;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "____________"; //Enter the Auth code which was send by Blink

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "_"; //Enter your WIFI Name
char pass[] = "
"; //Enter your WIFI Password

//DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()

{
float D = ((2.92.9((900-(tfmini.getDistance()))/100))*0.55); //D as distance
float D2 = tfmini.getDistance();
float S = tfmini.getRecentSignalStrength();
Blynk.virtualWrite(V5, D ); //V5 is for Distance
Blynk.virtualWrite(V6,D2 );
Blynk.virtualWrite(V7,S );
}
void setup()
{
Serial.begin(115200);
while (!Serial);
Blynk.begin(auth, ssid, pass);

// Step 1: Initialize hardware serial port (serial debug port)tama lisatty 22.2.-20

// wait for serial port to connect. Needed for native USB port only

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

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

//dht.begin(); Poistettu kenoviioivlla 22.2.-20

// Setup a function to be called every second
timer.setInterval(10000L, sendSensor);
}

void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}


It works fine with this code and I get values to blynk app. I were wondering that I can measure volume at storage with this TFmini lidar and blynk app. Thats why there are calculations with measurement results on blynk "D" value.

Br.
Tomi
Finland

@budryerson
Copy link
Owner

Tomi,

It appears that you are calling the TFMini library header file ('TFMini.h'). You are NOT using the TFMini-Plus library. There is no getDistance() function in the TFMini-Plus library.

Can that be part of the problem? Please let me know.

Thanks,
Bud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants