Hello Everyone,
I have project where i am using Arduino MEGA 2560 and TFMini-S for distance measurement.
I uploaded the pre-made library example code as shown below with pin 53 & 51 for TX & RX using Arduino MEGA.
Currently i am getting the message in Serial communication monitor as- TF Mini error: too many measurement attempts Last error: ERROR_SERIAL_BADCHECKSUM 65535 cm sigstr: 65535
Can anyone please help me out as i have very limited information for MEGA and how RX/TX works ?
Thank you in advance. Look forward to hear any positive news.
The code i am using-
#include <SoftwareSerial.h> #include "TFMini.h"
// Setup software serial port
SoftwareSerial mySerial(53, 51); // 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);
}
Besides i have more devices already using PWM pins. And 3 of TFMini-S already hooked up. Code that i posted here is just for setup 1 TFMini to make sure it works OK. Than COPY logic all over in project.
Thanks.
Hi Mike,
I could use them if i choose not to go with some RGB LEDs with PWMs.
I have few PWM bits already used by motors and LEDs.
So, i selected those 51,53 bits for RX&TX while trying to test my code shown above before dumping in my main code. Which is not complete yet. I watched several videos to understand all the hardware 1st and code as i go. I will see if i can switch few bits around to use TFMini.
Hi Tom,
The code you see is standard code from the example that comes with TFMini-S Library. This code is only designed with UNO that's why you see UNO !
But my actual hardware has more PWM and motors, ultimately made me to use MEGA.
I will go with what mike said and re-arrange the pinout or may be take some LED out to fit everything in.